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

Simplification & bug-fix of _extract_setting #28

Merged
merged 1 commit into from
Dec 18, 2017
Merged
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
37 changes: 20 additions & 17 deletions hey_fireball.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,21 @@ def _extract_count(self):
pass

def _extract_setting(self):
if self.bot_is_first:
idx = 2
curPref = get_pm_preference(self.requestor_id)
if len(self.parts) < 3:
#Act as a toggle
if curPref:
return 0
else:
return 1
if self.parts[idx].lower() == 'on' and not curPref:
return 1
elif self.parts[idx].lower() == 'off' and curPref:
"""Find the setting from self-targeting commands"""
idx = sum([bool(self.bot_is_first), bool(self.requestor_id)])
current_preference = get_pm_preference(self.requestor_id)
if 'on' in self.parts and not current_preference:
return 1
elif 'off' in self.parts and current_preference:
return 0
elif len(self.parts) == idx:
# No Arguments, act as a toggle:
if current_preference:
return 0
else:
pass
return 1
else:
return 2

'''
# Use the following to catch and handle missing methods/properties as we want
Expand Down Expand Up @@ -315,11 +315,14 @@ def handle_command(fireball_message):
send_message_to = fireball_message.requestor_id_only

elif fireball_message.command == 'setpm':
set_pm_preference(fireball_message.requestor_id, fireball_message.setting)
if fireball_message.setting:
msg = "Receive PM's: On"
if fireball_message.setting <= 1:
set_pm_preference(fireball_message.requestor_id, fireball_message.setting)
if fireball_message.setting:
msg = "Receive PM's: On"
else:
msg = "Receive PM's: Off\n*Warning:* _Future messages that were sent only to you will look like this. This type of response does not typically persist between slack sessions._"
else:
msg = "Receive PM's: Off\n*Warning:* _Future messages that were sent only to you will look like this. This type of response does not typically persist between slack sessions._"
msg = f"The option is already set as requested, or the argument was invalid.\nI accept: `{AT_BOT} setpm on`, `{AT_BOT} setpm off`, or `{AT_BOT} setpm` (to act as a toggle). "
send_message_to = fireball_message.requestor_id_only
else:
# Message was not valid, so
Expand Down