2016-03-31 11:10:51 +00:00
|
|
|
import datetime
|
2018-09-24 14:13:27 +00:00
|
|
|
from src import Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2016-03-29 11:56:58 +00:00
|
|
|
self.bot = bot
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.message.private").hook(self.private_message)
|
2018-09-09 09:17:22 +00:00
|
|
|
exports.add("serverset", {"setting": "ctcp-responses",
|
|
|
|
"help": "Set whether I respond to CTCPs on this server",
|
|
|
|
"validate": Utils.bool_or_none})
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def private_message(self, event):
|
|
|
|
if event["message"][0] == "\x01" and event["message"][-1] == "\x01":
|
2018-08-08 12:41:25 +00:00
|
|
|
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(" ")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-08-08 12:41:25 +00:00
|
|
|
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")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-08-08 12:41:25 +00:00
|
|
|
if ctcp_response:
|
|
|
|
event["user"].send_ctcp_response(ctcp_command,
|
|
|
|
ctcp_response)
|