main #15
1 changed files with 55 additions and 0 deletions
55
kaikout/erdhe.py
Normal file
55
kaikout/erdhe.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#!/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
|
Loading…
Reference in a new issue