This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
68 lines (46 loc) · 1.78 KB
/
bot.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
import os
import logging
from uuid import uuid4
from telegram import InlineQueryResultVoice
from telegram.ext import Updater, InlineQueryHandler, CommandHandler
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.WARNING)
logger = logging.getLogger(__name__)
# Get a new dictionary on every launch
file = open("dict.csv","r")
next(file)
data = {}
for line in file:
item = line.split(',')
data[item[0]] = item[1]
def get_audio_names(query):
result = list(filter(lambda key: data[key].find(query) != -1, data.keys()))[:10]
return result, [data[key][:-1] for key in result]
# Define a few command handlers
def error(update, context):
logger.warning('Update "%s" caused error "%s"', update, context.error)
def start(update, context):
update.message.reply_text('черт фил ты пьешь эту гадость тебе не надо было это пить')
def help(update, context):
update.message.reply_text("""
...
""")
def inlinequery(update, context):
query = update.inline_query.query
audio_names, titles = get_audio_names(query)
results = [
InlineQueryResultVoice(id=str(uuid4()),
voice_url=f'https://raw.githubusercontent.com/tiulpin/tg-fargusbot/master/opus/{audio_name}.ogg',
title=title) for audio_name, title in zip(*get_audio_names(query))]
update.inline_query.answer(results)
def main():
updater = Updater(os.environ['TELEGRAM_TOKEN'], use_context=True)
dp = updater.dispatcher
dp.add_error_handler(error)
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(InlineQueryHandler(inlinequery))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()