Updating to use tildeverse links and fixes bugs for using bot with lite features
This commit is contained in:
parent
286c144bdf
commit
64d0208837
|
@ -1,6 +1,7 @@
|
||||||
# App-specific
|
# App-specific
|
||||||
settings.json
|
settings.json
|
||||||
settings.demo.json
|
settings.demo.json
|
||||||
|
settings.test.json
|
||||||
data/*.json
|
data/*.json
|
||||||
logs/*.log*
|
logs/*.log*
|
||||||
logs/*.log.*
|
logs/*.log.*
|
||||||
|
|
|
@ -75,9 +75,8 @@ def summon(self, name, source, response):
|
||||||
self.bot.send_message(source, confirmation)
|
self.bot.send_message(source, confirmation)
|
||||||
|
|
||||||
def how_dare_you(self, name, source, response):
|
def how_dare_you(self, name, source, response):
|
||||||
user = response.split("!summon ")[1]
|
|
||||||
rude = "{}: You think you can just summon someone without a reason? Rude."
|
rude = "{}: You think you can just summon someone without a reason? Rude."
|
||||||
self.bot.send_message(source, rude.format(user))
|
self.bot.send_message(source, rude.format(name))
|
||||||
|
|
||||||
def whois(self, name, source, response):
|
def whois(self, name, source, response):
|
||||||
botnick = self.bot.botnick
|
botnick = self.bot.botnick
|
||||||
|
@ -104,4 +103,4 @@ def whois(self, name, source, response):
|
||||||
elif not (registered or nameservers):
|
elif not (registered or nameservers):
|
||||||
self.bot.send_message(source, "{} is '{}'".format(domain, "available"))
|
self.bot.send_message(source, "{} is '{}'".format(domain, "available"))
|
||||||
else:
|
else:
|
||||||
self.bot.send_message(source, "{} might be available".format(domain))
|
self.bot.send_message(source, "{} might be available".format(domain))
|
||||||
|
|
8
app.py
8
app.py
|
@ -65,7 +65,9 @@ def handle_invite(channel, name):
|
||||||
if changed:
|
if changed:
|
||||||
bot.thread(bot.save_memories)
|
bot.thread(bot.save_memories)
|
||||||
|
|
||||||
def handle_kick(name):
|
def handle_kick(name, source):
|
||||||
|
if source in bot.settings.get("extras", dict()).get("rejoin", list()):
|
||||||
|
bot.join(source)
|
||||||
users = bot.memories["users"]
|
users = bot.memories["users"]
|
||||||
if name not in users:
|
if name not in users:
|
||||||
bot.memories["users"][name] = dict()
|
bot.memories["users"][name] = dict()
|
||||||
|
@ -79,8 +81,8 @@ def handle_message(name, source, response):
|
||||||
bot.logger.debug(":: {}".format(bot.memories))
|
bot.logger.debug(":: {}".format(bot.memories))
|
||||||
|
|
||||||
def handle_raw(message):
|
def handle_raw(message):
|
||||||
with open("/tmp/babs", "a") as babs:
|
if "KICK #chaos {}".format(bot.author) in message:
|
||||||
babs.write(repr(message) + "\n")
|
bot.send("INVITE {} :#chaos".format(bot.author))
|
||||||
|
|
||||||
def handle_crashed():
|
def handle_crashed():
|
||||||
bot.logger.debug("Rebooting")
|
bot.logger.debug("Rebooting")
|
||||||
|
|
28
bot/core.py
28
bot/core.py
|
@ -1,4 +1,6 @@
|
||||||
import re
|
import re
|
||||||
|
import ssl
|
||||||
|
import time
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
import os.path
|
import os.path
|
||||||
|
@ -13,11 +15,12 @@ logging.basicConfig(
|
||||||
)
|
)
|
||||||
|
|
||||||
class Bot:
|
class Bot:
|
||||||
def __init__(self, server, port):
|
def __init__(self, server, port, secure=False):
|
||||||
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.logger = logging.getLogger("")
|
self.logger = logging.getLogger("")
|
||||||
self.server = server
|
self.server = server
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.secure = secure
|
||||||
self.channels = []
|
self.channels = []
|
||||||
self.running = True
|
self.running = True
|
||||||
self.crashed = False
|
self.crashed = False
|
||||||
|
@ -31,6 +34,9 @@ class Bot:
|
||||||
self.recv_size = 2048
|
self.recv_size = 2048
|
||||||
self.splitter = "\r\n"
|
self.splitter = "\r\n"
|
||||||
|
|
||||||
|
if self.secure:
|
||||||
|
self.ircsock = ssl.wrap_socket(self.ircsock)
|
||||||
|
|
||||||
def send(self, message, *args):
|
def send(self, message, *args):
|
||||||
response = message.format(*args) + "\n"
|
response = message.format(*args) + "\n"
|
||||||
password = self.settings.get("password", None)
|
password = self.settings.get("password", None)
|
||||||
|
@ -65,9 +71,13 @@ class Bot:
|
||||||
|
|
||||||
message = ""
|
message = ""
|
||||||
magic_string = "End of /NAMES list."
|
magic_string = "End of /NAMES list."
|
||||||
|
banned = "Cannot join channel (You're banned)"
|
||||||
while magic_string not in message:
|
while magic_string not in message:
|
||||||
try:
|
try:
|
||||||
message = self.ircsock.recv(self.recv_size).decode()
|
message = self.ircsock.recv(self.recv_size).decode()
|
||||||
|
if banned in message:
|
||||||
|
self.places.remove(chan)
|
||||||
|
return
|
||||||
# message = message.strip(self.splitter)
|
# message = message.strip(self.splitter)
|
||||||
self.logger.debug(message)
|
self.logger.debug(message)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
@ -141,8 +151,9 @@ class Bot:
|
||||||
|
|
||||||
def handle_kick(self, message):
|
def handle_kick(self, message):
|
||||||
before, after = message.split("KICK ", 1)
|
before, after = message.split("KICK ", 1)
|
||||||
|
source = after.split(" ", 1)[0]
|
||||||
name = self.parse_name(self.get_name(before))
|
name = self.parse_name(self.get_name(before))
|
||||||
return name
|
return name, source
|
||||||
|
|
||||||
def handle_join(self, message):
|
def handle_join(self, message):
|
||||||
before, after = message.split("JOIN ", 1)
|
before, after = message.split("JOIN ", 1)
|
||||||
|
@ -231,9 +242,10 @@ class Bot:
|
||||||
"needs_to_register": "choose a different nick",
|
"needs_to_register": "choose a different nick",
|
||||||
"needs_to_confirm": "Your account will expire"
|
"needs_to_confirm": "Your account will expire"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
authenticate = len(password) > 0 and len(confirm) > 0
|
||||||
magic_string = "MODE {} +r".format(self.botnick)
|
magic_string = "MODE {} +r".format(self.botnick)
|
||||||
while magic_string not in message:
|
while magic_string not in message and authenticate:
|
||||||
try:
|
try:
|
||||||
message = self.ircsock.recv(self.recv_size).decode()
|
message = self.ircsock.recv(self.recv_size).decode()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
|
@ -248,7 +260,9 @@ class Bot:
|
||||||
if not confirmed and magic_phrase["needs_to_confirm"] in message:
|
if not confirmed and magic_phrase["needs_to_confirm"] in message:
|
||||||
self.send_message("NickServ", "CONFIRM {}", self.confirm)
|
self.send_message("NickServ", "CONFIRM {}", self.confirm)
|
||||||
confirmed = True
|
confirmed = True
|
||||||
|
if not authenticate:
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
self.send("MODE {} +B".format(self.botnick))
|
self.send("MODE {} +B".format(self.botnick))
|
||||||
|
|
||||||
print("DEBUG: Joining")
|
print("DEBUG: Joining")
|
||||||
|
@ -298,9 +312,9 @@ class Bot:
|
||||||
if "nick" in callback:
|
if "nick" in callback:
|
||||||
callback["nick"](old_name, new_name)
|
callback["nick"](old_name, new_name)
|
||||||
elif "KICK " in message:
|
elif "KICK " in message:
|
||||||
kicker = self.handle_kick(message)
|
kicker, source = self.handle_kick(message)
|
||||||
if "kick" in callback:
|
if "kick" in callback:
|
||||||
callback["kick"](kicker)
|
callback["kick"](kicker, source)
|
||||||
elif "JOIN " in message:
|
elif "JOIN " in message:
|
||||||
user = self.handle_join(message)
|
user = self.handle_join(message)
|
||||||
if "join" in callback:
|
if "join" in callback:
|
||||||
|
|
|
@ -20,10 +20,6 @@ class Responses:
|
||||||
if name not in users:
|
if name not in users:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if name in users and "blacklist" in users[name]:
|
|
||||||
reason = users[name]["blacklist"]["reason"]
|
|
||||||
return False
|
|
||||||
|
|
||||||
last_response = 0
|
last_response = 0
|
||||||
if "last_response" in self.bot.memories["users"][name]:
|
if "last_response" in self.bot.memories["users"][name]:
|
||||||
last_response = self.bot.memories["users"][name]["last_response"]
|
last_response = self.bot.memories["users"][name]["last_response"]
|
||||||
|
@ -59,13 +55,26 @@ class Responses:
|
||||||
for trigger in list(self.triggers.keys()):
|
for trigger in list(self.triggers.keys()):
|
||||||
for pattern, callback in self.triggers[trigger].items():
|
for pattern, callback in self.triggers[trigger].items():
|
||||||
if pattern[0] != "/" and pattern[-1] != "/":
|
if pattern[0] != "/" and pattern[-1] != "/":
|
||||||
if pattern == check and self.allowed(name, source):
|
if pattern == check:
|
||||||
callback(self, name, source, response)
|
if self.allowed(name, source):
|
||||||
|
callback(self, name, source, response)
|
||||||
|
elif "blacklist" in users[name]:
|
||||||
|
reason = users[name]["blacklist"]["reason"]
|
||||||
|
message = "You were banished for reason '{}'"
|
||||||
|
message = message.format(reason)
|
||||||
|
#self.bot.send_message(name, message)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
regex = re.compile(pattern[1:-1])
|
regex = re.compile(pattern[1:-1])
|
||||||
if regex.match(trig[trigger]) is not None:
|
if regex.match(trig[trigger]) is not None:
|
||||||
if self.allowed(name, source):
|
if self.allowed(name, source):
|
||||||
callback(self, name, source, response)
|
callback(self, name, source, response)
|
||||||
|
elif "blacklist" in users[name]:
|
||||||
|
reason = users[name]["blacklist"]["reason"]
|
||||||
|
message = "You were banished for reason '{}'"
|
||||||
|
message = message.format(reason)
|
||||||
|
#self.bot.send_message(name, message)
|
||||||
|
return False
|
||||||
|
|
||||||
now = datetime.now().timestamp()
|
now = datetime.now().timestamp()
|
||||||
self.bot.memories["users"][name]["last_response"] = now
|
self.bot.memories["users"][name]["last_response"] = now
|
||||||
|
|
|
@ -18,7 +18,7 @@ coroutines = [
|
||||||
"state": {
|
"state": {
|
||||||
"alias": "bbj",
|
"alias": "bbj",
|
||||||
"source": "http://localhost:7099/api",
|
"source": "http://localhost:7099/api",
|
||||||
"channels": ["#team"]
|
"channels": ["#team", "#tildeverse"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -41,4 +41,4 @@ coroutines = [
|
||||||
"channels": ["#tildeverse"]
|
"channels": ["#tildeverse"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue