add basic bot framework

pull/1/head
Mallory Hancock 2017-09-27 12:27:24 -07:00
parent 6f0e4d4564
commit 10115d9841
2 changed files with 46 additions and 0 deletions

View File

46
pinhook/bot.py 100644
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
import imp
import os
import sys
import irc.bot
irc.client.ServerConnection.buffer_class.errors = 'replace'
class Bot(irc.bot.SingleServerIRCBot):
def __init__(self, channels, nickname, server, port=6667, ops=[]):
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.chanlist = channels
self.bot_nick = nickname
self.ops = ops
def on_welcome(self, c, e):
for channel in self.chanlist:
c.join(channel)
def on_pubmsg(self, c, e):
self.process_command(c, e, e.arguments[0])
def on_privmsg(self, c, e):
self.process_command(c, e, e.arguments[0])
def process_command(self, c, e, text):
nick = e.source.nick
if e.target == self.bot_nick:
chan = nick
else:
chan = e.target
cmd = text.split(' ')[0]
if len(text.split(' ')) > 1:
arg = ''.join([i + ' ' for i in text.split(' ')[1:]]).strip()
else:
arg = ''
output = ()
if cmd == '!join' and nick in self.ops:
c.join(arg)
c.privmsg(chan, '{}: joined {}'.format(nick, arg))
elif cmd == '!quit' and nick in self.ops:
c.quit("See y'all later!")
quit()