Initial commit

This commit is contained in:
Robert Miles 2018-06-25 15:46:13 -04:00
commit 0b218247cf
9 changed files with 2724 additions and 0 deletions

104
.gitignore vendored Normal file
View File

@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

2427
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Richard Pappalardo <rpappalax@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

11
Makefile Normal file
View File

@ -0,0 +1,11 @@
SRCS:=$(wildcard teambot/*.py)
build:
python setup.py sdist
# DO NOT USE THIS!!!!
#upload:
# python setup.py sdist upload
clean:
python setup.py clean

4
README.rst Normal file
View File

@ -0,0 +1,4 @@
teambot
=======
A framework for IRC bots.

34
setup.py Normal file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.rst')) as f:
README = f.read()
REQUIREMENTS = [
'irc'
]
setup(
name='teambot',
version='0.1.5',
description='teambot',
long_description=README,
author='Robert Miles',
author_email='khuxkm@tilde.team',
url='https://git.tilde.team/meta/teambot',
license="MIT",
install_requires=REQUIREMENTS,
keywords=["irc","bot"],
packages=find_packages(),
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.3',
],
entry_points={
'console_scripts': ['teambot = teambot.console_handler:main']
},
)

4
teambot/__init__.py Normal file
View File

@ -0,0 +1,4 @@
from bot import TeamBot
from handler import *
__all__ = ["TeamBot","Handler","CommandHandlerMixin"]

50
teambot/bot.py Normal file
View File

@ -0,0 +1,50 @@
## @module teambot.bot
# Contains the bot class.
import irc.bot
import handler
## The main bot class.
#
#
class TeamBot(irc.bot.SingleServerIRCBot):
## Initializes the bot.
#
# @param self The bot instance.
# @param channels A list of channels for the bot to join.
# @param nickname A nickname for the bot.
# @param server The server to connect to.
# @param chandler The Handler subclass to use.
def __init__(self, channels, nickname, server, port=6667, chandler=handler.Handler):
irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
self.chanlist = channels
self.bot_nick = nickname
self.handler = chandler(self)
## Joins the supplied channels and stores the connection object.
#
# @param self The bot object.
# @param conn The connection object. Stored in self.conn after this.
# @param event The welcome event. Unused.
def on_welcome(self, conn, event):
for channel in self.chanlist:
c.join(channel)
self.conn = c
## Called when a message is sent in a public channel.
#
# @param self The bot object.
# @param conn The connection object.
# @param event The event object.
def on_pubmsg(self, conn, event):
self.handler.event = e
self.handler.on_pubmsg(e.target,e.source.nick,e.arguments[0])
## Called when a message is sent to the bot in a private message/query.
#
# @param self The bot object.
# @param conn The connection object.
# @param event The event object.
def on_privmsg(self, conn, event):
self.handler.event = e
self.handler.on_privmsg(e.source.nick,e.arguments[0])

69
teambot/handler.py Normal file
View File

@ -0,0 +1,69 @@
## @package teambot.handler
# Contains the base handler class.
## Base Handler class.
#
# This class will handle all messages from bots.
# In on_pubmsg or on_privmsg, the event property will be set with the message event. (See jaraco/irc documentation for event object properties.
class Handler:
def __init__(self,bot):
self._bot = bot # save bot instance
## Called when a message is sent in a public channel.
#
# @param self The handler object
# @param channel The channel the message was sent in.
# @param nick The nickname of the user who sent the message.
# @param text The text of the message.
def on_pubmsg(self,channel,nick,text):
pass
## Called when a message is sent to the bot in a private message/query.
#
# @param self The handler object
# @param nick The nickname of the user who sent the message.
# @param text The text of the message.
def on_privmsg(self,nick,text):
pass
## Sends a message to a channel or nick.
#
# @param self The handler object
# @param target The target of the message
# @param message The message to send
def say(self,target,message):
self._bot.conn.privmsg(target,message)
## Command handler mixin for Handler class
#
# In specific, this class causes all messages to be sent to the `handle_command` function. The event property is still set.
class CommandHandlerMixin:
## Called when a message is sent in a public channel.
#
# CommandHandlerMixin causes the message to be sent to `handle_command`.
#
# @param self The handler object
# @param channel The channel the message was sent in.
# @param nick The nickname of the user who sent the message.
# @param text The text of the message.
def on_pubmsg(self,channel,nick,text):
self.handle_command(channel,nick,text)
## Called when a message is sent to the bot in a private message/query.
#
# CommandHandlerMixin causes the message to be sent to `handle_command`.
#
# @param self The handler object
# @param nick The nickname of the user who sent the message.
# @param text The text of the message.
def on_privmsg(self,nick,text):
self.handle_command(self.event.target,nick,text)
## Called when a message is recieved.
#
# @param self The handler object
# @param target The target of the original message.
# @param nick The nickname of the user who sent the message.
# @param text The text of the message.
def handle_command(self,target,nick,text):
pass