dice_score_telegram

Форк
0
173 строки · 9.1 Кб
1
import telebot, time, json, config
2

3

4

5
bot = telebot.TeleBot(config.token)
6
score = {}
7

8
@bot.message_handler(commands=['start'])
9
def start(message):
10
    bot.send_message(message.chat.id, 'Привет, я бот сделанный командой @b4dcat404\n'
11
                                      'Я умею считать очки в баскетболе, футболе, боулинге и дартсе\n'
12
                                      'Добавь меня в свою группу и назначь админом\n'
13
                                      'Для просмотра команд напиши /help')
14
@bot.message_handler(commands=['info'])
15
def info(message):
16
    bot.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'])
22
def test(message):
23
    pscore = score[message.from_user.id]
24
    if pscore.get('b_sshots') != 0:
25
        pscorepersent = 100 / (pscore.get('b_shots') / pscore.get('b_sshots'))
26
    else:
27
        pscorepersent = 0
28
    if pscore.get('f_sshots') != 0:
29
        pfscore = 100 / pscore.get('f_shots') / pscore.get('f_sshots')
30
    else:
31
        pfscore = 0
32
    if pscore.get('bou_sshots') != 0:
33
        pbouscore = 100 / pscore.get('bou_shots') / pscore.get('bou_sshots')
34
    else:
35
        pbouscore = 0
36
    if pscore.get('d_sshots') != 0:
37
        pdscore = 100 / pscore.get('d_shots') / pscore.get('d_sshots')
38
    else:
39
        pdscore = 0
40

41
    if (message.text == '/stb' or message.text == '/stb@basket404_bot'):
42
        bot.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)*',
47
                         parse_mode="MarkdownV2", disable_web_page_preview=True)
48
    elif (message.text == '/stf' or message.text == '/stf@basket404_bot'):
49
        bot.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)*',
54
                                     parse_mode="MarkdownV2", disable_web_page_preview=True)
55
    elif (message.text == '/stbou' or message.text == '/stbou@basket404_bot'):
56
        bot.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)*',
61
                                     parse_mode="MarkdownV2", disable_web_page_preview=True)
62
    elif (message.text == '/std' or message.text == '/std@basket404_bot'):
63
        bot.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)*',
68
                                        parse_mode="MarkdownV2", disable_web_page_preview=True)
69

70
@bot.message_handler(commands=['help'])
71
def help(message):
72
    bot.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)*',
79
                     parse_mode="MarkdownV2", disable_web_page_preview=True)
80
# In progress
81
@bot.message_handler(commands=['score'])
82
def scores(message):
83
    usrid = message.from_user.id
84
    jscore = json.dumps(score, indent=4, sort_keys=True)
85
    print("Счет\n " + jscore)
86
    for key, value in score.items():
87
        print(key)
88
        user = key
89
        for v in value.items():
90
            print(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'])
98
def handle_sticker(msg):
99
    dice = msg.dice.value
100
    if msg.dice.emoji == '🏀':
101
        if msg.from_user.id not in score:
102
            score[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}
103
        else:
104
            score[msg.from_user.id]["b_shots"] += 1
105
            if dice > 3:
106
                score[msg.from_user.id]["b_sshots"] += 1
107
    elif msg.dice.emoji == '⚽':
108
        if msg.from_user.id not in score:
109
            score[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}
110
        else:
111
            score[msg.from_user.id]["f_shots"] += 1
112
            if dice > 3:
113
                score[msg.from_user.id]["f_sshots"] += 1
114
    elif msg.dice.emoji == '🎳':
115
        if msg.from_user.id not in score:
116
            score[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}
117
        else:
118
            score[msg.from_user.id]["bou_shots"] += 1
119
            if dice == 6:
120
                score[msg.from_user.id]["bou_sshots"] += 1
121
    elif msg.dice.emoji == '🎯':
122
        if msg.from_user.id not in score:
123
            score[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}
124
        else:
125
            score[msg.from_user.id]["d_shots"] += 1
126
            if dice == 6:
127
                score[msg.from_user.id]["d_sshots"] += 1
128

129
# cheatcode | Can set score via /set "shots" "successful shots"
130
@bot.message_handler(commands=['set'])
131
def setscore(msg):
132
    tscore = score[msg.from_user.id]
133
    set = int(msg.text.split()[1])
134
    sett = int(msg.text.split()[2])
135
    tscore['b_shots'] = set
136
    tscore['b_sshots'] = sett
137

138

139

140
@bot.message_handler(commands=['rsb', 'rsf', 'rsd', 'rsbou'])
141
def reset(message):
142
    tscore = score[message.from_user.id]
143
    if (message.text == '/rsb' or message.text == '/rsb@basket404_bot'):
144
        tscore['b_shots'] = 0
145
        tscore['b_sshots'] = 0
146
        bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
147
                     ' твой счет обнулен\.\n', parse_mode="MarkdownV2")
148
    elif (message.text == '/rsf' or message.text == '/rsf@basket404_bot'):
149
        tscore['f_shots'] = 0
150
        tscore['f_sshots'] = 0
151
        bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
152
                         ' твой счет обнулен\.\n', parse_mode="MarkdownV2")
153
    elif (message.text == '/rsd' or message.text == '/rsd@basket404_bot'):
154
        tscore['d_shots'] = 0
155
        tscore['d_sshots'] = 0
156
        bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
157
                         ' твой счет обнулен\.\n', parse_mode="MarkdownV2")
158
    elif (message.text == '/rsbou' or message.text == '/rsbou@basket404_bot'):
159
        tscore['bou_shots'] = 0
160
        tscore['bou_sshots'] = 0
161
        bot.send_message(message.chat.id, '*' + message.from_user.first_name + '*' +
162
                         ' твой счет обнулен\.\n', parse_mode="MarkdownV2")
163

164

165
if __name__ == '__main__':
166
    while True:
167
        try:
168
            bot.polling(none_stop=True, interval=0)
169
        except Exception as e:
170
            print('Ошибка:')
171
            print(e)
172
            time.sleep(2)
173
            continue
174

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.