aboutsummaryrefslogtreecommitdiff
path: root/modules/ctcp.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-02-12 16:49:57 +0000
committerGravatar jesopo2019-02-12 16:49:57 +0000
commit938495fc3a3a7ac8c48363b997935358dcdb61c1 (patch)
treece093fa5cac72bc3c6e7a155e5c30df548710b67 /modules/ctcp.py
parentAlso strip \x01 off the start of CTCP commands, if it's there (utils.irc) (diff)
Refactor how CTCPs are sent through events
Diffstat (limited to 'modules/ctcp.py')
-rw-r--r--modules/ctcp.py42
1 files changed, 19 insertions, 23 deletions
diff --git a/modules/ctcp.py b/modules/ctcp.py
index f165b03d..5ccf85c7 100644
--- a/modules/ctcp.py
+++ b/modules/ctcp.py
@@ -1,32 +1,28 @@
import datetime
from src import ModuleManager, utils
+VERSION_DEFAULT = "BitBot (https://git.io/bitbot)"
+SOURCE_DEFAULT = "https://git.io/bitbot"
+
@utils.export("serverset", {"setting": "ctcp-responses",
"help": "Set whether I respond to CTCPs on this server",
"validate": utils.bool_or_none})
class Module(ModuleManager.BaseModule):
- @utils.hook("received.message.private")
- def private_message(self, event):
- if event["message"][0] == "\x01" and event["message"][-1] == "\x01":
- if event["server"].get_setting("ctcp-responses", True):
- ctcp_command = event["message_split"][0][1:].upper()
- if ctcp_command.endswith("\x01"):
- ctcp_command = ctcp_command[:-1]
- ctcp_args = " ".join(event["message_split"][1:])[:-1]
- ctcp_args_split = ctcp_args.split(" ")
+ @utils.hook("received.ctcp.version.private")
+ def ctcp_version(self, event):
+ event["user"].send_ctcp_response("VERSION",
+ self.bot.config.get("ctcp-version", VERSION_DEFAULT))
+
+ @utils.hook("received.ctcp.source.private")
+ def ctcp_source(self, event):
+ event["user"].send_ctcp_response("SOURCE",
+ self.bot.config.get("ctcp-source", SOURCE_DEFAULT))
- ctcp_response = None
- if ctcp_command == "VERSION":
- ctcp_response = self.bot.config.get("ctcp-version",
- "BitBot (https://github.com/jesopo/bitbot)")
- elif ctcp_command == "SOURCE":
- ctcp_response = self.bot.config.get("ctcp-source",
- "https://github.com/jesopo/bitbot")
- elif ctcp_command == "PING":
- ctcp_response = " ".join(ctcp_args_split)
- elif ctcp_command == "TIME":
- ctcp_response = datetime.datetime.now().strftime("%c")
+ @utils.hook("received.ctcp.ping.private")
+ def ctcp_ping(self, event):
+ event["user"].send_ctcp_response("PING", event["message"])
- if ctcp_response:
- event["user"].send_ctcp_response(ctcp_command,
- ctcp_response)
+ @utils.hook("received.ctcp.time.private")
+ def ctcp_time(self, event):
+ event["user"].send_ctcp_response("TIME",
+ datetme.datetime.now().strftime("%c"))