Exemple #1
0
    def handleCTCP(self, server, source, user, message):
        if not self.bot.moduleHandler.useModuleOnServer(self.name, server):
            return

        if message.upper() == "PING" or message.upper().startswith("PING "):
            self.sendCTCPReply(server, user.nick, "PING", message[5:])
        elif message.upper() == "VERSION":
            self.sendCTCPReply(server, user.nick, "VERSION", "PyHeufyBot v{} / {}".format(__version__, platform()))
        elif message.upper() == "TIME":
            self.sendCTCPReply(server, user.nick, "TIME", strftimeWithTimezone(now()))
        elif message.upper() == "SOURCE":
            self.sendCTCPReply(server, user.nick, "SOURCE", "https://github.com/Heufneutje/PyHeufyBot/")
Exemple #2
0
    def handleCTCP(self, server, source, user, message):
        if not self.bot.moduleHandler.useModuleOnServer(self.name, server):
            return

        if message.upper() == "PING" or message.upper().startswith("PING "):
            self.sendCTCPReply(server, user.nick, "PING", message[5:])
        elif message.upper() == "VERSION":
            self.sendCTCPReply(
                server, user.nick, "VERSION",
                "PyHeufyBot v{} / {}".format(__version__, platform()))
        elif message.upper() == "TIME":
            self.sendCTCPReply(server, user.nick, "TIME",
                               strftimeWithTimezone(now()))
        elif message.upper() == "SOURCE":
            self.sendCTCPReply(server, user.nick, "SOURCE",
                               "https://github.com/Heufneutje/PyHeufyBot/")
Exemple #3
0
 def execute(self, server, source, command, params, data):
     start = strftimeWithTimezone(self.bot.startTime)
     delta = timeDeltaString(now(), self.bot.startTime)
     self.replyPRIVMSG(server, source, "I have been up since {} ({}).".format(start, delta))
Exemple #4
0
 def execute(self, server, source, command, params, data):
     start = strftimeWithTimezone(self.bot.startTime)
     delta = timeDeltaString(now(), self.bot.startTime)
     self.replyPRIVMSG(server, source,
                       "I have been up since {} ({}).".format(start, delta))
Exemple #5
0
 def execute(self, server, source, command, params, data):
     if command == "tell" or command == "tellafter":
         if len(params) == 0 or len(params) == 1:
             self.replyPRIVMSG(server, source, "Tell who?")
             return
         elif len(params) == 1 and command == "tellafter":
             self.replyPRIVMSG(server, source, "Tell it when?")
             return
         elif len(params
                  ) == 1 or len(params) == 2 and command == "tellafter":
             self.replyPRIVMSG(server, source,
                               "Tell {} what?".format(params[0]))
             return
         sentTells = []
         if command == "tellafter":
             try:
                 date = datetime.strptime(params[1], "%Y-%m-%d")
             except ValueError:
                 date = now() + durationToTimedelta(params[1])
         else:
             date = now()
         for recep in params[0].split("&"):
             if recep.lower() == self.bot.servers[server].nick.lower():
                 self.replyPRIVMSG(
                     server, source,
                     "Thanks for telling me that, {}.".format(
                         data["user"].nick))
                 continue
             message = {
                 "to":
                 recep.lower(),
                 "body":
                 " ".join(params[1:])
                 if command == "tell" else " ".join(params[2:]),
                 "date":
                 now(),
                 "datetoreceive":
                 date,
                 "from":
                 data["user"].nick,
                 "source":
                 source if source[0]
                 in self.bot.servers[server].supportHelper.chanTypes else
                 "PM"
             }
             if networkName(self.bot, server) not in self.tells:
                 self.tells[networkName(self.bot, server)] = []
             self.tells[networkName(self.bot, server)].append(message)
             sentTells.append(recep.replace("/", " or "))
         if len(sentTells) > 0:
             if command == "tellafter":
                 m = "Okay, I'll tell {} that when they speak after {}.".format(
                     "&".join(sentTells), strftimeWithTimezone(date))
             else:
                 m = "Okay, I'll tell {} that next time they speak.".format(
                     "&".join(sentTells))
             self.replyPRIVMSG(server, source, m)
         self.bot.storage["tells"] = self.tells
     elif command == "stells":
         if networkName(self.bot, server) not in self.tells:
             return
         tells = []
         for tell in self.tells[networkName(self.bot, server)]:
             if tell["from"].lower() == data["user"].nick.lower():
                 tells.append(self._parseSentTell(tell))
         if len(tells) > 0:
             for tell in tells:
                 self.replyNOTICE(server, data["user"].nick, tell)
         else:
             self.replyNOTICE(
                 server, data["user"].nick,
                 "No undelivered messages sent by you were found.")
     elif command == "rtell":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "Remove what?")
             return
         if networkName(self.bot, server) not in self.tells:
             self.replyNOTICE(
                 server, data["user"].nick,
                 "No tells matching {!r} were found.".format(params[0]))
             return
         tells = [
             x for x in self.tells[networkName(self.bot, server)]
             if x["from"].lower() == data["user"].nick.lower()
         ]
         for tell in tells:
             if re.search(" ".join(params), tell["body"], re.IGNORECASE):
                 self.tells[networkName(self.bot, server)].remove(tell)
                 self.bot.storage["tells"] = self.tells
                 m = "Message {!r} was removed from the message database.".format(
                     self._parseSentTell(tell))
                 self.replyNOTICE(server, data["user"].nick, m)
                 break
         else:
             self.replyNOTICE(
                 server, data["user"].nick,
                 "No tells matching {!r} were found.".format(params[0]))
Exemple #6
0
 def _parseSentTell(self, tell):
     return "{} < Sent to {} on {}, to be received on {} in {}.".format(
         tell["body"], tell["to"], strftimeWithTimezone(tell["date"]),
         strftimeWithTimezone(tell["datetoreceive"]), tell["source"])
Exemple #7
0
 def execute(self, server, source, command, params, data):
     if command == "tell" or command == "tellafter":
         if len(params) == 0 or len(params) == 1:
             self.replyPRIVMSG(server, source, "Tell who?")
             return
         elif len(params) == 1 and command == "tellafter":
             self.replyPRIVMSG(server, source, "Tell it when?")
             return
         elif len(params) == 1 or len(params) == 2 and command == "tellafter":
             self.replyPRIVMSG(server, source, "Tell {} what?".format(params[0]))
             return
         sentTells = []
         if command == "tellafter":
             try:
                 date = datetime.strptime(params[1], "%Y-%m-%d")
             except ValueError:
                 date = now() + durationToTimedelta(params[1])
         else:
             date = now()
         for recep in params[0].split("&"):
             if recep.lower() == self.bot.servers[server].nick.lower():
                 self.replyPRIVMSG(server, source, "Thanks for telling me that, {}.".format(data["user"].nick))
                 continue
             message = {
                 "to": recep.lower(),
                 "body": " ".join(params[1:]) if command == "tell" else " ".join(params[2:]),
                 "date": now(),
                 "datetoreceive": date,
                 "from": data["user"].nick,
                 "source": source if source[0] in self.bot.servers[server].supportHelper.chanTypes else "PM"
             }
             if networkName(self.bot, server) not in self.tells:
                 self.tells[networkName(self.bot, server)] = []
             self.tells[networkName(self.bot, server)].append(message)
             sentTells.append(recep.replace("/", " or "))
         if len(sentTells) > 0:
             if command == "tellafter":
                 m = "Okay, I'll tell {} that when they speak after {}.".format("&".join(sentTells),
                                                                                strftimeWithTimezone(date))
             else:
                 m = "Okay, I'll tell {} that next time they speak.".format("&".join(sentTells))
             self.replyPRIVMSG(server, source, m)
         self.bot.storage["tells"] = self.tells
     elif command == "stells":
         if networkName(self.bot, server) not in self.tells:
             return
         tells = []
         for tell in self.tells[networkName(self.bot, server)]:
             if tell["from"].lower() == data["user"].nick.lower():
                 tells.append(self._parseSentTell(tell))
         if len(tells) > 0:
             for tell in tells:
                 self.replyNOTICE(server, data["user"].nick, tell)
         else:
             self.replyNOTICE(server, data["user"].nick, "No undelivered messages sent by you were found.")
     elif command == "rtell":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "Remove what?")
             return
         if networkName(self.bot, server) not in self.tells:
             self.replyNOTICE(server, data["user"].nick, "No tells matching {!r} were found.".format(params[0]))
             return
         tells = [x for x in self.tells[networkName(self.bot, server)] if x["from"].lower() == data[
             "user"].nick.lower()]
         for tell in tells:
             if re.search(" ".join(params), tell["body"], re.IGNORECASE):
                 self.tells[networkName(self.bot, server)].remove(tell)
                 self.bot.storage["tells"] = self.tells
                 m = "Message {!r} was removed from the message database.".format(self._parseSentTell(tell))
                 self.replyNOTICE(server, data["user"].nick, m)
                 break
         else:
             self.replyNOTICE(server, data["user"].nick, "No tells matching {!r} were found.".format(params[0]))
Exemple #8
0
 def _parseSentTell(self, tell):
     return "{} < Sent to {} on {}, to be received on {} in {}.".format(tell["body"], tell["to"],
                                                                        strftimeWithTimezone(tell["date"]),
                                                                        strftimeWithTimezone(tell["datetoreceive"]),
                                                                        tell["source"])
Exemple #9
0
 def execute(self, server, source, command, params, data):
     if networkName(self.bot, server) not in self.events:
         self.events[networkName(self.bot, server)] = []
     if command == "event":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "Add what event?")
             return
         try:
             date = datetime.strptime(" ".join(params[0:2]), "%Y-%m-%d %H:%M")
             eventOffset = 2
             if len(params) < 3:
                 self.replyPRIVMSG(server, source, "Add what event?")
                 return
         except ValueError:
             try:
                 date = datetime.strptime(params[0], "%Y-%m-%d")
                 eventOffset = 1
                 if len(params) < 2:
                     self.replyPRIVMSG(server, source, "Add what event?")
                     return
             except ValueError:
                 e = "The date format you specified is invalid. The format is yyyy-MM-dd or yyyy-MM-dd HH:mm."
                 self.replyPRIVMSG(server, source, e)
                 return
         event = {
             "event": " ".join(params[eventOffset:]),
             "date": date,
             "user": data["user"].nick,
             "fired": True if date < now() else False
         }
         self.events[networkName(self.bot, server)].append(event)
         self.bot.storage["events"] = self.events
         m = "Event {!r} on date {} was added to the events database!".format(event["event"],
                                                                              strftimeWithTimezone(date))
         self.replyPRIVMSG(server, source, m)
     elif command == "timetill":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "You didn't specify an event")
             return
         events = [x for x in self.events[networkName(self.bot, server)] if x["date"] > now()]
         events.sort(key=lambda item: item["date"])
         for event in events:
             if re.search(" ".join(params), event["event"], re.IGNORECASE):
                 m = "{}'s event {!r} will occur in {}.".format(event["user"], event["event"], timeDeltaString(
                     event["date"], now()))
                 self.replyPRIVMSG(server, source, m)
                 break
         else:
             m = "No events matching {!r} were found in the events database.".format(" ".join(params))
             self.replyPRIVMSG(server, source, m)
     elif command == "timesince":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "You didn't specify an event")
             return
         events = [x for x in self.events[networkName(self.bot, server)] if x["date"] < now()]
         events.sort(key=lambda item: item["date"], reverse=True)
         for event in events:
             if re.search(" ".join(params), event["event"], re.IGNORECASE):
                 m = "{}'s event {!r} occurred {} ago.".format(event["user"], event["event"], timeDeltaString(
                     now(), event["date"]))
                 self.replyPRIVMSG(server, source, m)
                 break
         else:
             m = "No events matching {!r} were found in the events database.".format(" ".join(params))
             self.replyPRIVMSG(server, source, m)
     elif command == "dateof":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "You didn't specify an event")
             return
         events = [x for x in self.events[networkName(self.bot, server)] if x["date"] > now()]
         events.sort(key=lambda item: item["date"])
         for event in events:
             if re.search(" ".join(params), event["event"], re.IGNORECASE):
                 m = "{}'s event {!r} will occur on {}.".format(event["user"], event["event"],
                                                                strftimeWithTimezone(event["date"]))
                 self.replyPRIVMSG(server, source, m)
                 break
         else:
             events = [x for x in self.events[networkName(self.bot, server)] if x["date"] < now()]
             events.sort(key=lambda item: item["date"], reverse=True)
             for event in events:
                 if re.search(" ".join(params), event["event"], re.IGNORECASE):
                     m = "{}'s event {!r} occurred on {}.".format(event["user"], event["event"],
                                                                  strftimeWithTimezone(event["date"]))
                     self.replyPRIVMSG(server, source, m)
                     break
             else:
                 m = "No events matching {!r} were found in the events database.".format(" ".join(params))
                 self.replyPRIVMSG(server, source, m)
     elif command == "events":
         if len(params) == 0 or not isNumber(params[0]):
             days = 7
         else:
             days = int(params[0]) if int(params[0]) < 365 else 365
         events = [x for x in self.events[networkName(self.bot, server)] if x["date"] > now() and x[
             "date"] <= now() + timedelta(days)]
         dayString = "" if days == 1 else "s"
         if len(events) > 0:
             events.sort(key=lambda item: item["date"])
             eventNames = [x["event"] for x in events]
             m = "Events occurring in the next {} day{}: {}.".format(days, dayString, ", ".join(eventNames))
         else:
             m = "No events are occurring in the next {} day{}.".format(days, dayString)
         self.replyPRIVMSG(server, source, m)
     elif command == "revent":
         if len(params) == 0:
             self.replyPRIVMSG(server, source, "You didn't specify an event")
             return
         events = [x for x in self.events[networkName(self.bot, server)] if x["date"] > now()]
         events.sort(key=lambda item: item["date"])
         for event in events:
             if re.search(" ".join(params), event["event"], re.IGNORECASE):
                 self.events[networkName(self.bot, server)].remove(event)
                 self.bot.storage["events"] = self.events
                 m = "{}'s event {!r} with date {} has been removed from the events database.".format(
                     event["user"], event["event"], strftimeWithTimezone(event["date"]))
                 self.replyPRIVMSG(server, source, m)
                 break
         else:
             events = [x for x in self.events[networkName(self.bot, server)] if x["date"] < now() and x[
                 "user"].lower() == data["user"].nick.lower()]
             events.sort(key=lambda item: item["date"], reverse=True)
             for event in events:
                 if re.search(" ".join(params), event["event"], re.IGNORECASE):
                     self.events[networkName(self.bot, server)].remove(event)
                     self.bot.storage["events"] = self.events
                     m = "{}'s event {!r} with date {} has been removed from the events database.".format(
                         event["user"], event["event"], strftimeWithTimezone(event["date"]))
                     self.replyPRIVMSG(server, source, m)
                     break
             else:
                 m = "No events matching {!r} by you were found in the events database.".format(" ".join(params))
                 self.replyPRIVMSG(server, source, m)
     elif command == "subevent" or command == "unsubevent":
         if networkName(self.bot, server) not in self.subscriptions:
             self.subscriptions[networkName(self.bot, server)] = []
         src = source if "channel" in data else data["user"].nick
         subAction = command == "subevent"
         self._handleSubscription(server, src, subAction)