Initial commit

This commit is contained in:
Robert Miles 2018-08-05 10:37:02 -04:00
commit 8f4d794569
3 changed files with 149 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/

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# tetrisbot
Bot for #tetris, my disassembly project channel.

42
bot.py Normal file
View File

@ -0,0 +1,42 @@
import teambot
USAGE = dict(help="!help [command]")
HELP = dict(help="Helps define commands.")
PREFIX = "!"
BOTOPS = "khuxkm khuxkm|lounge".split()
class TetrisBot(teambot.Handler):
def on_pubmsg(self,channel,nick,text):
self.channel = channel
parts = text.split(PREFIX,1)[1].split()
command = parts.pop(0)
parts.insert(0,nick)
if hasattr(self,"do_"+command.lower()):
try:
getattr(self,"do_"+command.lower())(*parts)
except TypeError: # missing an arg or having too many? print usage
self.say(self.channel,"{}: Usage: {}".format(nick,USAGE[command.lower()]))
def do_help(self,nick,command=None):
if command is None:
self.say(self.channel,"{}: Commands: {}".format(nick,", ".join(USAGE[k] for k in USAGE.keys())))
else:
if command not in HELP:
self.say(self.channel,"{}: no such command!".format(nick))
else:
self.say(self.channel,"{}: {} - {} ({})".format(nick,command,HELP[command],USAGE[command]))
def do_admin(self,nick,action,prefix="!"):
if nick not in BOTOPS:
self.say(self.channel,nick+": you are not authorized to use this command")
if action=="quit":
self._bot.die("Goodbye!")
elif action=="prefix":
global PREFIX
PREFIX = prefix
self.say(self.channel,nick+": Prefix set to \"{}\".".format(prefix))
if __name__=="__main__":
channels = "#tetris".split()
bot = teambot.TeamBot(channels,"tetrisbot","localhost",chandler=TetrisBot)
bot.start()