generated from otter18/telegram-bot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
114 lines (97 loc) · 3.57 KB
/
main.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright (c) ChernV (@otter18), 2021.
import os
import random
import time
import requests as rq
from setup import *
# from setup import bot, logger
from webhook import app
from market import Market
market = Market()
# --------------- dialog params -------------------
dialog = {
'hello': {
'in': ['привет', 'hello', 'hi', 'privet', 'hey'],
'out': ['Приветствую', 'Здравствуйте', 'Привет!']
},
'how r u': {
'in': ['как дела', 'как ты', 'how are you', 'дела', 'how is it going'],
'out': ['Хорошо', 'Отлично', 'Good. And how are u?']
},
'name': {
'in': ['зовут', 'name', 'имя'],
'out': [
'Я telegram-template-bot',
'Я бот шаблон, но ты можешь звать меня в свой проект',
'Это секрет. Используй команду /help, чтобы узнать'
]
}
}
# --------------- bot -------------------
@bot.message_handler(commands=['help', 'start'])
def say_welcome(message):
logger.info(f'</code>@{message.from_user.username}<code> ({message.chat.id}) used /start or /help')
bot.send_message(
message.chat.id,
'<b>Привет, я упоротый бот</b>',
parse_mode='html'
)
#
# @bot.message_handler(func=lambda message: True)
# def echo(message):
# for t, resp in dialog.items():
# if sum([e in message.text.lower() for e in resp['in']]):
# logger.info(f'</code>@{message.from_user.username}<code> ({message.chat.id}) used {t}:\n\n%s', message.text)
# bot.send_message(message.chat.id, random.choice(resp['out']))
# return
#
# logger.info(f'</code>@{message.from_user.username}<code> ({message.chat.id}) used echo:\n\n%s', message.text)
# bot.send_message(message.chat.id, message.text)
#
# @bot.message_handler(commands=["id"])
# def get_id(message):
# logger.info(f'</code>@{message.from_user.username}<code> used /id')
# bot.send_message(message.chat.id, f"user_id = {message.chat.id}")
@bot.message_handler(commands=['test'])
def get_id(message):
test = 10
# url = 'https://' + os.environ.get('HOST') + '/' + WEBHOOK_TOKEN
url = 'https://' + os.environ.get('HOST') + '/'
while test:
# ping = rq.get(url)
ping = rq.get(url)
bot.send_message(
message.chat.id,
f'{url}\n <b>Привет, я упоротый бот</b> - {test} \n <b>Статус - </b>{ping.status_code}',
parse_mode='html'
)
test -= 1
time.sleep(600)
@bot.message_handler(commands=['market'])
def get_market(message):
test = 0
# url = 'https://' + os.environ.get('HOST') + '/' + WEBHOOK_TOKEN
url = 'https://' + os.environ.get('HOST') + '/'
while True:
ping = rq.get(url)
#msg = market.test()
msg_burick = market.getBuricklOrders()
# if msg:
# bot.send_message(
# message.chat.id,
# f'<b>Привет, я упоротый маркетбот</b> - {test} \n <b>Статус - </b>{ping.status_code} \n {msg}',
# parse_mode='html'
# )
if msg_burick:
bot.send_message(
message.chat.id,
f'<b>Burick</b> - \n{msg_burick}\n',
parse_mode='html'
)
test += 1
time.sleep(60)
if __name__ == '__main__':
if os.environ.get("IS_PRODUCTION", "False") == "True":
app.run()
else:
bot.infinity_polling()