made it a proper(ish) python package

This commit is contained in:
Stephen McQuay 2013-02-24 20:42:00 -08:00
parent 3c1bdca561
commit 5324c48a0e
3 changed files with 42 additions and 20 deletions

View File

@ -1,8 +1,7 @@
import argparse
import re import re
from twisted.words.protocols import irc from twisted.words.protocols import irc
from twisted.internet import protocol, reactor from twisted.internet import protocol
class IRCBot(irc.IRCClient): class IRCBot(irc.IRCClient):
@ -19,6 +18,10 @@ class IRCBot(irc.IRCClient):
print('joined {}'.format(channel)) print('joined {}'.format(channel))
def privmsg(self, user, channel, msg): def privmsg(self, user, channel, msg):
""" deals with messages, both private and public, in a channel
Your code will most likely go in here.
"""
username = user.split('!', 1)[0] username = user.split('!', 1)[0]
if channel == self.nickname: if channel == self.nickname:
self.msg(username, "whisper back ...") self.msg(username, "whisper back ...")
@ -40,21 +43,3 @@ class IRCBotFactory(protocol.ClientFactory):
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
print('could not connect: {}'.format(reason)) print('could not connect: {}'.format(reason))
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', type=str, default='localhost')
parser.add_argument('-p', '--port', type=int, default=6667)
parser.add_argument('-n', '--nick', type=str, default='bot')
parser.add_argument('channels', nargs='+')
args = parser.parse_args()
reactor.connectTCP(
args.host, int(args.port),
IRCBotFactory(
('#{}'.format(c) for c in args.channels),
nickname=args.nick
)
)
reactor.run()

24
ircbot/main.py Normal file
View File

@ -0,0 +1,24 @@
import argparse
from twisted.internet import reactor
from ircbot import IRCBotFactory
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--host', type=str, default='localhost')
parser.add_argument('-p', '--port', type=int, default=6667)
parser.add_argument('-n', '--nick', type=str, default='bot')
parser.add_argument('channels', nargs='+')
args = parser.parse_args()
reactor.connectTCP(
args.host, int(args.port),
IRCBotFactory(
('#{}'.format(c) for c in args.channels),
nickname=args.nick
)
)
reactor.run()

13
setup.py Normal file
View File

@ -0,0 +1,13 @@
from setuptools import setup, find_packages
setup(
name='ircbot',
version="0.1dev",
packages=find_packages(),
author='Stephen McQuay',
author_email='stephen@mcquay.me',
install_requires=['Twisted'],
entry_points={'console_scripts': [
'ircbot = ircbot.main:main',
]},
)