use oirc improvements
This commit is contained in:
parent
e0ed0341a5
commit
f69bffa29b
2 changed files with 45 additions and 22 deletions
61
bot.py
61
bot.py
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
import pydle, asyncio, sys, os, time
|
import pydle, asyncio, dataset, sys, os, time
|
||||||
|
|
||||||
class Oven(pydle.Client):
|
class Oven(pydle.Client):
|
||||||
async def on_connect(self):
|
async def on_connect(self):
|
||||||
|
@ -11,7 +11,8 @@ class Oven(pydle.Client):
|
||||||
self.cmd = {}
|
self.cmd = {}
|
||||||
self.raw = {}
|
self.raw = {}
|
||||||
self.help = {}
|
self.help = {}
|
||||||
|
self.db = dataset.connect('sqlite:///database.db')
|
||||||
|
self.t=0
|
||||||
|
|
||||||
print('loading modules...')
|
print('loading modules...')
|
||||||
await self.loadMods()
|
await self.loadMods()
|
||||||
|
@ -20,8 +21,12 @@ class Oven(pydle.Client):
|
||||||
await self.join(i)
|
await self.join(i)
|
||||||
print('Done!')
|
print('Done!')
|
||||||
|
|
||||||
|
# tilde +B bot
|
||||||
|
await self.set_mode(self.nickname, '+B')
|
||||||
|
|
||||||
|
|
||||||
async def loadMods(self):
|
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]
|
i = i[:-3]
|
||||||
print('loading', i)
|
print('loading', i)
|
||||||
m = __import__("modules."+i)
|
m = __import__("modules."+i)
|
||||||
|
@ -31,38 +36,54 @@ class Oven(pydle.Client):
|
||||||
|
|
||||||
async def on_invite(self, channel, by):
|
async def on_invite(self, channel, by):
|
||||||
print('{} invited me to {}!'.format(by, channel))
|
print('{} invited me to {}!'.format(by, channel))
|
||||||
|
self.t = time.time()+1
|
||||||
await self.join(channel)
|
await self.join(channel)
|
||||||
|
|
||||||
|
|
||||||
async def on_message(self, chan, source, msg):
|
async def on_message(self, chan, source, msg):
|
||||||
if source != self.nickname:
|
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:
|
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 msg == '!botlist':
|
if cmd in self.cmd:
|
||||||
await self.message(chan, 'dah helooooooo i am kim jong un, pingus me to have a nice conversation with llckthecheese (https://git.io/KimBot)')
|
await self.cmd[cmd](self, chan, source, msg)
|
||||||
if msg[:len(self.prefix)] == self.prefix:
|
return
|
||||||
|
|
||||||
msg = msg[len(self.prefix):]
|
# fuzzy search for commands
|
||||||
cmd = msg.split(' ')[0]
|
results = [i for i in self.cmd if i.startswith(cmd)]
|
||||||
msg = msg[len(cmd)+1:]
|
if len(results) == 1:
|
||||||
if cmd in self.cmd:
|
await self.cmd[results[0]](self, chan, source, msg)
|
||||||
await self.cmd[cmd](self, chan, source, msg)
|
|
||||||
|
|
||||||
|
|
||||||
async def is_admin(self, nickname):
|
async def is_admin(self, nickname):
|
||||||
admin = False
|
|
||||||
|
|
||||||
# Check the WHOIS info to see if the source has identified with NickServ.
|
# Check the WHOIS info to see if the source has identified with NickServ.
|
||||||
# This is a blocking operation, so use yield.
|
# This is a blocking operation, so use yield.
|
||||||
if nickname in self.admins:
|
info = await self.whois(nickname)
|
||||||
info = await self.whois(nickname)
|
if 'account' in info:
|
||||||
admin = info['identified']
|
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):
|
async def on_private_message(self, trash, source, msg):
|
||||||
if source != self.nickname:
|
if source != self.nickname:
|
||||||
|
@ -71,8 +92,8 @@ class Oven(pydle.Client):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
client = Oven('kim', realname='Kim Jong Un?')
|
client = Oven('kim', realname='owens bot')
|
||||||
client.admins = ['lickthecheese', 'ben', 'cmccabe', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'brendo', 'khuxkm','lick']
|
client.admins = ['lickthecheese', 'ben', 'coffeeowl', 'gbmor', 'tomasino', 'ubergeek', 'deepend', 'calamitous', 'khuxkm']
|
||||||
client.prefix = 'kim: '
|
client.prefix = '.'
|
||||||
client.run('team.tilde.chat', tls=True, tls_verify=False)
|
client.run('team.tilde.chat', tls=True, tls_verify=False)
|
||||||
|
|
||||||
|
|
2
dep.sh
Executable file
2
dep.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
gweb -p oirc -r ~/ph/git/oirc.git -l https://xfnw.ttm.sh/git/oirc.git ~/ph/git/oirc
|
||||||
|
|
Loading…
Reference in a new issue