-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbot.py
75 lines (55 loc) · 2.32 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
68
69
70
71
72
73
74
75
import logging
import os
from telegram.ext import Updater, MessageHandler, CommandHandler, Filters
from commands.links import links
from commands.issues import issues
from commands.help import help
from commands.xkcd import xkcd
from commands.welcome import welcome
from commands.meetup import set_meetup, meetup
from commands.tweepyStreaming import tweets
bot_name = os.getenv("bot_name")
token = os.getenv("token")
root = logging.getLogger()
root.setLevel(logging.INFO)
logging.basicConfig(
level=logging.INFO,
format="""%(asctime)s - %(name)s - %(levelname)s
- %(message)s""",
)
logger = logging.getLogger(__name__)
def start(update, context):
chat_id = update.message.chat.id
text = (
"Hello everyone!\n\n"
"I am the JODC-bot.\n"
"If you want to know about what I can do, use the /help command\n"
)
context.bot.send_message(chat_id=chat_id, text=text)
def unknown(update, context):
chat_id = update.message.chat.id
text = "Sorry, I don't know that command"
context.bot.send_message(chat_id=chat_id, text=text)
def check(update, context):
if update.message.new_chat_members:
for new_member in update.message.new_chat_members:
if new_member.username == bot_name:
return start(update, context)
else:
return welcome(update, context, new_member)
def main():
updater = Updater(token, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("help", help, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("xkcd", xkcd, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("links", links, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("issues", issues, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("set_meetup", set_meetup, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("meetup", meetup, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(CommandHandler("run", tweets, Filters.regex(r'.*@%s' % bot_name)))
dp.add_handler(MessageHandler(Filters.status_update, check))
dp.add_handler(MessageHandler(Filters.command & Filters.regex(r'.*@%s' % bot_name), unknown))
updater.start_polling(timeout=30, clean=True)
updater.idle()
if __name__ == "__main__":
main()