Update readme.

This commit is contained in:
AB
2019-11-08 22:16:05 +00:00
parent d65189efab
commit ab3399af25
2 changed files with 45 additions and 6 deletions

View File

@ -10,8 +10,41 @@ There is a Docker image. Run your own bot:
```shell
export ALLOWED_CHAT=-11111111
export TG_TOKEN=<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 <<EOF
[Unit]
Description=Telegram TechOps destiny bot
[Service]
Type=simple
User=conf-bot
Group=conf-bot
Restart=always
RestartSec=5
StartLimitInterval=60s
StartLimitBurst=3
Environment=ALLOWED_CHAT=-11111111
Environment=TG_TOKEN=<token>
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
```

14
bot.py
View File

@ -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}",)