57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
|
#! /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, rule, priority
|
||
|
from tools import Identifier
|
||
|
|
||
|
def setup(bot):
|
||
|
bot.memory['away'] = {}
|
||
|
|
||
|
|
||
|
@commands('away')
|
||
|
@example('.away Gonna go kill myself.', 'User is now away: Gonna go kill myself.')
|
||
|
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)
|
||
|
|
||
|
|
||
|
@rule('(.*)')
|
||
|
@priority('low')
|
||
|
def message(bot, trigger):
|
||
|
"""
|
||
|
If an away users name is said, print their away message.
|
||
|
"""
|
||
|
for key in bot.memory['away'].keys():
|
||
|
msg = "\x0308" + key + "\x03 is away: \x0311" + \
|
||
|
bot.memory['away'][key]
|
||
|
if trigger.startswith(key+":"):
|
||
|
return bot.say(msg)
|
||
|
elif trigger.startswith(key+","):
|
||
|
return bot.say(msg)
|
||
|
elif trigger == key:
|
||
|
return bot.say(msg)
|
||
|
"""
|
||
|
name = Identifier(trigger.group(1))
|
||
|
if name in bot.memory['away'].keys():
|
||
|
msg = "\x0308" + name + "\x03 is away: \x0311" + \
|
||
|
bot.memory['away'][name]
|
||
|
bot.say(msg)
|
||
|
"""
|
||
|
|
||
|
@rule('(.*)')
|
||
|
@priority('low')
|
||
|
def notAway(bot, trigger):
|
||
|
"""
|
||
|
If an away user says something, remove them from the away dict.
|
||
|
"""
|
||
|
if trigger.nick in bot.memory['away'].keys() and not trigger.group(0).startswith(".away"):
|
||
|
bot.memory['away'].pop(trigger.nick, None)
|