From 10115d9841015eac1a7c7412e965cb44c2f0bbd7 Mon Sep 17 00:00:00 2001 From: Mallory Hancock Date: Wed, 27 Sep 2017 12:27:24 -0700 Subject: [PATCH] add basic bot framework --- pinhook/__init__.py | 0 pinhook/bot.py | 46 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 pinhook/__init__.py create mode 100644 pinhook/bot.py diff --git a/pinhook/__init__.py b/pinhook/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pinhook/bot.py b/pinhook/bot.py new file mode 100644 index 0000000..223248c --- /dev/null +++ b/pinhook/bot.py @@ -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() +