From 13aac4b6656c6bbeb64a694a3d87818c51507abe Mon Sep 17 00:00:00 2001 From: lickthecheese Date: Sun, 5 Apr 2020 18:25:19 -0400 Subject: [PATCH] bot framework a bit --- bot.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index bfb4984..76734bf 100755 --- a/bot.py +++ b/bot.py @@ -1,20 +1,64 @@ #!/usr/bin/env python3 -import pydle, asyncio +import pydle, asyncio, sys, os class Oven(pydle.Client): async def on_connect(self): print('Connected!') + self.modules = {} + self.cmd = {} + self.raw = {} + self.help = {} + + print('joining channels...') + for i in self.chansjoin: + await self.join(i) + print('loading modules...') + await self.loadMods() + print('Done!') + + async def loadMods(self): + for i in [s for s in os.listdir('modules') if ".py" in s]: + i = i[:-3] + print('loading', i) + m = __import__("modules."+i) + m = eval('m.'+i) + await m.init(self) + self.modules[i] = m + + + - await self.join('#bots') async def on_message(self, chan, source, msg): if source != self.nickname: - await self.message(chan, ' '.join(await self.whois(source).keys())) + if msg == '!botlist': + await self.message(chan, 'hoinlo im oven im owned by lickthecheese and bake stuff for you') + for i in self.raw: + await self.raw[i](self, chan,source,msg) + if msg[:len(self.prefix)] == self.prefix: + cmd = msg.split(' ')[0] + msg = msg[len(cmd):] + if cmd in self.cmd: + await self.cmd[cmd](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'] + + return admin + if __name__ == "__main__": client = Oven('oven', realname='Oven IRC Bot') + client.chansjoin = ['#bots'] + client.admins = ['lickthecheese'] + client.prefix = 'ov ' client.run('irc.tilde.chat', tls=True, tls_verify=False)