Skip to content

Commit

Permalink
feat: add bot.hostmask getter
Browse files Browse the repository at this point in the history
Adds shortcut for `bot.users.get(bot.nick).hostmask`.

Closes #1533.
  • Loading branch information
HumorBaby committed Apr 4, 2019
1 parent d06898f commit 940e60d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ def __init__(self, config, daemon=False):
self.config.core.host_blocks = []
self.setup()

@property
def hostmask(self):
"""str: the current hostmask for the bot :class:`sopel.tools.target.User`
Bot must be connected and in at least one channel.
"""
if not self.users or not self.users.contains(self.nick):
raise KeyError("'hostmask' not available: bot must be connected and in at least one channel.")

return self.users.get(self.nick).hostmask

# Backwards-compatibility aliases to attributes made private in 6.2. Remove
# these in 7.0
times = property(lambda self: getattr(self, '_times'))
Expand Down

0 comments on commit 940e60d

Please sign in to comment.