use oirc improvements

This commit is contained in:
vulpine 2020-07-11 22:00:18 +00:00
parent e0ed0341a5
commit f69bffa29b
2 changed files with 45 additions and 22 deletions

65
bot.py
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import pydle, asyncio, sys, os, time
import pydle, asyncio, dataset, sys, os, time
class Oven(pydle.Client):
async def on_connect(self):
@ -11,7 +11,8 @@ class Oven(pydle.Client):
self.cmd = {}
self.raw = {}
self.help = {}
self.db = dataset.connect('sqlite:///database.db')
self.t=0
print('loading modules...')
await self.loadMods()
@ -20,8 +21,12 @@ class Oven(pydle.Client):
await self.join(i)
print('Done!')
# tilde +B bot
await self.set_mode(self.nickname, '+B')
async def loadMods(self):
for i in [s for s in os.listdir('modules') if ".py" in s]:
for i in [s for s in os.listdir('modules') if ".py" in s and '.swp' not in s]:
i = i[:-3]
print('loading', i)
m = __import__("modules."+i)
@ -31,38 +36,54 @@ class Oven(pydle.Client):
async def on_invite(self, channel, by):
print('{} invited me to {}!'.format(by, channel))
self.t = time.time()+1
await self.join(channel)
async def on_message(self, chan, source, msg):
if source != self.nickname:
if time.time() > self.t:
if msg == '!botlist':
await self.message(chan, 'helo im kim, a learning chatbot https://xfnw.ttm.sh/git/kim/')
await self.parseCommand(chan, source, msg)
for i in self.raw:
await self.raw[i](self, chan,source,msg)
await self.raw[i](self, chan, source, msg)
async def parseCommand(self, chan, source, msg):
if msg[:len(self.prefix)] == self.prefix:
msg = msg[len(self.prefix):]
cmd = msg.split(' ')[0]
msg = msg[len(cmd)+1:]
if len(cmd) < 1:
return
if cmd in self.cmd:
await self.cmd[cmd](self, chan, source, msg)
return
if msg == '!botlist':
await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation with llckthecheese (https://git.io/KimBot)')
if msg[:len(self.prefix)] == self.prefix:
msg = msg[len(self.prefix):]
cmd = msg.split(' ')[0]
msg = msg[len(cmd)+1:]
if cmd in self.cmd:
await self.cmd[cmd](self, chan, source, msg)
# fuzzy search for commands
results = [i for i in self.cmd if i.startswith(cmd)]
if len(results) == 1:
await self.cmd[results[0]](self, chan, source, msg)
async def is_admin(self, nickname):
admin = False
# Check the WHOIS info to see if the source has identified with NickServ.
# This is a blocking operation, so use yield.
if nickname in self.admins:
info = await self.whois(nickname)
admin = info['identified']
info = await self.whois(nickname)
if 'account' in info:
account = info['account']
else:
# they are not nickserv registered
return False
return admin
return account in self.admins
async def on_private_message(self, trash, source, msg):
if source != self.nickname:
@ -71,8 +92,8 @@ class Oven(pydle.Client):
if __name__ == "__main__":
client = Oven('kim', realname='Kim Jong Un?')
client.admins = ['lickthecheese', 'ben', 'cmccabe', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'brendo', 'khuxkm','lick']
client.prefix = 'kim: '
client = Oven('kim', realname='owens bot')
client.admins = ['lickthecheese', 'ben', 'coffeeowl', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'khuxkm']
client.prefix = '.'
client.run('team.tilde.chat', tls=True, tls_verify=False)

2
dep.sh Executable file
View File

@ -0,0 +1,2 @@
gweb -p oirc -r ~/ph/git/oirc.git -l https://xfnw.ttm.sh/git/oirc.git ~/ph/git/oirc