-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
110 lines (91 loc) · 3.43 KB
/
bot.py
File metadata and controls
110 lines (91 loc) · 3.43 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
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
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 = 'codeshows_bot'
@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('TOKEN')
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 CodeshowsBot currently working with Codeshows.
To hire me contact my admin.
Use /help to get help.
'''
)
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 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 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 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 codeshows Telegram group link
/facebook - to get a link to codeshows Facebook page
/website - to get codeshows website link
/github - link to codeshows github repos
'''
)
def welcome(bot, update):
message = update.message
chat_id = message.chat.id
phrases = [
'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 intro(bot, update):
message = update.message
chat_id = message.chat.id
text = 'Hi everyone,I am a python bot working to serve Codeshows.'
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:
if update.message.new_chat_member.username == BOTNAME:
return intro(bot, update)
else:
return welcome(bot, update)
if __name__ == '__main__':
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('start', start))
dispatcher.add_handler(CommandHandler('github',github))
updater.start_polling()
updater.idle()