-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgbot.sh
48 lines (40 loc) · 1.23 KB
/
tgbot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
while true; do
python - << EOF
import os
import sys
import time
from datetime import datetime
from telebot import TeleBot
bot = TeleBot('TOKEN')
bot_start_time = time.time()
def is_message_new(message):
message_time = datetime.fromtimestamp(message.date)
return message_time.timestamp() > bot_start_time
@bot.message_handler(commands=['help'])
def help_command(message):
if is_message_new(message):
bot.reply_to(message, '/saldo /today and number')
@bot.message_handler(commands=['saldo'])
def saldo_command(message):
if is_message_new(message):
result = os.popen('./saldo').read()
bot.reply_to(message, result)
@bot.message_handler(commands=['today'])
def today_command(message):
if is_message_new(message):
result = os.popen('./saldo --today').read()
bot.reply_to(message, result)
@bot.message_handler(func=lambda message: True)
def number_added_command(message):
if is_message_new(message):
try:
number = message.text
result = os.popen('./saldo ' + number).read()
bot.reply_to(message, 'Number added. ' + result)
except ValueError:
bot.reply_to(message, 'Wrong command!')
bot.polling()
EOF
sleep 10
done