lono/send_users_list.py

35 lines
852 B
Python
Raw Normal View History

2019-03-03 23:23:12 +00:00
#!/usr/bin/env python3
from telegram import Bot
from db import get_conn, Subscriber
2019-03-03 23:26:51 +00:00
from config import BOT_TOKEN, MANAGEMENT_CHAT
2019-03-03 23:23:12 +00:00
def send_users_list(bot: Bot = None):
conn = get_conn(read_only=True)
if not bot:
bot = Bot(BOT_TOKEN)
subs = conn.root.subscribers.values()
2019-03-03 23:25:10 +00:00
messages = [f'Count: {len(subs)}\n']
2019-03-03 23:23:12 +00:00
for sub in subs: # type: Subscriber
2019-03-03 23:25:45 +00:00
msg = f'<code>{sub.uid:>14}</code> '
2019-03-03 23:23:12 +00:00
if sub.uid < 0:
msg += str(sub.name)
else:
msg += f'<a href="tg://user?id={sub.uid}">{sub.name}</a>'
messages.append(msg)
for i in range(0, len(messages), 40):
2019-03-03 23:26:51 +00:00
bot.send_message(MANAGEMENT_CHAT, '\n'.join(messages[i:i+40]), parse_mode='html')
print('User list was sent to the management chat')
conn.close()
2019-03-03 23:23:12 +00:00
if __name__ == '__main__':
send_users_list()