Compare commits

...

11 Commits

11 changed files with 121 additions and 41 deletions

9
bot.py
View File

@ -9,10 +9,11 @@ class Balun(pydle.Client):
self.modules = {}
self.cmd = {}
self.raw = {}
self.rawm = {}
self.help = {}
self.db = dataset.connect('sqlite:///database.db')
self.t=0
self.acceptInvites=True
print('loading modules...')
await self.loadMods()
@ -35,6 +36,8 @@ class Balun(pydle.Client):
self.modules[i] = m
async def on_invite(self, channel, by):
if not self.acceptInvites:
return
print('{} invited me to {}!'.format(by, channel))
self.t = time.time()+1
await self.join(channel)
@ -58,8 +61,8 @@ class Balun(pydle.Client):
if msg == '!botlist':
await self.message(chan, 'helo im owen\'s nice bot https://xfnw.ttm.sh/git/oirc')
await self.parseCommand(chan, source, msg)
for i in self.raw:
await self.raw[i](self, chan, source, msg)
for i in self.rawm:
await self.rawm[i](self, chan, source, msg)
async def parseCommand(self, chan, source, msg):
if msg[:len(self.prefix)] == self.prefix:

View File

@ -13,7 +13,7 @@ async def reloadmods(self, chan, source, msg):
await self.message(chan, '[\x036admin\x0f] reloading modules...')
self.oldcmd = self.cmd
self.cmd = {}
self.raw = {}
self.rawm = {}
self.help = {}
try:
for i in self.modules:
@ -83,6 +83,67 @@ async def schans(self, c, n, m):
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))
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 self.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
self.rawm[al]=Ot(m,al).ot
await self.message(c,'[\x036admin\x0f] 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
if al in self.rawm:
await self.message(c,'[\x036admin\x0f] no dont overwrite a command dummy')
return
self.rawm[al]=Trigger(m,al).trigger
await self.message(c,'[\x036admin\x0f] added "{}" trigger for "{}"'.format(al,m))
class Ot():
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
async def ot(alself,self,c,n,m):
if alself.al in m and n != self.nickname:
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
self.rawm.pop(alself.al)
class Trigger():
def __init__(self, ms, al):
self.ms = str(ms)
self.al = str(al)
async def trigger(alself,self,c,n,m):
if alself.al in m:
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
class Alias():
def __init__(self, ms):
self.ms = str(ms)
async def alias(alself,self,c,n,m):
asyncio.create_task(self.on_message(c,n,alself.ms.format(m)))
@ -96,7 +157,10 @@ commands = {
'send': send,
'joins': joins,
'shut': shut,
'schans': schans
'schans': schans,
'addalias': addalias,
'addtrigger': addtrigger,
'addot': addot,
}
async def adminHandle(self, chan, source, msg):
@ -106,7 +170,7 @@ async def adminHandle(self, chan, source, msg):
await self.message(chan, '[\x036admin\x0f] Invalid command')
return
print('[ADMIN MODULE] {} told me to {}!!!'.format(source,msg[0]))
await commands[msg.pop(0)](self, chan, source, ' '.join(msg))
asyncio.create_task(commands[msg.pop(0)](self, chan, source, ' '.join(msg)))
else:
await self.message(chan, '[\x036admin\x0f] You do not have permission to do this')

View File

@ -1,10 +1,16 @@
async def action(self,c,n,m):
await self.message(c,'\x01ACTION {}\x01'.format(m[:400]))
async def echo(self,c,n,m):
await self.message(c,'[\x036channels\x0f] {}'.format(m[:400]))
async def init(self):
self.chansjoin = ['#bots']
self.cmd['echo']=echo
self.cmd['action']=action

View File

@ -2,14 +2,17 @@ import random
async def coffeeup(self,c,n,m):
if c in ['#coffee','#tea','#water']:
if c[1:]+"!" in m and c+'!' not in m:
if c in ['#coffee','#tea','#water','#CAPS']:
if (c[1:]+"!" in m and c+'!' not in m) or c=='#coffee' and ('latte!' in m or 'espresso!' in m) or c=='#tea' and ('chai!' in m):
cc = self.coffee.find_one(name=c)
if cc:
self.coffee.update(dict(name=c,value=cc['value']+1),['name'])
else:
self.coffee.insert(dict(name=c,value=1))
await self.message(c, '[\x036drinks\x0f] ・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()))
if c=='#CAPS':
await self.message(c, '[\x036drinks\x0f] ・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()).upper())
else:
await self.message(c, '[\x036drinks\x0f] ・゜゜・。。・゜゜c[~] {} UP!'.format(c[1:].upper()))
elif "cupcount" in m:
await self.message(c, '[\x036drinks\x0f] {} delicious cups of {}{} served so far!'.format(
self.coffee.find_one(name=c)['value'], random.choice(self.coffeetypes), c[1:]
@ -19,7 +22,7 @@ async def coffeeup(self,c,n,m):
async def init(self):
self.raw['coffeeup'] = coffeeup
self.rawm['coffeeup'] = coffeeup
self.coffee = self.db['coffee']
self.coffeetypes = [

View File

@ -8,10 +8,9 @@ async def source(self,c,n,m):
await self.message(c,'[\x036modulemanager\x0f] My source is at https://xfnw.ttm.sh/git/oirc/')
async def init(self):
self.help['modules'] = ['modules - list the modules',':o']
self.cmd['modules'] = listMods
self.raw['source'] = source
self.rawm['source'] = source

View File

@ -32,7 +32,7 @@ async def owotext(self, back, chan):
async def init(self):
self.owolog = {}
self.raw['owolog'] = owologger
self.rawm['owolog'] = owologger
self.cmd['owo'] = owoify
self.help['owo'] = ['owo [num] - owoify the text', 'owo owo uwu']

View File

@ -1,16 +0,0 @@
async def pd(self,c,n,m):
if n in ['tildebot','BitBot','xfnw'] and m == '・゜゜・。。・゜゜\\_o< QUACK!':
self.duckmsg[c] = 0
print('duck in',c)
elif c in self.duckmsg:
self.duckmsg[c] += 1
if self.duckmsg[c] == 200 or self.duckmsg[c] == 150 or self.duckmsg[c] == 140:
await self.notice(self.ducknotif,'i predict there will be a duck in {} soon'.format(c))
async def init(self):
self.raw['pd'] = pd
self.ducknotif='xfnw'
self.duckmsg = {}

View File

@ -32,5 +32,5 @@ async def init(self):
self.plog = {}
self.wlevel = {}
self.mutesyntax = ['+b','m:{}'] # ['+q','{}'] on freenode
self.raw['preventionlog'] = plogger
self.rawm['preventionlog'] = plogger

View File

@ -14,7 +14,19 @@ async def rpninp(self, chan, nick, msg):
if chan not in self.rpnhist:
self.rpnhist[chan] = [0]
try:
for m in msg.split(' '):
msg = msg.replace('+',' + ')
msg = msg.replace('a',' a ')
msg = msg.replace('-',' - ')
msg = msg.replace('s',' s ')
msg = msg.replace('\\',' \\ ')
msg = msg.replace('*',' * ')
msg = msg.replace('x',' x ')
msg = msg.replace('m',' m ')
msg = msg.replace('/',' / ')
msg = msg.replace('d',' d ')
msg = msg.replace('^',' ^ ')
msg = msg.replace('e',' e ')
for m in msg.split():
self.rpnhist[chan].append(0)
del self.rpnhist[chan][15:]
if isfloat(m):
@ -24,18 +36,17 @@ async def rpninp(self, chan, nick, msg):
self.rpnhist[chan][0] = self.rpnhist[chan][0]+self.rpnhist[chan].pop(1)
elif m == '-' or m == 's':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)-self.rpnhist[chan][0]
elif m == '\\':
self.rpnhist[chan].insert(0,self.rpnhist[chan][0])
elif m == '*' or m == 'x' or m == 'm':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)*self.rpnhist[chan][0]
elif m == '/' or m == 'd':
try:
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)/self.rpnhist[chan][0]
except ZeroDivisionError:
self.rpnhist[chan][0] = float('NaN')
elif m == '^' or m == 'e':
self.rpnhist[chan][0] = self.rpnhist[chan].pop(1)**self.rpnhist[chan][0]
elif msg == 'p':
pass # just dont do anything lol
elif msg == 'r':
@ -51,6 +62,16 @@ async def rpninp(self, chan, nick, msg):
if chan in self.rpnprint:
await self.message(chan, '[\x036rpn\x0f] '+str(self.rpnhist[chan][0]))
async def rpntinp(self, chan, nick, msg):
if chan in self.rpnprint:
await rpninp(self, chan, nick, msg)
else:
self.rpnprint.append(chan)
await rpninp(self, chan, nick, msg)
self.rpnprint.remove(chan)
async def rpntoggle(self, chan, nick, msg):
if chan in self.rpnprint:
self.rpnprint.remove(chan)
@ -61,9 +82,9 @@ async def rpntoggle(self, chan, nick, msg):
async def init(self):
self.help['rpn'] = ['rpn <inp> - simple reverse polish notation calculator (more)', 'it has an alias of . so you can just do {}. <inp>, and if enabled it will also parse floats and functions as input. there are 4 functions, add (+|a), subtract (-|s), multiply (*|x|m), and devide (/|d), and p to print register 0'.format(self.prefix)]
self.cmd['rpn'] = rpninp
self.cmd['.'] = rpninp
self.raw['rpn'] = rpninp
self.cmd['rpn'] = rpntinp
self.cmd['.'] = rpntinp
self.rawm['rpn'] = rpninp
self.cmd['rt'] = rpntoggle
self.help['rt'] = ['rt - toggle the output of rpn calculatons into the channel', 'rpn is cool']

View File

@ -23,7 +23,7 @@ async def getPronouns(self,c,n,m):
await self.message(c,'[\x036scrape\x0f] sorry i could not find {}\'s pronouns. (i scrape pronouns from logs, you dont need to set them :3 )'.format(m))
async def init(self):
self.raw['scraper'] = scraper
self.rawm['scraper'] = scraper
self.pronoundb = self.db['pronouns']
self.cmd['pronouns'] = getPronouns

View File

@ -9,7 +9,7 @@ async def on_all(self,wtime=100):
print('will index users in ',wtime)
await asyncio.sleep(wtime)
print('started indexing users')
users = self.users
users = self.users.copy()
for person in users:
user = self.users[person]
await asyncio.sleep(0)
@ -29,7 +29,7 @@ async def maskfind(self,c,n,m):
alts = ["{}!{}@{}".format(i['nickname'],i['username'][:1]+"\u200c"+i['username'][1:],i['hostname']) for i in self.userdb.find(hostname={'like':host},username={'like':ident},nickname={'like':nick},order_by='-id')]
falt=' '.join([i[:1]+'\u200c'+i[1:] for i in sorted(list(set(alts)))])
falt=' '.join([i[:1]+'\u200c'+i[1:] for i in list(set(alts))])
if len(falt) > 250:
self.more[c] = falt[200:]
falt = falt[:200]+' (more)'