forked from aewens/babili-bot
Various bug fixes
This commit is contained in:
parent
57419aa78a
commit
721215b013
|
@ -2,12 +2,17 @@ def puppet(self, name, source, response):
|
||||||
botnick = self.bot.botnick
|
botnick = self.bot.botnick
|
||||||
author = self.bot.author
|
author = self.bot.author
|
||||||
command = response.split("!puppet ")[1]
|
command = response.split("!puppet ")[1]
|
||||||
place, message = command.split(" ", 1)
|
mode, place, message = command.split(" ", 2)
|
||||||
|
|
||||||
if name != author:
|
if name != author:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.bot.send_message(place, message)
|
modes = {
|
||||||
|
"say": self.bot.send_message,
|
||||||
|
"act": self.bot.send_action
|
||||||
|
}
|
||||||
|
default = lambda _, msg: self.bot.send_message(source, "Invalid action!")
|
||||||
|
modes.get(mode, default)(place, message)
|
||||||
|
|
||||||
def inject(self, name, source, response):
|
def inject(self, name, source, response):
|
||||||
botnick = self.bot.botnick
|
botnick = self.bot.botnick
|
||||||
|
@ -33,5 +38,4 @@ def nomad(self, name, source, response):
|
||||||
"leave": self.bot.leave
|
"leave": self.bot.leave
|
||||||
}
|
}
|
||||||
default = lambda p: self.bot.send_message(source, "Invalid action!")
|
default = lambda p: self.bot.send_message(source, "Invalid action!")
|
||||||
|
|
||||||
actions.get(action, default)(place)
|
actions.get(action, default)(place)
|
|
@ -94,13 +94,14 @@ def whois(self, name, source, response):
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
self.bot.send_message(source, "{} cannot exist".format(domain))
|
self.bot.send_message(source, "{} cannot exist".format(domain))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
registered = data.get("registered", False)
|
||||||
|
nameservers = len(data.get("nameservers", list())) > 0
|
||||||
|
self.bot.logger.debug("WHOIS: {}".format(data))
|
||||||
|
|
||||||
registered = data.get("registered", None)
|
if registered and nameservers:
|
||||||
if registered is not None:
|
self.bot.send_message(source, "{} is '{}'".format(domain, "registered"))
|
||||||
nameservers = len(data.get("nameservers", ""))
|
elif not (registered or nameservers):
|
||||||
registrar = data.get("registrar", dict())
|
self.bot.send_message(source, "{} is '{}'".format(domain, "available"))
|
||||||
is_registered = "id" in registrar or nameservers > 0
|
|
||||||
status = "registered" if is_registered else "available"
|
|
||||||
self.bot.send_message(source, "{} is '{}'".format(domain, status))
|
|
||||||
else:
|
else:
|
||||||
self.bot.send_message(source, "{} might be available".format(domain))
|
self.bot.send_message(source, "{} might be available".format(domain))
|
27
app.py
27
app.py
|
@ -21,14 +21,6 @@ bot = Bot("127.0.0.1", 6667)
|
||||||
responses = Responses(bot)
|
responses = Responses(bot)
|
||||||
tasks = Tasks(bot)
|
tasks = Tasks(bot)
|
||||||
|
|
||||||
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"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# for coro in coroutines:
|
# for coro in coroutines:
|
||||||
# worker = coro["worker"]
|
# worker = coro["worker"]
|
||||||
# interval = coro["interval"]
|
# interval = coro["interval"]
|
||||||
|
@ -37,6 +29,14 @@ for action in actions:
|
||||||
# tasks.add_coroutine(worker, interval, coro_state)
|
# tasks.add_coroutine(worker, interval, coro_state)
|
||||||
tasks.coroutines = coroutines
|
tasks.coroutines = coroutines
|
||||||
|
|
||||||
|
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"]
|
||||||
|
)
|
||||||
|
|
||||||
def try_to_king_me(channel):
|
def try_to_king_me(channel):
|
||||||
bot.send_message("ChanServ", "REGISTER {}", channel)
|
bot.send_message("ChanServ", "REGISTER {}", channel)
|
||||||
bot.send_message("ChanServ", "SET Successor {} {}", channel, bot.botnick)
|
bot.send_message("ChanServ", "SET Successor {} {}", channel, bot.botnick)
|
||||||
|
@ -83,11 +83,16 @@ def handle_kick(name):
|
||||||
def handle_message(name, source, response):
|
def handle_message(name, source, response):
|
||||||
responses.parse(name, source, response)
|
responses.parse(name, source, response)
|
||||||
if response == "!debug":
|
if response == "!debug":
|
||||||
print("::", bot.memories)
|
bot.logger.debug(":: {}".format(bot.memories))
|
||||||
|
|
||||||
def handle_crashed():
|
def handle_crashed():
|
||||||
bot.crashed = False
|
bot.logger.debug("Rebooting")
|
||||||
bot.stop()
|
bot.crashed = True
|
||||||
|
bot.tasks.stop()
|
||||||
|
|
||||||
|
tasks = Tasks(bot)
|
||||||
|
tasks.coroutines = coroutines
|
||||||
|
|
||||||
bot.tasks = tasks
|
bot.tasks = tasks
|
||||||
bot.start(arguments.config, dirname(realpath(__file__)), {
|
bot.start(arguments.config, dirname(realpath(__file__)), {
|
||||||
"pm": handle_pm,
|
"pm": handle_pm,
|
||||||
|
|
20
bot/core.py
20
bot/core.py
|
@ -195,8 +195,8 @@ class Bot:
|
||||||
setattr(self, name, attr)
|
setattr(self, name, attr)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.send("QUIT :Overheating, powering down")
|
||||||
self.running = False
|
self.running = False
|
||||||
self.send("QUIT")
|
|
||||||
|
|
||||||
def start(self, config, location, callback):
|
def start(self, config, location, callback):
|
||||||
message = ""
|
message = ""
|
||||||
|
@ -255,7 +255,7 @@ class Bot:
|
||||||
if getattr(self.tasks, "run", None) is not None:
|
if getattr(self.tasks, "run", None) is not None:
|
||||||
self.tasks.run()
|
self.tasks.run()
|
||||||
|
|
||||||
while self.running or not self.crashed:
|
while self.running:
|
||||||
message = ""
|
message = ""
|
||||||
while self.splitter not in message:
|
while self.splitter not in message:
|
||||||
message = self.ircsock.recv(self.recv_size).decode()
|
message = self.ircsock.recv(self.recv_size).decode()
|
||||||
|
@ -263,9 +263,9 @@ class Bot:
|
||||||
message = message.strip(self.splitter)
|
message = message.strip(self.splitter)
|
||||||
self.logger.debug("{}".format(message))
|
self.logger.debug("{}".format(message))
|
||||||
|
|
||||||
if "ERROR" in message or ":Closing link:" in message:
|
if ":Closing link:" in message:
|
||||||
self.logger.warning(message)
|
self.logger.warning(message)
|
||||||
self.crashed = True
|
self.stop()
|
||||||
if "crashed" in callback:
|
if "crashed" in callback:
|
||||||
callback["crashed"]()
|
callback["crashed"]()
|
||||||
break
|
break
|
||||||
|
@ -277,6 +277,12 @@ class Bot:
|
||||||
self.ping(message)
|
self.ping(message)
|
||||||
if "ping" in callback:
|
if "ping" in callback:
|
||||||
callback["ping"]()
|
callback["ping"]()
|
||||||
|
elif "PRIVMSG " in message:
|
||||||
|
name, source, response = self.parse(message)
|
||||||
|
if source == self.botnick and "pm" in callback:
|
||||||
|
callback["pm"](name, response)
|
||||||
|
elif "message" in callback:
|
||||||
|
callback["message"](name, source, response)
|
||||||
elif "MODE " in message:
|
elif "MODE " in message:
|
||||||
channel, mode = self.handle_mode(message)
|
channel, mode = self.handle_mode(message)
|
||||||
if "mode" in callback:
|
if "mode" in callback:
|
||||||
|
@ -301,11 +307,5 @@ class Bot:
|
||||||
channel, name = self.handle_invite(message)
|
channel, name = self.handle_invite(message)
|
||||||
if "invite" in callback:
|
if "invite" in callback:
|
||||||
callback["invite"](channel, name)
|
callback["invite"](channel, name)
|
||||||
elif "PRIVMSG " in message:
|
|
||||||
name, source, response = self.parse(message)
|
|
||||||
if source == self.botnick and "pm" in callback:
|
|
||||||
callback["pm"](name, response)
|
|
||||||
elif "message" in callback:
|
|
||||||
callback["message"](name, source, response)
|
|
||||||
elif "unhandled" in callback:
|
elif "unhandled" in callback:
|
||||||
callback["unhandled"](message)
|
callback["unhandled"](message)
|
|
@ -32,6 +32,10 @@ class Tasks:
|
||||||
"state": state
|
"state": state
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
list(map(self.scheduler.cancel, self.scheduler.queue))
|
||||||
|
self.thread.stop()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.thread.daemon = True
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
|
@ -1,6 +1,6 @@
|
||||||
from xml.etree import ElementTree as etree
|
from xml.etree import ElementTree as etree
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError, URLError
|
||||||
from json import loads, dumps
|
from json import loads, dumps
|
||||||
from re import sub
|
from re import sub
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ class RSS:
|
||||||
response = urlopen(req).read()
|
response = urlopen(req).read()
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
return
|
return
|
||||||
|
except URLError:
|
||||||
|
return
|
||||||
|
|
||||||
feed = etree.fromstring(response)
|
feed = etree.fromstring(response)
|
||||||
items = feed.findall("channel/item")
|
items = feed.findall("channel/item")
|
||||||
|
|
Loading…
Reference in New Issue