#!/usr/bin/env python3
from telegram import Bot
from db import get_conn, Subscriber
from config import BOT_TOKEN, MANAGEMENT_CHAT
def send_users_list(bot: Bot = None, conn=None):
if conn is None:
conn = get_conn(read_only=True)
if not bot:
bot = Bot(BOT_TOKEN)
subs = conn.root.subscribers.values()
messages = [f'Count: {len(subs)}\n']
for sub in subs: # type: Subscriber
msg = f'{sub.uid:>14}
'
if sub.uid < 0:
msg += str(sub.name)
else:
msg += f'{sub.name}'
messages.append(msg)
for i in range(0, len(messages), 40):
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()
if __name__ == '__main__':
send_users_list()