1
0
Fork 0
forked from sch/KaikOut

Compare commits

..

No commits in common. "main" and "main" have entirely different histories.
main ... main

2 changed files with 1 additions and 63 deletions

View file

@ -11,7 +11,6 @@ from kaikout.utilities import Config
from kaikout.xmpp.client import XmppClient from kaikout.xmpp.client import XmppClient
from getpass import getpass from getpass import getpass
from argparse import ArgumentParser from argparse import ArgumentParser
from erdhe import integrate_with_kaikout # Add this import
import logging import logging
# import os # import os
# import slixmpp # import slixmpp
@ -57,11 +56,5 @@ def main():
port = account_xmpp['client']['port'] if 'port' in account_xmpp['client'] else None port = account_xmpp['client']['port'] if 'port' in account_xmpp['client'] else None
XmppClient(jid, password, hostname, port, alias) XmppClient(jid, password, hostname, port, alias)
# Create the XMPP client
xmpp_client = XmppClient(jid, password, hostname, port, alias)
# Integrate the welcome whisper feature
welcomer = integrate_with_kaikout(xmpp_client)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1,55 +0,0 @@
#!/usr/bin/env python3
from slixmpp import ClientXMPP
from slixmpp.exceptions import IqError, IqTimeout
import logging
class WelcomeWhisperer:
"""
A feature class that sends welcome whispers to users joining an XMPP room.
"""
def __init__(self, xmpp_client):
self.xmpp = xmpp_client
self.rooms = {}
# Register event handlers
self.xmpp.add_event_handler("groupchat_presence", self.handle_groupchat_presence)
def handle_groupchat_presence(self, presence):
"""
Handle presence stanzas from chat rooms.
"""
if presence['type'] == 'available':
room = presence['from'].bare
nick = presence['from'].resource
# Check if this is a new user joining (not already in our room roster)
if room in self.rooms and nick not in self.rooms[room]:
self.send_welcome_whisper(room, nick)
# Update our room roster
if room not in self.rooms:
self.rooms[room] = set()
self.rooms[room].add(nick)
def send_welcome_whisper(self, room, nick):
"""
Send a welcome whisper to a user who just joined the room.
"""
message = f"Welcome to the room {nick}, have a good time in the channel!"
try:
self.xmpp.send_message(
mto=room,
mbody=f"/w {nick} {message}",
mtype='groupchat'
)
logging.info(f"Sent welcome whisper to {nick} in {room}")
except Exception as e:
logging.error(f"Failed to send welcome whisper: {e}")
def integrate_with_kaikout(xmpp_client):
"""
Integrate the WelcomeWhisperer feature with an existing Kaikout XmppClient instance.
"""
welcomer = WelcomeWhisperer(xmpp_client)
return welcomer