Skip to content

Commit

Permalink
labhub.py: Add error message when nick is empty
Browse files Browse the repository at this point in the history
All of the backends do not have `nick` attribute.
Hence an error will be shown whenever nick is empty.

Closes #632
  • Loading branch information
abhishalya committed Nov 2, 2018
1 parent b9d569d commit c0f0a89
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion plugins/labhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def team_mapping(self):
@cmdfilter
def members_only(self, msg, cmd, args, dry_run):
user = msg.frm.nick
if not user:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
return None, None, None
commands = constants.PRIVATE_CMDS

if cmd in commands:
Expand Down Expand Up @@ -122,6 +125,9 @@ def invite_cmd(self, msg, match):
"""
invitee = match.group(1)
inviter = msg.frm.nick
if not inviter:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
return

team = 'newcomers' if match.group(2) is None else match.group(2)
team = team.lower()
Expand Down Expand Up @@ -180,7 +186,9 @@ def callback_message(self, msg):
"""Invite the user whose message includes the holy 'hello world'"""
if re.search(r'hello\s*,?\s*world', msg.body, flags=re.IGNORECASE):
user = msg.frm.nick
if (not self.is_team_member(user, 'newcomers')
if not user:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
elif (not self.is_team_member(user, 'newcomers')
and user not in self.hello_world_users):
response = tenv().get_template(
'labhub/hello-world.jinja2.md'
Expand All @@ -196,6 +204,9 @@ def callback_message(self, msg):
def create_issue_cmd(self, msg, match):
"""Create issues on GitHub and GitLab repositories.""" # Ignore QuotesBear, LineLengthBear, PyCodeStyleBear
user = msg.frm.nick
if not user:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
return
repo_name = match.group(1)
iss_title = match.group(2)
iss_description = match.group(3) if match.group(3) is not None else ''
Expand Down Expand Up @@ -234,6 +245,9 @@ def unassign_cmd(self, msg, match):
issue_number = match.group(4)

user = msg.frm.nick
if not user:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
return

try:
assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME
Expand Down Expand Up @@ -317,6 +331,9 @@ def assign_cmd(self, msg, match):
iss_number = match.group(4)

user = msg.frm.nick
if not user:
self.send(msg.frm, 'ERROR: The command cannot be operated without using `nick`')
return

try:
assert org == self.GH_ORG_NAME or org == self.GL_ORG_NAME
Expand Down

1 comment on commit c0f0a89

@gitmate-bot

This comment was marked as resolved.

Please sign in to comment.