-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumbifyBot.py
More file actions
79 lines (63 loc) · 2.54 KB
/
DumbifyBot.py
File metadata and controls
79 lines (63 loc) · 2.54 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import logging
import os
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import MessageHandler, Filters
from telegram import InlineQueryResultArticle, InputTextMessageContent
from telegram.ext import InlineQueryHandler
import random
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger()
PORT = int(os.environ.get('PORT', 5000))
def dumbify(chain):
chain = chain.lower()
i = 0
random.seed()
min = 1
max = 2
amount = random.randint(min, max)
while i < len(chain):
substr = chain[i:i+amount]
chain = chain[:i] + substr.upper() + chain[i+len(substr):]
i += amount+1+random.randint(min, max)
amount = random.randint(min, max)
return chain
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="To use this bot, write @DumbifyBot followed by your message. For long messages just send me the text in private and I will dumbify it. Enjoy!")
def dumbifyMessage(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=dumbify(update.message.text))
def inline_dumbify(update, context):
query = update.inline_query.query.lower()
if not query:
return
query = dumbify(query)
results = list()
results.append(
InlineQueryResultArticle(
id=query,
title='Dumbify your message!',
input_message_content=InputTextMessageContent(query)
)
)
context.bot.answer_inline_query(update.inline_query.id, results)
def main():
"""Start the bot."""
# Create the Updater and pass it your bot's token.
# Make sure to set use_context=True to use the new context based callbacks
# Post version 12 this will no longer be necessary
updater = Updater(token='1704982427:AAFL55HPUrj65dEG3mxraxbsNsqCGLINGp8', use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# handler adding
dp.add_handler(CommandHandler("start", start))
dp.add_handler(MessageHandler(Filters.text & (~Filters.command), dumbifyMessage))
dp.add_handler(InlineQueryHandler(inline_dumbify))
# log all errors
# dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
updater.idle()
main()