Skip to content

Commit

Permalink
Fixing channel interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Riveros committed Oct 22, 2017
1 parent 8307961 commit 3754dcb
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,35 @@ def save_allowed(s):
else:
sys.exit("No config file found. Remember changing the name of config-sample.json to config.json")

def is_allowed(msg):
if msg['chat']['type'] == 'channel':
return True #all channel admins are allowed to use the bot (channels don't have sender info)
return 'from' in msg and msg['from']['id'] in allowed

def handle(msg):
print("Message: " + str(msg))
if ('from' in msg and msg['from']['id'] in allowed) or ('text' in msg and "/addme" == msg['text'].strip()[:6]):
content_type, chat_type, chat_id = telepot.glance(msg)
txt = ""
if 'text' in msg:
txt = txt + msg['text']
elif 'caption' in msg:
txt = txt + msg['caption']
# Add person as allowed
content_type, chat_type, chat_id = telepot.glance(msg)
txt = ""
if 'text' in msg:
txt = txt + msg['text']
elif 'caption' in msg:
txt = txt + msg['caption']
if "/addme" == txt.strip()[:6]:
if msg['chat']['type'] != 'private':
bot.sendMessage(chat_id, "This command is meant to be used only on personal chats.")
else:
used_password = " ".join(txt.strip().split(" ")[1:])
if used_password == PASSWORD:
allowed.add(msg['from']['id'])
save_allowed(allowed)
bot.sendMessage(chat_id, msg['from']['first_name'] + ", you have been registered " +
"as an authorized user of this bot.")
else:
bot.sendMessage(chat_id, "Wrong password.")
if is_allowed(msg):
if txt != "":
if "/addme " == txt.strip()[:7]:
if msg['chat']['type'] != 'private':
bot.sendMessage(chat_id, "This command is meant to be used only on personal chats.")
else:
used_password = " ".join(txt.strip().split(" ")[1:])
if used_password == PASSWORD:
allowed.add(msg['from']['id'])
save_allowed(allowed)
bot.sendMessage(chat_id, msg['from']['first_name']+", you have been registered " +
"as an authorized user of this bot.")
else:
bot.sendMessage(chat_id, "Wrong password.")
elif "/rmme" == txt.strip()[:5]:
if "/rmme" == txt.strip()[:5]:
allowed.remove(msg['from']['id'])
save_allowed(allowed)
bot.sendMessage(chat_id, "Your permission for using the bot was removed successfully.")
Expand Down

0 comments on commit 3754dcb

Please sign in to comment.