-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbot.py
More file actions
57 lines (39 loc) · 1.61 KB
/
Copy pathbot.py
File metadata and controls
57 lines (39 loc) · 1.61 KB
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
# -*- coding: utf-8 -*-
#import redis
import os
token = os.environ['TELEGRAM_TOKEN']
import numpy as np
import random
import logging
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from telegram.ext import MessageHandler, Filters
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
sticker_filepath = 'sticker.txt'
def start(bot, update):
update.message.reply_text("Me envie um sticker e eu te enviarei outro de volta!")
def help(bot, update):
update.message.reply_text("Me envie um sticker e eu te enviarei outro de volta!")
def random_sticker(bot, update):
stickerfile = np.loadtxt(sticker_filepath, dtype=str)
stickerid = update.message.sticker.file_id
if(stickerid not in stickerfile):
stickerfile = np.append(stickerfile, stickerid)
np.savetxt(sticker_filepath, stickerfile, fmt='%s')
stickerid = stickerfile[random.randint(0, len(stickerfile)-1)]
update.message.reply_sticker(stickerid)
def main():
# Create the Updater and pass it your bot's token.
updater = Updater(token)
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CommandHandler('help', help))
updater.dispatcher.add_handler(MessageHandler(Filters.sticker, random_sticker))
# Start the Bot
updater.start_polling()
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.idle()
if __name__ == '__main__':
main()