2020-01-08 07:51:00 -05:00
|
|
|
#!/usr/bin/env python3
|
2018-03-16 03:13:43 -04:00
|
|
|
"""
|
|
|
|
Marks a user as away with an optional message and informs anyone who attempt
|
|
|
|
to ping them of their away status. Goes away when the user talks again.
|
|
|
|
"""
|
|
|
|
from module import commands, example, hook
|
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
bot.memory['away'] = {}
|
|
|
|
|
|
|
|
|
|
|
|
@commands('away')
|
|
|
|
@example('.away commiting sudoku')
|
|
|
|
def away(bot, trigger):
|
|
|
|
"""
|
|
|
|
Stores in the user's name and away message in memory.
|
|
|
|
"""
|
2020-01-07 18:58:19 -05:00
|
|
|
if len(trigger.args) < 2:
|
2018-03-16 03:13:43 -04:00
|
|
|
bot.memory['away'][trigger.nick] = ""
|
|
|
|
else:
|
2020-01-07 18:58:19 -05:00
|
|
|
bot.memory['away'][trigger.nick] = ' '.join(trigger.args[1:])
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
@hook(True)
|
|
|
|
def message(bot, trigger):
|
|
|
|
"""
|
|
|
|
If an away users name is said, print their away message.
|
|
|
|
"""
|
2020-01-07 18:58:19 -05:00
|
|
|
name = trigger.args[0]
|
2018-03-16 03:13:43 -04:00
|
|
|
if name.endswith(":") or name.endswith(","):
|
|
|
|
name = name[:-1]
|
|
|
|
if name in bot.memory["away"]:
|
|
|
|
print(True)
|
|
|
|
msg = f"\x0308{name}\x03 is away: \x0311{bot.memory['away'][name]}"
|
2018-05-25 15:21:18 -04:00
|
|
|
bot.msg(msg)
|
2018-03-16 03:13:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
@hook(True)
|
|
|
|
def notAway(bot, trigger):
|
|
|
|
"""
|
|
|
|
If an away user says something, remove them from the away dict.
|
|
|
|
"""
|
2020-01-07 18:58:19 -05:00
|
|
|
if not trigger.args[0] == ".away":
|
2018-03-16 03:13:43 -04:00
|
|
|
if trigger.nick in bot.memory["away"]:
|
|
|
|
bot.memory["away"].pop(trigger.nick)
|