from akkomabot import Akkomabot from ejabberdapi import Ejabberd import pdb # main if __name__ == '__main__': bot = Akkomabot() ejabberd = Ejabberd() notifications = bot.akkoma.notifications() for notif in notifications: if notif.type != 'mention': print(f"Dismissing notification id {notif.id}") bot.akkoma.notifications_dismiss(notif.id) else: mention = bot.get_data(notif) if mention.reply and '@' not in mention.acct: if mention.question == 'registre': password = ejabberd.generate_pass() is_registered, text = ejabberd.register(mention.acct, bot.akkoma_hostname, password) if is_registered: post = f"@{mention.acct} compte xmpp registrat amb èxit!\n\nusuari: {mention.acct}@{bot.akkoma_hostname}\n" post += f"contrasenya: {password}\nservidor: {bot.akkoma_hostname}" bot.akkoma.status_post(post, in_reply_to_id=mention.status_id, visibility='direct') else: bot.akkoma.status_post(f'@{mention.acct}, {text}', in_reply_to_id=mention.status_id, visibility='direct') elif mention.question == 'baixa': is_unregistered, message = ejabberd.unregister(mention.acct, bot.akkoma_hostname) if is_unregistered: bot.akkoma.status_post(f"@{mention.acct}, compte xmpp {mention.acct}@{bot.akkoma_hostname}: {message}", in_reply_to_id=mention.status_id, visibility='direct') else: bot.akkoma.status_post(f'@{mention.acct}, {message}', in_reply_to_id=mention.status_id, visibility='direct') elif mention.question == 'info': stats = ejabberd.stats() post = f'@{mention.acct}, estadístiques del node #xmpp a {bot.akkoma_hostname}:\n\n' post += f'usuaris registrats: {stats.registeredusers}\n' post += f'usuaris en línia: {stats.onlineusers}\n' post += f'usuaris del node: {stats.onlineusersnode}\n' post += f'temps en línia (uptime): {stats.uptimeseconds}\n' post += f'processos: {stats.processes}\n' bot.akkoma.status_post(post, in_reply_to_id=mention.status_id, visibility=mention.visibility) print(f"Dismissing notification id {mention.id}") bot.akkoma.notifications_dismiss(mention.id) else: print(f"Dismissing notification id {mention.id}") bot.akkoma.notifications_dismiss(mention.id)