2022-08-08 22:36:12 +02:00
|
|
|
from akkomabot import Akkomabot
|
|
|
|
from ejabberdapi import Ejabberd
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
if mention.question == bot.register_str:
|
2022-08-08 22:36:12 +02:00
|
|
|
|
|
|
|
password = ejabberd.generate_pass()
|
|
|
|
|
|
|
|
is_registered, text = ejabberd.register(mention.acct, bot.akkoma_hostname, password)
|
|
|
|
|
|
|
|
if is_registered:
|
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post = f"@{mention.acct} {bot.registerok_str}\n\n{bot.user_str} {mention.acct}@{bot.akkoma_hostname}\n"
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f"{bot.password_str} {password}\n{bot.server_str} {bot.akkoma_hostname}"
|
2022-08-08 22:36:12 +02:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
elif mention.question == bot.unregister_str:
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
is_unregistered, is_admin = ejabberd.unregister(mention.acct, bot.akkoma_hostname)
|
2022-08-08 22:36:12 +02:00
|
|
|
|
|
|
|
if is_unregistered:
|
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
bot.akkoma.status_post(f"@{mention.acct}, {bot.xmpp_account_str} {mention.acct}@{bot.akkoma_hostname}: {bot.deleted_str}", in_reply_to_id=mention.status_id, visibility='direct')
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
elif not is_unregistered:
|
|
|
|
|
|
|
|
if is_admin:
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
bot.akkoma.status_post(f'@{mention.acct}, {bot.notdeleteadmin_str}', in_reply_to_id=mention.status_id, visibility='direct')
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
elif mention.question == bot.stats_str:
|
2022-08-08 22:36:12 +02:00
|
|
|
|
|
|
|
stats = ejabberd.stats()
|
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post = f'@{mention.acct}, {bot.stats_title_str} {bot.akkoma_hostname}:\n\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f'{bot.registered_users_str} {stats.registeredusers}\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f'{bot.users_online_str} {stats.onlineusers}\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f'{bot.node_users_str} {stats.onlineusersnode}\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f'{bot.uptime_str} {stats.uptimeseconds}\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
2022-08-09 11:16:26 +02:00
|
|
|
post += f'{bot.processes_str} {stats.processes}\n'
|
2022-08-08 22:36:12 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|