dice_score_telegram
/
main.py
173 строки · 9.1 Кб
1import telebot, time, json, config
2
3
4
5bot = telebot.TeleBot(config.token)
6score = {}
7
8@bot.message_handler(commands=['start'])
9def start(message):
10bot.send_message(message.chat.id, 'Привет, я бот сделанный командой @b4dcat404\n'
11'Я умею считать очки в баскетболе, футболе, боулинге и дартсе\n'
12'Добавь меня в свою группу и назначь админом\n'
13'Для просмотра команд напиши /help')
14@bot.message_handler(commands=['info'])
15def info(message):
16bot.send_message(message.chat.id, "*Powered by\:*\n\n"
17"@B4DCAT404 \- 🇷🇺 telegram chanel for developers, students and freelancers\n\n"
18"View source code on [GitHub](https://github.com/vi-dev0/dice_score_telegram), "
19"feel free to contribute\n", parse_mode="MarkdownV2")
20
21@bot.message_handler(commands=['stb','stf', 'std', 'stbou'])
22def test(message):
23pscore = score[message.from_user.id]
24if pscore.get('b_sshots') != 0:
25pscorepersent = 100 / (pscore.get('b_shots') / pscore.get('b_sshots'))
26else:
27pscorepersent = 0
28if pscore.get('f_sshots') != 0:
29pfscore = 100 / pscore.get('f_shots') / pscore.get('f_sshots')
30else:
31pfscore = 0
32if pscore.get('bou_sshots') != 0:
33pbouscore = 100 / pscore.get('bou_shots') / pscore.get('bou_sshots')
34else:
35pbouscore = 0
36if pscore.get('d_sshots') != 0:
37pdscore = 100 / pscore.get('d_shots') / pscore.get('d_sshots')
38else:
39pdscore = 0
40
41if (message.text == '/stb' or message.text == '/stb@basket404_bot'):
42bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' + ' твой личный счет:\n\n' +
43'*БАСКТЕБОЛ*🏀\n' +
44'Броски: ' + str(pscore.get('b_shots')) + '\nПопадания: '
45+ str(pscore.get('b_sshots')) + '\nПроцент попадания: ' + str(int(pscorepersent)) +
46'%\n\n*[@B4DCAT404](https://t.me/b4dcat404)*',
47parse_mode="MarkdownV2", disable_web_page_preview=True)
48elif (message.text == '/stf' or message.text == '/stf@basket404_bot'):
49bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' + ' твой личный счет:\n\n' +
50'*ФУТБОЛ*⚽\n' +
51'Удары: ' + str(pscore.get('f_shots')) + '\nГолы: '
52+ str(pscore.get('f_sshots')) + '\nПроцент голов: ' + str(int(pfscore)) +
53'%\n\n*[@B4DCAT404](https://t.me/b4dcat404)*',
54parse_mode="MarkdownV2", disable_web_page_preview=True)
55elif (message.text == '/stbou' or message.text == '/stbou@basket404_bot'):
56bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' + ' твой личный счет:\n\n' +
57'*БОУЛИНГ*🎳\n' +
58'Броски: ' + str(pscore.get('bou_shots')) + '\nСтрайки: '
59+ str(pscore.get('bou_sshots')) + '\nПроцент страйков: ' + str(int(pbouscore)) +
60'%\n\n*[@B4DCAT404](https://t.me/b4dcat404)*',
61parse_mode="MarkdownV2", disable_web_page_preview=True)
62elif (message.text == '/std' or message.text == '/std@basket404_bot'):
63bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' + ' твой личный счет:\n\n' +
64'\n\n*ДАРТС*🎯\n' +
65'Броски: ' + str(pscore.get('d_shots')) + '\nВ яблочко: '
66+ str(pscore.get('d_sshots')) + '\nПроцент попаданий: ' + str(int(pdscore)) +
67'%\n\n*[@B4DCAT404](https://t.me/b4dcat404)*',
68parse_mode="MarkdownV2", disable_web_page_preview=True)
69
70@bot.message_handler(commands=['help'])
71def help(message):
72bot.send_message(message.chat.id, '*Помощь по боту*\n'
73'Что бы бот начал вести счет, тебе нужно отправить один из эмоджи:\n'
74'🏀 \- посмотреть счет `/stb` \| сбросить счет `/rsb`\n'
75'⚽ \- посмотреть счет `/stf` \| сбросить счет `/rsf`\n'
76'🎯 \- посмотреть счет `/std` \| сбросить счет `/rsd`\n'
77'🎳 \- посмотреть счет `/stbou` \| сбросить счет `/rsbou`\n\n'
78'*[@B4DCAT404](https://t.me/b4dcat404)*',
79parse_mode="MarkdownV2", disable_web_page_preview=True)
80# In progress
81@bot.message_handler(commands=['score'])
82def scores(message):
83usrid = message.from_user.id
84jscore = json.dumps(score, indent=4, sort_keys=True)
85print("Счет\n " + jscore)
86for key, value in score.items():
87print(key)
88user = key
89for v in value.items():
90print(v[1])
91
92
93#bot.send_message(message.chat.id, 'Общий счёт:\n' + jscore)
94
95
96
97@bot.message_handler(func=lambda message: True, content_types=['dice'])
98def handle_sticker(msg):
99dice = msg.dice.value
100if msg.dice.emoji == '🏀':
101if msg.from_user.id not in score:
102score[msg.from_user.id] = {"b_shots": 0, "b_sshots": 0, "f_shots": 0, "f_sshots": 0, "bou_shots": 0, "bou_sshots": 0, "d_shots": 0, "d_sshots": 0}
103else:
104score[msg.from_user.id]["b_shots"] += 1
105if dice > 3:
106score[msg.from_user.id]["b_sshots"] += 1
107elif msg.dice.emoji == '⚽':
108if msg.from_user.id not in score:
109score[msg.from_user.id] = {"b_shots": 0, "b_sshots": 0, "f_shots": 0, "f_sshots": 0, "bou_shots": 0, "bou_sshots": 0, "d_shots": 0, "d_sshots": 0}
110else:
111score[msg.from_user.id]["f_shots"] += 1
112if dice > 3:
113score[msg.from_user.id]["f_sshots"] += 1
114elif msg.dice.emoji == '🎳':
115if msg.from_user.id not in score:
116score[msg.from_user.id] = {"b_shots": 0, "b_sshots": 0, "f_shots": 0, "f_sshots": 0, "bou_shots": 0, "bou_sshots": 0, "d_shots": 0, "d_sshots": 0}
117else:
118score[msg.from_user.id]["bou_shots"] += 1
119if dice == 6:
120score[msg.from_user.id]["bou_sshots"] += 1
121elif msg.dice.emoji == '🎯':
122if msg.from_user.id not in score:
123score[msg.from_user.id] = {"b_shots": 0, "b_sshots": 0, "f_shots": 0, "f_sshots": 0, "bou_shots": 0, "bou_sshots": 0, "d_shots": 0, "d_sshots": 0}
124else:
125score[msg.from_user.id]["d_shots"] += 1
126if dice == 6:
127score[msg.from_user.id]["d_sshots"] += 1
128
129# cheatcode | Can set score via /set "shots" "successful shots"
130@bot.message_handler(commands=['set'])
131def setscore(msg):
132tscore = score[msg.from_user.id]
133set = int(msg.text.split()[1])
134sett = int(msg.text.split()[2])
135tscore['b_shots'] = set
136tscore['b_sshots'] = sett
137
138
139
140@bot.message_handler(commands=['rsb', 'rsf', 'rsd', 'rsbou'])
141def reset(message):
142tscore = score[message.from_user.id]
143if (message.text == '/rsb' or message.text == '/rsb@basket404_bot'):
144tscore['b_shots'] = 0
145tscore['b_sshots'] = 0
146bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
147' твой счет обнулен\.\n', parse_mode="MarkdownV2")
148elif (message.text == '/rsf' or message.text == '/rsf@basket404_bot'):
149tscore['f_shots'] = 0
150tscore['f_sshots'] = 0
151bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
152' твой счет обнулен\.\n', parse_mode="MarkdownV2")
153elif (message.text == '/rsd' or message.text == '/rsd@basket404_bot'):
154tscore['d_shots'] = 0
155tscore['d_sshots'] = 0
156bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
157' твой счет обнулен\.\n', parse_mode="MarkdownV2")
158elif (message.text == '/rsbou' or message.text == '/rsbou@basket404_bot'):
159tscore['bou_shots'] = 0
160tscore['bou_sshots'] = 0
161bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
162' твой счет обнулен\.\n', parse_mode="MarkdownV2")
163
164
165if __name__ == '__main__':
166while True:
167try:
168bot.polling(none_stop=True, interval=0)
169except Exception as e:
170print('Ошибка:')
171print(e)
172time.sleep(2)
173continue
174