Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
706188827a | |||
2f3e887c83 |
2 changed files with 63 additions and 1 deletions
|
@ -11,6 +11,7 @@ from kaikout.utilities import Config
|
|||
from kaikout.xmpp.client import XmppClient
|
||||
from getpass import getpass
|
||||
from argparse import ArgumentParser
|
||||
from erdhe import integrate_with_kaikout # Add this import
|
||||
import logging
|
||||
# import os
|
||||
# import slixmpp
|
||||
|
@ -56,5 +57,11 @@ def main():
|
|||
port = account_xmpp['client']['port'] if 'port' in account_xmpp['client'] else None
|
||||
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__':
|
||||
main()
|
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