fulvia/modules/away.py

47 lines
1.1 KiB
Python
Raw Normal View History

2018-03-16 03:13:43 -04:00
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
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.
"""
if not trigger.group(2):
bot.memory['away'][trigger.nick] = ""
else:
bot.memory['away'][trigger.nick] = trigger.group(2)
@hook(True)
def message(bot, trigger):
"""
If an away users name is said, print their away message.
"""
name = trigger.group(1)
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.
"""
if not trigger.group(0).startswith(".away"):
if trigger.nick in bot.memory["away"]:
bot.memory["away"].pop(trigger.nick)