2018-07-15 13:14:20 +00:00
|
|
|
import datetime
|
2018-09-27 10:46:10 +00:00
|
|
|
from src import EventManager, ModuleManager, Utils
|
2018-07-15 13:14:20 +00:00
|
|
|
|
2018-09-27 10:46:10 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-07-23 09:20:00 +00:00
|
|
|
def print_line(self, event, line, channel=None):
|
2018-07-15 13:14:20 +00:00
|
|
|
timestamp = datetime.datetime.now().isoformat()
|
|
|
|
target = str(event["server"])
|
2018-07-23 09:20:00 +00:00
|
|
|
if not channel == None:
|
|
|
|
target += channel
|
2018-08-28 11:23:57 +00:00
|
|
|
self.bot.log.info("%s | %s", [target, line])
|
2018-07-15 13:14:20 +00:00
|
|
|
|
|
|
|
def _on_message(self, event, nickname):
|
|
|
|
if not self.bot.args.verbose:
|
|
|
|
if event["action"]:
|
2018-07-23 09:20:00 +00:00
|
|
|
self.print_line(event, "* %s %s" % (
|
|
|
|
nickname, event["message"]),
|
|
|
|
channel=event["channel"].name)
|
2018-07-15 13:14:20 +00:00
|
|
|
else:
|
2018-07-23 09:20:00 +00:00
|
|
|
self.print_line(event, "<%s> %s" % (
|
|
|
|
nickname, event["message"]),
|
|
|
|
channel=event["channel"].name)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.message.channel",
|
|
|
|
priority=EventManager.PRIORITY_HIGH)
|
2018-07-15 13:14:20 +00:00
|
|
|
def channel_message(self, event):
|
|
|
|
self._on_message(event, event["user"].nickname)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("self.message.channel")
|
2018-07-15 13:14:20 +00:00
|
|
|
def self_channel_message(self, event):
|
|
|
|
self._on_message(event, event["server"].nickname)
|
|
|
|
|
2018-07-23 09:20:00 +00:00
|
|
|
def _on_notice(self, event, target):
|
|
|
|
self.print_line(event, "(notice->%s) <%s> %s" % (
|
|
|
|
target, event["user"].nickname, event["message"]))
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.notice.channel",
|
|
|
|
priority=EventManager.PRIORITY_HIGH)
|
2018-07-23 09:20:00 +00:00
|
|
|
def channel_notice(self, event):
|
|
|
|
self._on_notice(event, event["channel"].name)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.notice.private", priority=EventManager.PRIORITY_HIGH)
|
2018-07-23 09:20:00 +00:00
|
|
|
def private_notice(self, event):
|
|
|
|
self._on_notice(event, event["server"].nickname)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.server-notice", priority=EventManager.PRIORITY_HIGH)
|
2018-07-23 09:20:00 +00:00
|
|
|
def server_notice(self, event):
|
|
|
|
self.print_line(event, "(server notice) %s" % event["message"])
|
|
|
|
|
2018-07-15 13:14:20 +00:00
|
|
|
def _on_join(self, event, nickname):
|
|
|
|
if not self.bot.args.verbose:
|
|
|
|
self.print_line(event, "%s joined %s" % (nickname,
|
|
|
|
event["channel"].name))
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.join")
|
2018-07-15 13:14:20 +00:00
|
|
|
def join(self, event):
|
|
|
|
self._on_join(event, event["user"].nickname)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("self.join")
|
2018-07-15 13:14:20 +00:00
|
|
|
def self_join(self, event):
|
|
|
|
self._on_join(event, event["server"].nickname)
|
|
|
|
|
|
|
|
def _on_part(self, event, nickname):
|
|
|
|
if not self.bot.args.verbose:
|
|
|
|
self.print_line(event, "%s left %s%s" % (nickname,
|
|
|
|
event["channel"].name, "" if not event[
|
2018-07-15 14:22:37 +00:00
|
|
|
"reason"] else " (%s)" % event["reason"]))
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.part")
|
2018-07-15 13:14:20 +00:00
|
|
|
def part(self, event):
|
|
|
|
self._on_part(event, event["user"].nickname)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("self.part")
|
2018-07-15 13:14:20 +00:00
|
|
|
def self_part(self, event):
|
|
|
|
self._on_part(event, event["server"].nickname)
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.nick")
|
|
|
|
@Utils.hook("self.nick")
|
2018-07-15 13:14:20 +00:00
|
|
|
def on_nick(self, event):
|
|
|
|
if not self.bot.args.verbose:
|
|
|
|
self.print_line(event, "%s changed nickname to %s" % (
|
|
|
|
event["old_nickname"], event["new_nickname"]))
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.quit")
|
2018-07-15 13:14:20 +00:00
|
|
|
def on_quit(self, event):
|
|
|
|
if not self.bot.args.verbose:
|
2018-07-20 12:12:55 +00:00
|
|
|
self.print_line(event, "%s quit%s" % (event["user"].nickname,
|
2018-07-31 07:48:37 +00:00
|
|
|
"" if not event["reason"] else " (%s)" % event["reason"]))
|
2018-07-15 13:14:20 +00:00
|
|
|
|
|
|
|
def _on_kick(self, event, nickname):
|
|
|
|
if not self.bot.args.verbose:
|
|
|
|
self.print_line(event, "%s kicked %s from %s%s" % (
|
|
|
|
event["user"].nickname, nickname, event["channel"].name,
|
2018-07-15 14:22:37 +00:00
|
|
|
"" if not event["reason"] else " (%s)" % event["reason"]))
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.kick")
|
2018-07-15 13:14:20 +00:00
|
|
|
def kick(self, event):
|
|
|
|
self._on_kick(event, event["target_user"].nickname)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("self.kick")
|
2018-07-15 13:14:20 +00:00
|
|
|
def self_kick(self, event):
|
|
|
|
self._on_kick(event, event["server"].nickname)
|
2018-08-29 13:57:40 +00:00
|
|
|
|
2018-08-29 14:17:06 +00:00
|
|
|
def _on_topic(self, event, setter, action, topic, channel):
|
|
|
|
self.print_line(event, "topic %s by %s: %s" % (action, setter,
|
|
|
|
topic), channel=channel.name)
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.topic")
|
2018-08-29 13:57:40 +00:00
|
|
|
def on_topic(self, event):
|
2018-08-29 14:17:06 +00:00
|
|
|
self._on_topic(event, event["user"].nickname, "changed",
|
|
|
|
event["topic"], event["channel"])
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.numeric.333")
|
2018-08-29 14:17:06 +00:00
|
|
|
def on_333(self, event):
|
|
|
|
self._on_topic(event, event["setter"], "set",
|
|
|
|
event["channel"].topic, event["channel"])
|
2018-09-02 21:41:04 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.mode.channel")
|
2018-09-02 21:41:04 +00:00
|
|
|
def mode(self, event):
|
|
|
|
args = " ".join(event["mode_args"])
|
|
|
|
if args:
|
|
|
|
args = " %s" % args
|
|
|
|
self.print_line(event, "%s set mode %s%s" % (
|
|
|
|
event["user"].nickname, "".join(event["modes"]),
|
|
|
|
args), channel=event["channel"].name)
|