Compare commits

...

15 commits

Author SHA1 Message Date
d38345c3d9 add admin deleteword command 2022-05-17 23:04:29 -04:00
9d9c9dcd34 fix recording nouns
i should not be allowed near a computer
2022-05-17 22:26:01 -04:00
3e1c3dac5b
fox comment wording 2022-05-13 21:55:28 -04:00
2ac269d7f8 ignore mutations of rawm while iterating 2022-05-12 08:43:29 -06:00
bccf3c855a fix addspook not deleting itself 2022-05-12 08:38:29 -06:00
c42e5edcc1
put channel back, whoops 2022-04-28 13:50:14 -04:00
790aa9aff5
merge admin.py from upstream oirc 2022-04-28 13:47:47 -04:00
fd3174b1fe
merge bot.py from upstream oirc 2022-04-28 13:45:08 -04:00
f67b269b1b
build privmsg instead of using self.message
self.message will somewhat change behavior
2022-04-27 19:59:03 -04:00
2a21330e8b update default enmul 2022-03-10 12:04:10 -07:00
4d20f602a7 tokenize punctuation before recording words 2022-03-10 12:03:39 -07:00
dccdda1f5f improve ending balences 2022-03-10 09:41:56 -07:00
a886b95db6 make enmul stepping smaller 2022-03-09 16:45:50 -07:00
7348ef0354 noun count should not be used to end sentances
what in the world was i thinking, and how did i not notice this sooner?
2022-03-09 14:00:51 -07:00
7af2f8f675 reformat with black 2022-01-26 21:26:57 -05:00
6 changed files with 452 additions and 300 deletions

115
bot.py
View file

@ -10,80 +10,88 @@ from ircrobots import ConnectionParams, SASLUserPass, SASLSCRAM
from auth import username, password, channel
import shared
def is_admin(func):
async def decorator(self,channel,nick,msg):
if nick.lower() in self.users and self.users[nick.lower()].account in self.admins:
await func(self,channel,nick,msg)
async def decorator(self, channel, nick, msg):
if (
nick.lower() in self.users
and self.users[nick.lower()].account in self.admins
):
await func(self, channel, nick, msg)
else:
await message(self,'core',channel,'you do not have permission to do that')
await message(self, channel, "you do not have permission to do that")
return decorator
#def is_chanop(func):
# def is_chanop(func):
def command(commandname):
def decorator(func):
shared.commands[commandname] = func
return func
return decorator
def listener(listenername):
def decorator(func):
shared.listeners.append((listenername, func))
return func
return decorator
def rawm(rname):
def decorator(func):
shared.rawm[rname] = func
return func
return decorator
async def message(self,channel,msg):
modname = os.path.splittext(os.path.basename(inspect.stack()[1].filename))[0]
await self.send(build("PRIVMSG",[channel,f'[\x036{modname}\x0f] {msg}']))
async def message(self, channel, msg):
modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0]
await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
class Server(BaseServer):
async def line_read(self, line: Line):
if 'on_'+line.command.lower() in dir(self):
asyncio.create_task(self.__getattribute__('on_'+line.command.lower())(line))
if "on_" + line.command.lower() in dir(self):
asyncio.create_task(
self.__getattribute__("on_" + line.command.lower())(line)
)
for listener in shared.listeners:
if listener[0] == line.command:
asyncio.create_task(listener[1](self,line))
def line_preread(self, line: Line):
print(f"{self.name} < {line.format()}")
def line_presend(self, line: Line):
print(f"{self.name} > {line.format()}")
asyncio.create_task(listener[1](self, line))
async def line_preread(self, line: Line):
print(f"{self.name} < {line.format()}")
async def line_presend(self, line: Line):
print(f"{self.name} > {line.format()}")
async def on_001(self, line):
asyncio.create_task(self.load_modules())
async def load_modules(self):
for i in [s for s in os.listdir('modules') if '.py' in s and '.swp' not in s]:
for i in [s for s in os.listdir("modules") if ".py" in s and ".swp" not in s]:
i = i[:-3]
m = importlib.import_module('modules.' + i)
m = importlib.import_module("modules." + i)
asyncio.create_task(m.init(self))
shared.modules[i] = m
# depricated, to support old modules
async def message(self,channel,msg):
await self.send(build("PRIVMSG",[channel,msg]))
async def message(self, channel, msg):
modname = os.path.splitext(os.path.basename(inspect.stack()[:2][-1].filename))[0]
await self.send(build("PRIVMSG", [channel, f"[\x036{modname}\x0f] {msg}"]))
async def on_privmsg(self, line):
if line.tags and "batch" in line.tags and line.tags["batch"] == '1':
if line.tags and "batch" in line.tags and line.tags["batch"] == "1":
return
channel = line.params[0]
nick = line.source.split('!')[0]
nick = line.source.split("!")[0]
msg = line.params[1]
if nick == self.nickname:
@ -91,57 +99,56 @@ class Server(BaseServer):
if channel == self.nickname:
channel = nick
await self.handle_rawm(channel,nick,msg)
await self.handle_command(channel,nick,msg)
async def handle_rawm(self,channel,nick,msg):
for i in shared.rawm:
await shared.rawm[i](self,channel,nick,msg)
async def handle_command(self,channel,nick,msg):
if msg[:len(shared.prefix)] == shared.prefix:
msg = msg[len(shared.prefix):]
cmd = msg.split(' ')[0]
msg = msg[len(cmd)+1:]
await self.handle_rawm(channel, nick, msg)
await self.handle_command(channel, nick, msg)
async def handle_rawm(self, channel, nick, msg):
for i in list(shared.rawm):
await shared.rawm[i](self, channel, nick, msg)
async def handle_command(self, channel, nick, msg):
if msg[: len(shared.prefix)] == shared.prefix:
msg = msg[len(shared.prefix) :]
cmd = msg.split(" ")[0]
msg = msg[len(cmd) + 1 :]
if len(cmd) < 1:
return
if cmd in shared.commands:
await shared.commands[cmd](self,channel,nick,msg)
await shared.commands[cmd](self, channel, nick, msg)
return
results = [i for i in shared.commands if i.startswith(cmd)]
if len(results) == 1:
await shared.commands[results[0]](self,channel,nick,msg)
await shared.commands[results[0]](self, channel, nick, msg)
class Bot(BaseBot):
def create_server(self, name: str):
return Server(self, name)
async def main():
bot = Bot()
sasl_params = SASLUserPass(username, password)
params = ConnectionParams(
params = ConnectionParams(
"min",
host = "irc.libera.chat",
port = 6697,
tls = True,
sasl = sasl_params,
autojoin = channel)
host="irc.libera.chat",
port=6697,
tls=True,
sasl=sasl_params,
autojoin=channel,
)
await bot.add_server("libera", params)
params = ConnectionParams(
"min",
host = "manonet.lumey.dev",
port = 6697,
tls = True,
autojoin = ['#manonet'])
params = ConnectionParams(
"min", host="manonet.lumey.dev", port=6697, tls=True, autojoin=["#manonet"]
)
await bot.add_server("manonet", params)
await bot.run()
if __name__ == "__main__":
asyncio.run(main())

View file

@ -1,213 +1,321 @@
import importlib, time, asyncio, random
import importlib, time, asyncio, random, sys
from bot import *
quitmessages = [
"time to die",
'you can hide, but you can not run!',
"you're next",
'bye',
'the balun has been popped.',
]
"time to die",
"you can hide, but you can not run!",
"you're next",
"bye",
"the balun has been popped.",
]
async def commit(self, chan, source, msg):
await self.quit('{} told me to commit {}'.format(source,msg))
await self.send(build("QUIT", [f"{source} told me to commit {msg}!"]))
sys.exit()
async def quit(self, chan, source, msg):
await self.send(build("QUIT",[random.choice(quitmessages)]))
await self.send(build("QUIT", [random.choice(quitmessages)]))
sys.exit()
async def reloadmods(self, chan, source, msg):
await self.message(chan, '[\x036admin\x0f] reloading modules...')
shared.oldcmd = shared.commands
shared.commands = {}
shared.rawm = {}
shared.listeners = []
shared.help = {}
try:
for i in shared.modules:
importlib.reload(shared.modules[i])
await shared.modules[i].init(self)
#await self.message(chan, '[\x036admin\x0f] load {} sucess!'.format(i))
await self.message(chan, '[\x036admin\x0f] done! {} modules reloaded!'.format(len(shared.modules)))
except:
await self.message(chan, '[\x036admin\x0f] reload failed... attempting to recover...')
shared.commands = shared.oldcmd
await self.message(chan, "reloading modules...")
shared.oldcmd = shared.commands
shared.commands = {}
shared.rawm = {}
shared.listeners = []
shared.help = {}
try:
for i in shared.modules:
importlib.reload(shared.modules[i])
await shared.modules[i].init(self)
# await self.message(chan, 'load {} sucess!'.format(i))
await self.message(
chan, "done! {} modules reloaded!".format(len(shared.modules))
)
except:
await self.message(
chan, "reload failed... {}...".format(repr(sys.exc_info()[1]))
)
shared.commands = shared.oldcmd
async def rawcmd(self, chan, source, msg):
await self.send_raw(msg)
await self.send_raw(msg)
async def joins(self, chan, source, msg):
await self.message(chan, '[\x036admin\x0f] joining slowly as to not flood...')
for i in self.chandb.all():
await self.send(build("JOIN",[i['name']]))
await asyncio.sleep(1)
print('joined {}'.format(i['name']))
await self.message(chan, '[\x036admin\x0f] Sucess! i may be laggy for a bit while i sort through all these channels...')
await self.message(chan, "joining slowly as to not flood...")
for i in self.chandb.all():
await self.send(build("JOIN", [i["name"]]))
await asyncio.sleep(1)
print("joined {}".format(i["name"]))
await self.message(
chan,
"Sucess! i may be laggy for a bit while i sort through all these channels...",
)
async def aexec(self, code):
async def aexec(self, code, chan=None, source=None, msg=None):
# Make an async function with the code and `exec` it
exec(
f'async def __ex(self): ' +
''.join(f'\n {l}' for l in code.split('\n'))
f"async def __ex(self, chan, source, msg): "
+ "".join(f"\n {l}" for l in code.split("\\n"))
)
# Get `__ex` from local variables, call it and return the result
return await locals()['__ex'](self)
return await locals()["__ex"](self, chan, source, msg)
async def ev(self, chan, source, msg):
msg = msg.split(' ')
try:
await self.message(chan, '[\x036admin\x0f] ok, output: {}'.format(
str(await aexec(self, ' '.join(msg)))[:400]
))
except:
await self.message(chan, '[\x036admin\x0f] exception in eval!')
msg = msg.split(" ")
try:
await self.message(
chan, "ok, output: {}".format(str(await aexec(self, " ".join(msg)))[:400])
)
except:
await self.message(chan, "ut oh! {}".format(repr(sys.exc_info()[1])))
async def send(self, c, n, m):
msg = m.split(' ')
await self.message(msg.pop(0), ' '.join(msg))
await self.message(c, '[\x036admin\x0f] sent')
msg = m.split(" ")
await self.message(msg.pop(0), " ".join(msg))
await self.message(c, "sent")
async def shut(self, c, n, m):
shared.qtime[c] = time.time()+(60*10)
await self.message(c, '[\x036admin\x0f] Ok, il be back in 10 minutes')
shared.qtime[c] = time.time() + (60 * 10)
await self.message(c, "Ok, il be back in 10 minutes")
async def deleteword(self, c, n, m):
starttime = time.time()
deleteme = m.split()
shared.db["conver"].delete(pre=deleteme)
shared.db["prew"].delete(pre=deleteme)
shared.db["conver"].delete(pro=deleteme)
shared.db["prew"].delete(pro=deleteme)
shared.db["noun"].delete(word=deleteme)
shared.db["beg"].delete(word=deleteme)
shared.db["end"].delete(word=deleteme)
await self.message(
c, f"word(s) deleted in {round(time.time()-starttime,2)} seconds"
)
async def schans(self, c, n, m):
self.chandb.delete()
for i in self.channels:
self.chandb.insert(dict(name=i))
await self.message(c, '[\x036admin\x0f] Ok')
async def addalias(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
if al in self.cmd:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
self.cmd[al]=Alias(m).alias
await self.message(c,'[\x036admin\x0f] added "{}" alias for "{}"'.format(al,m))
self.chandb.delete()
for i in self.channels:
self.chandb.insert(dict(name=i))
await self.message(c, "Ok")
async def addot(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
async def addalias(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
Alias(al, m)
await self.message(c, 'added "{}" alias for "{}"'.format(al, m))
async def addcommand(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
Command(al, m)
await self.message(c, 'added "{}" alias for "{}"'.format(al, m))
async def addot(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
await self.message(c, "no dont overwrite a command dummy")
return
shared.rawm[al]=Ot(m,al).ot
Ot(al, m)
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
async def addspook(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
async def addspook(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
await self.message(c, "no dont overwrite a command dummy")
return
shared.rawm[al]=Spook(m,al).spook
Spook(al, m)
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
async def addtrigger(self,c,n,m):
al = m.split(' ')[0]
m = m[len(al)+1:] # dont use the list since i want trailing spaces
async def addtrigger(self, c, n, m):
al = m.split(" ")[0]
m = m[len(al) + 1 :] # dont use the list since i want trailing spaces
if al in shared.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
await self.message(c, "no dont overwrite a command dummy")
return
shared.rawm[al]=Trigger(m,al).trigger
Trigger(al, m)
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
await self.message(c, 'added "{}" trigger for "{}"'.format(al, m))
class Ot:
class Ot():
def __init__(self, ms, al):
ots = {}
def __init__(self, al, ms):
self.ms = str(ms)
self.al = str(al)
async def ot(alself,self,c,n,m):
self.__class__.ots[self.al] = ms
shared.rawm[self.al] = self.ot
async def ot(alself, self, c, n, m):
if alself.al in m and n != self.nickname:
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
shared.rawm.pop(alself.al)
class Spook():
def __init__(self, ms, al):
class Spook:
spooks = {}
def __init__(self, al, ms):
self.ms = str(ms)
self.al = str(al)
async def spook(alself,self,c,n,m):
self.__class__.spooks[self.al] = ms
shared.rawm[self.al] = self.spook
async def spook(alself, self, c, n, m):
if alself.al in m and n != self.nickname:
asyncio.create_task(self.message(c,alself.ms.format(m)))
self.send(build("PRIVMSG", [c, alself.ms.format(m)]))
shared.rawm.pop(alself.al)
class Trigger():
def __init__(self, ms, al):
class Trigger:
triggers = {}
def __init__(self, al, ms):
self.ms = str(ms)
self.al = str(al)
async def trigger(alself,self,c,n,m):
self.__class__.triggers[al] = ms
shared.rawm[al] = self.trigger
async def trigger(alself, self, c, n, m):
if alself.al in m:
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
class Alias():
def __init__(self, ms):
class Command:
commands = {}
def __init__(self, cmd, ms):
self.ms = str(ms)
async def alias(alself,self,c,n,m):
asyncio.create_task(self.on_privmsg(build("PRIVMSG",[c,alself.ms.format(m)],n+'!spoof@spoof')))
self.__class__.commands[cmd] = ms
shared.commands[cmd] = self.command
async def command(alself, self, chan, source, msg):
try:
out = await aexec(self, alself.ms, chan, source, msg)
except:
await self.message(chan, "ut oh! {}".format(repr(sys.exc_info()[1])))
else:
if out is not None and len(out) > 0:
await self.message(chan, str(out))
class Alias:
aliases = {}
def __init__(self, cmd, ms):
self.ms = str(ms)
self.__class__.aliases[cmd] = ms
shared.commands[cmd] = self.alias
async def alias(alself, self, c, n, m):
asyncio.create_task(
self.on_privmsg(
build("PRIVMSG", [c, alself.ms.format(m)], n + "!spoof@spoof")
)
)
commands = {
'quit': quit,
'reload': reloadmods,
'commit': commit,
'raw': rawcmd,
'eval': ev,
'send': send,
'joins': joins,
'shut': shut,
'schans': schans,
'addalias': addalias,
'addtrigger': addtrigger,
'addot': addot,
'addspook': addspook,
"quit": quit,
"reload": reloadmods,
"commit": commit,
"raw": rawcmd,
"eval": ev,
"send": send,
"joins": joins,
"shut": shut,
"deleteword": deleteword,
"schans": schans,
"addalias": addalias,
"addcommand": addcommand,
"addtrigger": addtrigger,
"addot": addot,
"addspook": addspook,
}
@command('admin')
@command("admin")
@is_admin
async def adminHandle(self, chan, source, msg):
msg = msg.split(' ')
msg = msg.split(" ")
if len(msg) < 1 or not msg[0] in commands:
await self.message(chan, '[\x036admin\x0f] Invalid command')
return
print('[ADMIN MODULE] {} told me to {}!!!'.format(source,msg[0]))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, ' '.join(msg)))
await self.message(chan, "Invalid command")
return
print("[ADMIN MODULE] {} told me to {}!!!".format(source, msg[0]))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, " ".join(msg)))
async def init(self):
self.chandb = shared.db['chan']
self.admins = ['xfnw']
return
self.cmd['admin'] = adminHandle
self.help['admin'] = ['admin - various bot owner commands (more for subcommands)', 'sub-commands of admin, for more info do help admin <command>: quit reload commit part join joins eval send']
self.help['admin quit'] = ['admin quit <message> - make the bot disconnect','no']
self.help['admin reload'] = ['admin reload - reload the modules and configs', 'nothing to see here']
self.help['admin commit'] = ['admin commit <action> - oh no (more)', 'suggested with <3 by khux']
self.help['admin part'] = ['admin part <channel> - leave a channel', ':o']
self.help['admin join'] = ['admin join <channel> - make the bot join a channel','...']
self.help['admin joins'] = ['admin joins - join more channels', 'dont reconnect to a bunch of chans when the bots crashing etc']
self.help['admin eval'] = ['admin eval <command> - absolute power corrupts absolutely', 'lmao']
self.help['admin send'] = ['admin send <channel> <message> - send a message', 'lmao']
self.help['admin schans'] = ['admin schans - save the commands to join',';p;']
self.chandb = shared.db["chan"]
self.admins = ["xfnw"]
return
self.help["admin"] = [
"admin - various bot owner commands (more for subcommands)",
"sub-commands of admin, for more info do help admin <command>: quit reload commit part join joins eval send",
]
self.help["admin quit"] = ["admin quit <message> - make the bot disconnect", "no"]
self.help["admin reload"] = [
"admin reload - reload the modules and configs",
"nothing to see here",
]
self.help["admin commit"] = [
"admin commit <action> - oh no (more)",
"suggested with <3 by khux",
]
self.help["admin part"] = ["admin part <channel> - leave a channel", ":o"]
self.help["admin join"] = [
"admin join <channel> - make the bot join a channel",
"...",
]
self.help["admin joins"] = [
"admin joins - join more channels",
"dont reconnect to a bunch of chans when the bots crashing etc",
]
self.help["admin eval"] = [
"admin eval <command> - absolute power corrupts absolutely",
"lmao",
]
self.help["admin send"] = [
"admin send <channel> <message> - send a message",
"lmao",
]
self.help["admin schans"] = ["admin schans - save the commands to join", ";p;"]

View file

@ -1,9 +1,10 @@
from bot import *
@listener('INVITE')
async def on_invite(self,line):
self.send(build("JOIN",[line.params[1]]))
@listener("INVITE")
async def on_invite(self, line):
self.send(build("JOIN", [line.params[1]]))
async def init(self):
pass

View file

@ -2,33 +2,46 @@ from bot import *
import dataset, random, time, re
def get(l,i):
try:
if i <= len(l) and i >= 0:
return l[i]
else:
return ''
except IndexError:
return ''
def get(l, i):
try:
if i <= len(l) and i >= 0:
return l[i]
else:
return ""
except IndexError:
return ""
async def rec(self, m):
prew = shared.db['prew']
noch = shared.db['noun']
beg = shared.db['beg']
end = shared.db['end']
prew = shared.db["prew"]
noch = shared.db["noun"]
beg = shared.db["beg"]
end = shared.db["end"]
words = m.split()
words = re.sub(r"([\.,\?!])", r" \1", m).split()
if words[0] == 'admin' or len(words) < 2:
return
if words[0] == "admin" or len(words) < 2:
return
beg.insert(dict(word=words[0]))
end.insert(dict(word=words[-1]))
beg.insert(dict(word=words[0]))
end.insert(dict(word=words[-1]))
for w in range(len(words)):
if w > 0:
prew.insert_ignore(
dict(
pre3=get(words, w - 3),
pre2=get(words, w - 2),
pre=get(words, w - 1),
pro=get(words, w),
pro2=get(words, w + 1),
pro3=get(words, w + 2),
),
["id"],
)
noch.insert(dict(word=get(words, w)))
for w in range(len(words)):
if w > 0:
prew.insert_ignore(dict(pre3=get(words,w-3), pre2=get(words,w-2), pre=get(words,w-1), pro=get(words,w), pro2=get(words,w+1), pro3=get(words,w+2)),['id'])
noch.insert(dict(word=w))
async def getNoun(self, words, c):
if c in shared.cstate:
@ -36,108 +49,135 @@ async def getNoun(self, words, c):
else:
oldnoun = None
nouns = shared.db['noun']
nouns = shared.db["noun"]
out = {}
for i in words:
out[i] = nouns.count(word=i)
noun = min(out, key=out.get)
conversation = shared.db['conver']
conversation = shared.db["conver"]
if oldnoun != None:
print("adding", [oldnoun,noun])
conversation.insert_ignore(dict(pre=oldnoun,pro=noun),['id'])
print("adding", [oldnoun, noun])
conversation.insert_ignore(dict(pre=oldnoun, pro=noun), ["id"])
nextnoun = [i['pro'] for i in conversation.find(pre=noun)]
print("nextnoun:",nextnoun)
nextnoun = [i["pro"] for i in conversation.find(pre=noun)]
print("nextnoun:", nextnoun)
if len(nextnoun) > 0:
noun = random.choice(nextnoun)
shared.cstate[c] = noun
return noun
async def genOut(self, noun):
prew = shared.db['prew']
beg = shared.db['beg']
end = shared.db['end']
nouns = shared.db['noun']
iter=0
coun=0
out = [noun]
while (beg.find_one(word=out[0]) is None or nouns.count(word=out[0])-1 > iter * shared.enmul) and iter < shared.maxiter:
try:
out = [ random.choice(list(prew.find(pro=out[0],pro2=out[1],pro3=out[2])))['pre'] ] + out
except IndexError:
try:
out = [ random.choice(list(prew.find(pro=out[0],pro2=out[1])))['pre'] ] + out
except IndexError:
prew = shared.db["prew"]
beg = shared.db["beg"]
end = shared.db["end"]
nouns = shared.db["noun"]
iter = 0
coun = 0
out = [noun]
while (
beg.find_one(word=out[0]) is None
or beg.count(word=out[0]) - 1 < shared.enmul / (1 + iter / shared.maxiter)
) and iter < shared.maxiter:
try:
out = [ random.choice(list(prew.find(pro=out[0])))['pre'] ] + out
out = [
random.choice(list(prew.find(pro=out[0], pro2=out[1], pro3=out[2])))[
"pre"
]
] + out
except IndexError:
iter += 69
iter += 1
coun += 1
iter = 0
while (end.find_one(word=out[-1]) is None or nouns.count(word=out[-1])-1 > iter * shared.enmul) and iter < shared.maxiter:
try:
out.append(random.choice(list(prew.find(pre3=out[-3],pre2=out[-2],pre=out[-1])))['pro'])
except IndexError:
try:
out.append(random.choice(list(prew.find(pre2=out[-2],pre=out[-1])))['pro'])
except IndexError:
try:
out = [
random.choice(list(prew.find(pro=out[0], pro2=out[1])))["pre"]
] + out
except IndexError:
try:
out = [random.choice(list(prew.find(pro=out[0])))["pre"]] + out
except IndexError:
iter += 69420
iter += 1
coun += 1
iter = 0
while (
end.find_one(word=out[-1]) is None
or end.count(word=out[-1]) - 1 < shared.enmul / (1 + iter / shared.maxiter)
) and iter < shared.maxiter:
try:
out.append(random.choice(list(prew.find(pre=out[-1])))['pro'])
out.append(
random.choice(list(prew.find(pre3=out[-3], pre2=out[-2], pre=out[-1])))[
"pro"
]
)
except IndexError:
iter += 69
iter += 1
coun += 1
try:
out.append(
random.choice(list(prew.find(pre2=out[-2], pre=out[-1])))["pro"]
)
except IndexError:
try:
out.append(random.choice(list(prew.find(pre=out[-1])))["pro"])
except IndexError:
iter += 69420
iter += 1
coun += 1
if coun <= 3:
shared.enmul -= 1
elif coun >= shared.maxiter:
shared.enmul += 1
if coun <= 4:
shared.enmul += 1
elif coun >= shared.maxiter:
shared.enmul -= 1
return out
print(f"coun {coun} enmul {shared.enmul} maxiter {shared.maxiter}")
return out
async def filter(self, c, n, m):
if c in shared.qtime and shared.qtime[c] > time.time():
return
if m[:len(shared.prefix)] == shared.prefix:
m = m[len(shared.prefix):]
await go(self, c, n, m)
elif m[:len(self.nickname)+1] == self.nickname+' ':
m = m[len(self.nickname)+1:]
await go(self, c, n, m)
elif '#' not in c and n != self.nickname:
await go(self, c, n, m)
else:
if len(m.split()) > 1:
if shared.learntime + shared.learndelay < time.time():
await rec(self, m)
shared.learntime = time.time()
if c in shared.qtime and shared.qtime[c] > time.time():
return
if m[: len(shared.prefix)] == shared.prefix:
m = m[len(shared.prefix) :]
await go(self, c, n, m)
elif m[: len(self.nickname) + 1] == self.nickname + " ":
m = m[len(self.nickname) + 1 :]
await go(self, c, n, m)
elif "#" not in c and n != self.nickname:
await go(self, c, n, m)
else:
if len(m.split()) > 1:
if shared.learntime + shared.learndelay < time.time():
await rec(self, m)
shared.learntime = time.time()
async def go(self, c, n, m):
await rec(self, m)
words = re.sub(r'([\.,\?!])', r' \1', m).split()
if words[0] == 'admin':
return
msg = re.sub(r' ([\.,\?!])', r'\1', ' '.join(await genOut(self, await getNoun(self, words, c))))
words = re.sub(r"([\.,\?!])", r" \1", m).split()
if words[0] == "admin":
return
msg = re.sub(
r" ([\.,\?!])",
r"\1",
" ".join(await genOut(self, await getNoun(self, words, c))),
)
if msg[-1] == "\x01" and msg[0] != "\x01":
msg = msg[:-1]
await self.message(c, msg)
await self.send(build("PRIVMSG", [c, msg]))
async def init(self):
shared.qtime = {}
shared.learntime = 0
shared.qtime = {}
shared.learntime = 0
# delay between grabbing random messages and passively
# learning.
shared.learndelay = 1
# sentance ending weight, lower means longer sentances,
# higher means shorter sentances. this will need to slowly
# get larger as the database grows
shared.enmul = 9
shared.maxiter = 14
# delay between grabbing random messages and passively
# learning.
shared.learndelay = 1
# sentance ending weight, higher means longer sentances,
# lower means shorter sentances. this will need to slowly
# get larger as the database grows
shared.enmul = 200
shared.maxiter = 14
shared.rawm['nlp'] = filter
shared.cstate = {}
shared.rawm["nlp"] = filter
shared.cstate = {}

View file

@ -2,13 +2,11 @@ import asyncio
import bot
@bot.command('test')
@bot.command("test")
@bot.is_admin
async def testy(self,channel,nick,msg):
await bot.message(self,channel,'hi there')
async def testy(self, channel, nick, msg):
await bot.message(self, channel, "hi there")
async def init(self):
pass
pass

View file

@ -1,12 +1,10 @@
import dataset
prefix = 'min: '
prefix = "min: "
modules = {}
listeners = []
commands = {}
rawm = {}
db = dataset.connect('sqlite:///database.db')
db = dataset.connect("sqlite:///database.db")
qtime = {}