2018-09-04 22:46:42 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-09-26 17:58:30 +00:00
|
|
|
from argparse import ArgumentParser
|
2018-09-13 19:37:32 +00:00
|
|
|
from os.path import dirname, realpath
|
|
|
|
|
2018-09-12 01:08:45 +00:00
|
|
|
from bot import Bot, Tasks, Responses
|
|
|
|
from actions import actions
|
2018-09-16 00:11:02 +00:00
|
|
|
from coroutines import coroutines
|
2018-09-12 01:08:45 +00:00
|
|
|
|
2018-09-26 17:58:30 +00:00
|
|
|
parser = ArgumentParser(description="A meta bot for ~team")
|
|
|
|
parser.add_argument(
|
|
|
|
"-c",
|
|
|
|
"--config",
|
|
|
|
dest="config",
|
2018-11-12 20:00:25 +00:00
|
|
|
default="settings.json",
|
2018-09-26 17:58:30 +00:00
|
|
|
help="Load config file"
|
|
|
|
)
|
|
|
|
arguments = parser.parse_args()
|
|
|
|
|
2019-04-10 18:12:14 +00:00
|
|
|
bot = Bot("localhost", 6667)
|
2018-09-12 01:08:45 +00:00
|
|
|
responses = Responses(bot)
|
2018-09-16 00:11:02 +00:00
|
|
|
tasks = Tasks(bot)
|
|
|
|
tasks.coroutines = coroutines
|
|
|
|
|
2018-11-03 02:25:23 +00:00
|
|
|
for action in actions:
|
|
|
|
if "type" in action and "pattern" in action and "callback" in action:
|
|
|
|
responses.add_trigger(
|
|
|
|
action["type"],
|
|
|
|
action["pattern"],
|
|
|
|
action["callback"]
|
|
|
|
)
|
|
|
|
|
2018-09-13 19:37:32 +00:00
|
|
|
def try_to_king_me(channel):
|
2018-09-12 01:08:45 +00:00
|
|
|
bot.send_message("ChanServ", "REGISTER {}", channel)
|
|
|
|
bot.send_message("ChanServ", "SET Successor {} {}", channel, bot.botnick)
|
|
|
|
bot.send_message("ChanServ", "SET Founder {} {}", channel, bot.author)
|
2018-09-04 22:46:42 +00:00
|
|
|
|
2018-09-10 22:32:21 +00:00
|
|
|
def handle_pm(name, response):
|
|
|
|
print("PM: {} - {}".format(name, response))
|
|
|
|
|
|
|
|
def handle_mode(channel, mode):
|
|
|
|
if mode == "-r":
|
2018-09-13 19:37:32 +00:00
|
|
|
try_to_king_me(channel)
|
2018-09-12 01:08:45 +00:00
|
|
|
|
|
|
|
def handle_invite(channel, name):
|
2018-10-01 16:10:25 +00:00
|
|
|
changed = False
|
2018-10-10 16:19:57 +00:00
|
|
|
kingme = bot.settings.get("extras", dict()).get("kingme", [])
|
2018-10-01 16:10:25 +00:00
|
|
|
|
2018-09-12 01:08:45 +00:00
|
|
|
if channel in kingme:
|
2018-09-13 19:37:32 +00:00
|
|
|
try_to_king_me(channel)
|
|
|
|
|
|
|
|
users = bot.memories["users"]
|
|
|
|
if name not in users:
|
|
|
|
bot.memories["users"][name] = dict()
|
2018-10-01 16:10:25 +00:00
|
|
|
changed = True
|
2018-09-13 19:37:32 +00:00
|
|
|
|
|
|
|
if "invites" not in users[name]:
|
|
|
|
bot.memories["users"][name]["invites"] = list()
|
2018-10-01 16:10:25 +00:00
|
|
|
changed = True
|
|
|
|
|
|
|
|
if channel not in bot.memories["users"][name]["invites"]:
|
|
|
|
bot.memories["users"][name]["invites"].append(channel)
|
|
|
|
changed = True
|
2018-09-13 19:37:32 +00:00
|
|
|
|
2019-04-10 18:12:14 +00:00
|
|
|
#if changed:
|
|
|
|
# bot.thread(bot.save_memories)
|
2018-09-12 01:08:45 +00:00
|
|
|
|
2019-03-07 17:37:55 +00:00
|
|
|
def handle_kick(name, source):
|
|
|
|
if source in bot.settings.get("extras", dict()).get("rejoin", list()):
|
|
|
|
bot.join(source)
|
2018-09-13 19:37:32 +00:00
|
|
|
users = bot.memories["users"]
|
|
|
|
if name not in users:
|
|
|
|
bot.memories["users"][name] = dict()
|
2018-09-12 01:08:45 +00:00
|
|
|
|
2018-09-13 19:37:32 +00:00
|
|
|
bot.memories["users"][name]["kicker"] = True
|
2019-04-10 18:12:14 +00:00
|
|
|
#bot.thread(bot.save_memories)
|
2018-09-12 01:08:45 +00:00
|
|
|
|
|
|
|
def handle_message(name, source, response):
|
|
|
|
responses.parse(name, source, response)
|
2018-09-13 19:37:32 +00:00
|
|
|
if response == "!debug":
|
2018-11-03 02:25:23 +00:00
|
|
|
bot.logger.debug(":: {}".format(bot.memories))
|
2018-09-04 22:46:42 +00:00
|
|
|
|
2018-11-27 20:23:23 +00:00
|
|
|
def handle_raw(message):
|
2019-04-10 18:12:14 +00:00
|
|
|
if "KICK #chaos {} :".format(bot.author) in message:
|
2019-03-07 17:37:55 +00:00
|
|
|
bot.send("INVITE {} :#chaos".format(bot.author))
|
2018-11-27 20:23:23 +00:00
|
|
|
|
2018-10-10 16:19:57 +00:00
|
|
|
def handle_crashed():
|
2018-11-03 02:25:23 +00:00
|
|
|
bot.logger.debug("Rebooting")
|
|
|
|
bot.crashed = True
|
|
|
|
bot.tasks.stop()
|
|
|
|
|
|
|
|
tasks = Tasks(bot)
|
|
|
|
tasks.coroutines = coroutines
|
|
|
|
|
2018-10-10 16:19:57 +00:00
|
|
|
bot.tasks = tasks
|
|
|
|
bot.start(arguments.config, dirname(realpath(__file__)), {
|
|
|
|
"pm": handle_pm,
|
|
|
|
"mode": handle_mode,
|
|
|
|
"invite": handle_invite,
|
|
|
|
"kick": handle_kick,
|
|
|
|
"crashed": handle_crashed,
|
|
|
|
"message": handle_message
|
|
|
|
})
|
|
|
|
|
2018-09-04 22:46:42 +00:00
|
|
|
if __name__ == "__main__":
|
2018-09-16 00:11:02 +00:00
|
|
|
bot.tasks = tasks
|
2018-09-26 17:58:30 +00:00
|
|
|
bot.start(arguments.config, dirname(realpath(__file__)), {
|
2018-09-10 22:32:21 +00:00
|
|
|
"pm": handle_pm,
|
2018-09-12 01:08:45 +00:00
|
|
|
"mode": handle_mode,
|
|
|
|
"invite": handle_invite,
|
|
|
|
"kick": handle_kick,
|
2018-10-10 16:19:57 +00:00
|
|
|
"crashed": handle_crashed,
|
2018-11-27 20:23:23 +00:00
|
|
|
"message": handle_message,
|
|
|
|
"raw": handle_raw
|
2018-11-12 20:00:25 +00:00
|
|
|
})
|