diff --git a/README.md b/README.md index 9cda1fb..2ac9a3b 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,41 @@ There is a Docker image. Run your own bot: ```shell export ALLOWED_CHAT=-11111111 export TG_TOKEN= -export OPS_LIST=@ultradesu,@jesus_christ +export OPS_LIST=@ultradesu,@jesus_christ,156754155 -docker run -ti -e ALLOWED_CHAT=${ALLOWED_CHAT} -e TG_TOKEN=${TG_TOKEN} -e OPS_LIST=${OPS_LIST} techops_bot:latest +docker run -ti \ + -e ALLOWED_CHAT=${ALLOWED_CHAT} \ + -e TG_TOKEN=${TG_TOKEN} \ + -e OPS_LIST=${OPS_LIST} \ + ultradesu/techops_bot:latest ``` +Or via systemd unit. +``` +git clone https://github.com/house-of-vanity/techops_bot /opt/techops-bot +cd /opt/techops-bot && pip3 install -r requirements.txt + +cat > /lib/systemd/system/techops-bot.service < +Environment=OPS_LIST=@ultradesu,@jesus_christ,156754155 +WorkingDirectory=/opt/techops-bot +ExecStart=/usr/bin/python3 /opt/techops-bot/bot.py +ExecStop=/usr/bin/killall -TERM /usr/bin/python3 /opt/techops-bot/bot.py +[Install] +WantedBy=multi-user.target +EOF + +systemctl start techops-bot.service +systemctl status techops-bot.service +``` diff --git a/bot.py b/bot.py index 64c66f3..c956108 100644 --- a/bot.py +++ b/bot.py @@ -50,6 +50,9 @@ bot = Bot(config['TG_TOKEN']) opses = list() try: for ops in config['OPS_LIST'].split(','): + if ops.isdigit(): + name = bot.get_chat_member(config['ALLOWED_CHAT'], ops)['user']['first_name'] + ops=f"[{name}](tg://user?id={ops})" opses.append(ops) except Exception as error: logger.error(f"Can't parse OPS_LIST env var: {error}") @@ -77,6 +80,7 @@ def restricted(func): help_text = f"""This bot will choose your destiny. *Configured Ops list:* + {', '.join(config['OPS_LIST'])} *Commands:* @@ -98,18 +102,20 @@ def roll(update, context): bot.sendChatAction( chat_id=update.message.chat_id, action=ChatAction.TYPING ) - message_id = update.message.reply_text(f"Rolling.") + message_id = update.message.reply_markdown(f"_Rolling._") sleep(1) bot.edit_message_text(chat_id=update.message.chat_id, + parse_mode='Markdown', message_id=message_id.message_id, - text='Rolling..',) + text='_Rolling.._',) bot.sendChatAction( chat_id=update.message.chat_id, action=ChatAction.TYPING ) sleep(1) bot.edit_message_text(chat_id=update.message.chat_id, + parse_mode='Markdown', message_id=message_id.message_id, - text='Rolling...',) + text='_Rolling..._',) bot.sendChatAction( chat_id=update.message.chat_id, action=ChatAction.TYPING ) @@ -117,13 +123,13 @@ def roll(update, context): for ops in config['OPS_LIST']: result[ops] = randint(1, 100) result = sorted(result.items(),key=operator.itemgetter(1),reverse=False) -# [%s](tg://user?id=%s) body = "" for user, score in result: if user.isdigit(): user = f"[{user}](tg://user?id={user})" body += f'\n{user}: {score}' bot.edit_message_text(chat_id=update.message.chat_id, + parse_mode='Markdown', message_id=message_id.message_id, text=f"Result: {body}",)