fulvia/modules/away.py

47 lines
1.1 KiB
Python
Executable File

#! /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]}"
bot.msg(msg)
@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)