Skip to content

Commit

Permalink
More consistent return values from send-based CAPI functions
Browse files Browse the repository at this point in the history
send_chat() and bankickunban() now follow through and return the request ID of the sent message, or False if one was not sent. In the event of trying to whisper a user not in the channel, a malformed whisper request is no longer sent after the user isn't found.
  • Loading branch information
Davnit committed Oct 31, 2019
1 parent df3fb4c commit 9e03c26
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,22 +209,24 @@ def send_chat(self, message, mtype="channel", target=None):
user = self.get_user(target)
if user is None:
self.parent.error(bncs.ERROR_NOTLOGGEDON)
return False
else:
payload["user_id"] = user.id

self.send_command(send_message_types.get(mtype), payload)
return self.send_command(send_message_types.get(mtype), payload)

def bankickunban(self, target, action="ban"):
user = self.get_user(target)
if action.lower() != "unban" and user is None:
self.parent.error(bncs.ERROR_NOTLOGGEDON)
return False
else:
action = bku_actions.get(action.lower())
if action is None:
raise ValueError("Invalid ban/kick/unban action - must be %s" % ', '.join(bku_actions.keys()))

payload = {"toon_name": target} if user is None else {"user_id": user.id}
self.send_command(action, payload)
return self.send_command(action, payload)

def run(self):
while self.connected():
Expand Down

0 comments on commit 9e03c26

Please sign in to comment.