-
Notifications
You must be signed in to change notification settings - Fork 6
/
ilugd.py
141 lines (111 loc) · 5.68 KB
/
ilugd.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import configparser
import logging
from telegram import ChatAction,ParseMode
from telegram.ext.dispatcher import run_async
from random import choice
import os
BOTNAME = 'ILUGDbot'
@run_async
def send_async(bot, *args, **kwargs):
bot.sendMessage(*args, **kwargs)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.DEBUG)
config = configparser.ConfigParser()
config.read('bot.ini')
updater = Updater(os.environ['token']) # we should use env variable !!
dispatcher = updater.dispatcher
def start(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id, action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text= '''
Hey!! I'm currently Working with Ilug-Delhi To hire me contact my admin
Use /help to get help''')
def website(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['website'])
def facebok(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['facebook'])
def invitelink(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['invite_link'])
def mailinglist(bot,update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['mailinglist'])
def twitter(bot,update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['twitter'])
def meetuplink(bot,update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['meetuplink'])
def github(bot,update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['github'])
def coc(bot,update):
bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['coc'])
def help(bot, update):
bot.sendChatAction(chat_id=update.message.chat_id, action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text='''Use one of the following commands
/invitelink - to get Ilug-D Telegram group invite link
/facebook - to get a link to Ilug-D Facebook page
/website - to get Ilug-D website link
/mailinglist - link for our mailing list
/twitter - twitter link for ILUGD
/meetuplink - to get meetup link for ILUGD
/github - link to ilugd github repos
''')
# Welcome a user to the chat
def welcome(bot, update):
message = update.message
chat_id = message.chat.id
phrases = ['Hello {}! Welcome to {} .Please introduce yourself. Dont forget to read the chat rules using !rules command'.format(message.new_chat_member.first_name,message.chat.title),
'Hi {}! Welcome to {} .let\'s start with introduction. Dont forget to read the chat rules using !rules command'.format(message.new_chat_member.first_name,message.chat.title)
#'Hello {}! Welcome to {} .Please introduce yourself.'.format(message.new_chat_member.first_name,message.chat.title),
#'Hello {}! Welcome to {} .Please introduce yourself.'.format(message.new_chat_member.first_name,message.chat.title),
#'Hello {}! Welcome to {} .Please introduce yourself.'.format(message.new_chat_member.first_name,message.chat.title)
]
text = choice(phrases)
send_async(bot, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)
def goodbye(bot, update):
message = update.message
chat_id = message.chat.id
text = 'Goodbye, $username!'
text = text.replace('$username',message.left_chat_member.first_name).replace('$title', message.chat.title)
send_async(bot, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)
def intro(bot, update):
message = update.message
chat_id = message.chat.id
text = 'Hi everyone,I am a python bot working to serve Ilug-D.'
send_async(bot, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)
def empty_message(bot, update):
if update.message.new_chat_member is not None:
# Bot was added to a group chat
if update.message.new_chat_member.username == BOTNAME:
return intro(bot, update)
# Another user joined the chat
else:
return welcome(bot, update)
# Someone left the chat
elif update.message.left_chat_member is not None:
if update.message.left_chat_member.username != BOTNAME:
return goodbye(bot, update)
dispatcher.add_handler(CommandHandler('website', website))
dispatcher.add_handler(CommandHandler('facebook', facebok))
dispatcher.add_handler(CommandHandler('help', help))
dispatcher.add_handler(MessageHandler([Filters.status_update], empty_message))
dispatcher.add_handler(CommandHandler('invitelink',invitelink))
dispatcher.add_handler(CommandHandler('mailinglist',mailinglist))
dispatcher.add_handler(CommandHandler('twitter',twitter))
dispatcher.add_handler(CommandHandler('meetuplink',meetuplink))
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('github',github))
updater.start_polling()
updater.idle()