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

adding a way to toggle the welcome message #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .idea/ilugd-bot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

182 changes: 182 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 39 additions & 6 deletions ilugd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
from random import choice
import os

BOTNAME = 'ILUGDbot'

BOTNAME = 'YOURBOTNAMEGOESHERE'
toggle_state_welcome = 0
@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 !!
updater = Updater(token = '630074149:AAE5G411hgWo33tejBsHP6qxFc6eSO7S-m0') # we should use env variable !! <- I don't (^^)
Copy link
Member

Choose a reason for hiding this comment

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

One must not push his token to a public repository, also this bot already has one, which is set as the environment variable, please revert the line back

Copy link
Member

Choose a reason for hiding this comment

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

also .idea should not be pushed it should be in .gitignore

dispatcher = updater.dispatcher


Expand Down Expand Up @@ -74,22 +73,36 @@ def help(bot, update):
/twitter - twitter link for ILUGD
/meetuplink - to get meetup link for ILUGD
/github - link to ilugd github repos
/toggle_welcome_usage - makes the bot sound more friendly to new users
''')


# Welcome a user to the chat
def welcome(bot, update):
global toggle_state_welcome
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),
'Hi {}! Welcome to {} .let\'s start with introduction.'.format(message.new_chat_member.first_name,message.chat.title)
if message.new_chat_member.username!="" and toggle_state_welcome==1:
name_to_call = message.new_chat_member.username
else:
name_to_call = message.new_chat_member.first_name
phrases = ['Hello {}! Welcome to {} .Please introduce yourself.'.format(name_to_call,message.chat.title),
'Hi {}! Welcome to {} .let\'s start with introduction.'.format(name_to_call,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 toggle_welcome_usage(bot, update):
global toggle_state_welcome
toggle_state_welcome = 1 - toggle_state_welcome
states_welcome=['first_name','username']
state_welcome=states_welcome[toggle_state_welcome]
bot.sendMessage(chat_id=update.message.chat_id, text='toggles the welcome usage from username to first name')
bot.sendMessage(chat_id=update.message.chat_id, text='currently toggled to "{}"'.format(state_welcome))


def goodbye(bot, update):
message = update.message
Expand Down Expand Up @@ -119,6 +132,25 @@ def empty_message(bot, update):
if update.message.left_chat_member.username != BOTNAME:
return goodbye(bot, update)

"""def welcome_test(bot, update): #was a very ugly way to test the command directly in telegram
global toggle_state_welcome
message = update.message
chat_id = message.chat.id
if message.from_user.username!="" and toggle_state_welcome==1:
name_to_call = message.from_user.username
else:
name_to_call = message.from_user.first_name
phrases = ['Hello {}! Welcome to {} .Please introduce yourself.'.format(name_to_call,message.chat.title),
'Hi {}! Welcome to {} .let\'s start with introduction.'.format(name_to_call,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)"""
#dispatcher.add_handler(CommandHandler('wesite', welcome_test))



dispatcher.add_handler(CommandHandler('website', website))
dispatcher.add_handler(CommandHandler('facebook', facebok))
Expand All @@ -130,6 +162,7 @@ def empty_message(bot, update):
dispatcher.add_handler(CommandHandler('meetuplink',meetuplink))
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('github',github))
dispatcher.add_handler(CommandHandler('toggle_welcome_usage',toggle_welcome_usage))

updater.start_polling()
updater.idle()