aboutsummaryrefslogtreecommitdiff
path: root/modules/ctcp.py
blob: f646cedf04d37496bb2d468e97ff1137d9a29865 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Module(object):
    def __init__(self, bot):
        bot.events.on("received").on("message").on("private").hook(
            self.private_message)
        self.bot = bot

    def private_message(self, event):
        if event["message"][0] == "\x01" and event["message"][-1] == "\x01":
            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(" ")

            ctcp_response = None
            if ctcp_command == "VERSION":
                ctcp_response = self.bot.config.get("ctcp-version",
                    "BitBot")
            elif ctcp_command == "PING":
                ctcp_response = " ".join(ctcp_args_split)

            if ctcp_response:
                event["user"].send_ctcp_response(ctcp_command,
                    ctcp_response)