Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues #1, #3 added some new features. #7

Closed
41 changes: 28 additions & 13 deletions ilugd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def website(bot, update):
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text=config['BOT']['website'])

def facebok(bot, update):
def facebook(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'])
Expand Down Expand Up @@ -82,17 +82,25 @@ def help(bot, update):
/github - link to ilugd github repos
''')

def unknown(bot, update):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

bot.sendChatAction(chat_id=update.message.chat_id,
action=ChatAction.TYPING)
bot.sendMessage(chat_id=update.message.chat_id, text="Unknown command. Use /help")

# 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)
]

try:
# new_chat_members return a list of dicts from which member's username has to be searched
member_first_name = [member['first_name'] for member in message.new_chat_members if 'first_name' in member]
except KeyError:
member_first_name = message.new_chat_members[0]['first_name']

phrases = ['Hello {}! Welcome to {} .Please introduce yourself. Dont forget to read the chat rules using !rules command'.format(member_first_name,message.chat.title)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why modify the list it was planned to expand it so that if multiple people join on same day its too boring to receive same message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no documentation or comment about it. I will write a comment and add a few more welcoming messages. Should I proceed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies to same sticker what do you think (i was thinking like a list and throw a random one to chat)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no documentation or comment about it. I will write a comment and add a few more welcoming messages. Should I proceed?

yupz (also for stickers (I love gifs))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds awesome! Also what about the '!rules' command mentioned in 'phrases'? How should I go about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @nk521 for more info (@nk521 we can merge both ?)
it's from a different bot

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for the time being, I will make changes for stickers and 'phrases' and will raise an issue about the 'rules' command to be solved in future commits. Is that all right?


bot.send_sticker(chat_id=chat_id, sticker="CAADAgADAQEAAladvQoivp8OuMLmNBYE")
text = choice(phrases)
send_async(bot, chat_id=chat_id, text=text, parse_mode=ParseMode.HTML)

Expand All @@ -101,20 +109,26 @@ 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)
text = text.replace('$username', message.left_chat_member.first_name)
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.'
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):

try:
# new_chat_members return a list of dicts from which bot's username has to be searched
member_username = [member['username'] for member in update.message.new_chat_members if 'username' in member]
except KeyError:
member_username = update.message.new_chat_members[0]['username']

if update.message.new_chat_member is not None:
if update.message.new_chat_members is not None:
# Bot was added to a group chat
if update.message.new_chat_member.username == BOTNAME:
if member_username == BOTNAME:
return intro(bot, update)
# Another user joined the chat
else:
Expand All @@ -127,15 +141,16 @@ def empty_message(bot, update):


dispatcher.add_handler(CommandHandler('website', website))
dispatcher.add_handler(CommandHandler('facebook', facebok))
dispatcher.add_handler(CommandHandler('facebook', facebook))
dispatcher.add_handler(CommandHandler('help', help))
dispatcher.add_handler(MessageHandler([Filters.status_update], empty_message))
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))
dispatcher.add_handler(MessageHandler(Filters.command, unknown)

updater.start_polling()
updater.idle()