Change to.py to use user_channel_settings in to.py and set priority to MEDIUM to

avoid !to to one's self sending two messages
This commit is contained in:
jesopo 2018-08-05 12:53:02 +01:00
parent 28debfa919
commit 38a518f1fa

View file

@ -1,27 +1,30 @@
import EventManager
class Module(object): class Module(object):
def __init__(self, bot): def __init__(self, bot):
bot.events.on("received").on("message").on("channel" bot.events.on("received").on("message").on("channel"
).hook(self.channel_message) ).hook(self.channel_message,
priority=EventManager.PRIORITY_MEDIUM)
bot.events.on("received").on("command").on("to").hook( bot.events.on("received").on("command").on("to").hook(
self.to, min_args=2, help=("Relay a message to a " self.to, min_args=2, help=("Relay a message to a "
"user the next time they talk in a channel"), "user the next time they talk in a channel"),
channel_only=True, usage="<username> <message>") channel_only=True, usage="<username> <message>")
def channel_message(self, event): def channel_message(self, event):
setting = "to-%s" % event["user"].nickname messages = event["channel"].get_user_setting(
messages = event["channel"].get_setting(setting, []) event["user"].nickname, "to", [])
for nickname, message in messages: for nickname, message in messages:
event["channel"].send_message("%s: <%s> %s" % ( event["channel"].send_message("%s: <%s> %s" % (
event["user"].nickname, nickname, message)) event["user"].nickname, nickname, message))
if messages: if messages:
event["channel"].del_setting(setting) event["channel"].del_user_setting(
event["user"].nickname, "to")
def to(self, event): def to(self, event):
setting = "to-%s" % event["args_split"][0] messages = event["target"].get_user_setting(
messages = event["target"].get_setting(setting, []) event["user"].nickname, "to", [])
messages.append([event["user"].nickname, messages.append([event["user"].nickname,
" ".join(event["args_split"][1:])]) " ".join(event["args_split"][1:])])
event["target"].set_setting(setting, messages) event["target"].set_user_setting(
event["user"].nickname, "to", messages)
event["stdout"].write("Message saved") event["stdout"].write("Message saved")