unfuck the requirements & dockerfile
This commit is contained in:
parent
50357b91de
commit
c7e2237de0
162
bin/pubsubbot
162
bin/pubsubbot
|
@ -1,162 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
from contextlib import closing
|
||||
from argparse import ArgumentParser
|
||||
from json import loads, load
|
||||
from msgbus.client import MsgbusSubClient
|
||||
import pyircbot
|
||||
import traceback
|
||||
from pyircbot.pyircbot import PrimitiveBot
|
||||
from pyircbot.irccore import IRCEvent, UserPrefix
|
||||
from pyircbot.common import TouchReload
|
||||
from json import dumps
|
||||
|
||||
|
||||
class PyIRCBotSub(PrimitiveBot):
|
||||
def __init__(self, name, host, port, config):
|
||||
super().__init__(config)
|
||||
self.name = name
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.meta = {}
|
||||
self.client = None # PubSub socket
|
||||
|
||||
def run(self):
|
||||
# Connect to msgbus and loop through messages
|
||||
with closing(MsgbusSubClient(self.host, self.port)) as self.client:
|
||||
self.client.prepare_pub()
|
||||
self.client.sub("pyircbot_privmsg")
|
||||
self.client.sub("pyircbot_join")
|
||||
self.client.sub("pyircbot_kick")
|
||||
self.client.sub("pyircbot_part")
|
||||
self.client.sub("pyircbot_mode")
|
||||
self.client.sub("pyircbot_quit")
|
||||
self.client.sub("pyircbot_meta_update")
|
||||
self.client.pub("pyircbot_meta_req", "x")
|
||||
while True:
|
||||
try:
|
||||
channel, body = self.client.recv()
|
||||
self.process_line(channel, body)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
|
||||
def process_line(self, channel, body):
|
||||
name, rest = body.split(" ", 1)
|
||||
if name != self.name:
|
||||
return
|
||||
|
||||
command = channel.split("_", 1)[1]
|
||||
|
||||
if command == "meta_update":
|
||||
self.meta.update(loads(rest))
|
||||
print(self.meta)
|
||||
return
|
||||
|
||||
args, sender, trailing, extras = loads(rest)
|
||||
nick, username, hostname = extras["prefix"]
|
||||
|
||||
msg = IRCEvent(command.upper(),
|
||||
args,
|
||||
UserPrefix(nick,
|
||||
username,
|
||||
hostname),
|
||||
trailing)
|
||||
|
||||
for module_name, module in self.moduleInstances.items():
|
||||
for hook in module.irchooks:
|
||||
validation = hook.validator(msg, self)
|
||||
if validation:
|
||||
hook.method(msg, validation)
|
||||
|
||||
" Filesystem Methods "
|
||||
def getConfigPath(self, moduleName):
|
||||
"""Return the absolute path for a module's config file
|
||||
|
||||
:param moduleName: the module who's config file we want
|
||||
:type moduleName: str"""
|
||||
|
||||
basepath = "%s/config/%s" % (self.botconfig["bot"]["datadir"], moduleName)
|
||||
|
||||
if os.path.exists("%s.json" % basepath):
|
||||
return "%s.json" % basepath
|
||||
return None
|
||||
|
||||
def getDataPath(self, moduleName):
|
||||
"""Return the absolute path for a module's data dir
|
||||
|
||||
:param moduleName: the module who's data dir we want
|
||||
:type moduleName: str"""
|
||||
module_dir = os.path.join(self.botconfig["bot"]["datadir"], "data", moduleName)
|
||||
if not os.path.exists(module_dir):
|
||||
os.mkdir(module_dir)
|
||||
return module_dir
|
||||
|
||||
def act_PRIVMSG(self, towho, message):
|
||||
"""Use the `/msg` command
|
||||
|
||||
:param towho: the target #channel or user's name
|
||||
:type towho: str
|
||||
:param message: the message to send
|
||||
:type message: str"""
|
||||
# self.sendRaw("PRIVMSG %s :%s" % (towho, message))
|
||||
self.client.pub("pyircbot_send", "{} {} {}".format(self.name, "privmsg", dumps([towho, message])))
|
||||
|
||||
def getBestModuleForService(self, service):
|
||||
if service == "services":
|
||||
return self
|
||||
return super().getBestModuleForService(service)
|
||||
|
||||
def nick(self):
|
||||
return self.meta.get("nick", None)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.WARNING,
|
||||
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
||||
log = logging.getLogger('main')
|
||||
|
||||
# parse command line args
|
||||
parser = ArgumentParser(description="Run pyircbot plugins behind a pubsub client")
|
||||
parser.add_argument("-c", "--config", help="Pyircbot config file")
|
||||
parser.add_argument("-s", "--server", default="localhost", help="Msgbus server address")
|
||||
parser.add_argument("-p", "--port", default=7100, type=int, help="Msgbus server port")
|
||||
parser.add_argument("-n", "--name", default="default", help="bot name")
|
||||
parser.add_argument("--debug", action="store_true", help="increase logging level")
|
||||
parser.add_argument("--touch-reload", action="store_true", help="reload modules on file modification")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
log.debug(args)
|
||||
|
||||
# Load config
|
||||
with open(args.config) as f:
|
||||
config = load(f)
|
||||
|
||||
bot = PyIRCBotSub(args.name, args.server, int(args.port), config)
|
||||
|
||||
# Load modules in config
|
||||
moddir = os.path.join(os.path.dirname(pyircbot.__file__), "modules")
|
||||
modpaths = []
|
||||
sys.path.append(moddir)
|
||||
for modulename in config["modules"]:
|
||||
bot.loadmodule(modulename)
|
||||
modpaths.append(os.path.join(moddir, modulename + ".py"))
|
||||
|
||||
if args.touch_reload:
|
||||
def changed(path):
|
||||
module_name = os.path.basename(path).split(".")[-2]
|
||||
logging.warning("{} was modified, reloading".format(module_name))
|
||||
if module_name in bot.moduleInstances.keys(): # TODO fix shitty mystery results from redomodule in core
|
||||
bot.redomodule(module_name)
|
||||
else:
|
||||
bot.loadmodule(module_name)
|
||||
|
||||
reloader = TouchReload(modpaths, changed)
|
||||
reloader.daemon = True
|
||||
reloader.start()
|
||||
|
||||
bot.run()
|
||||
|
47
bin/pyircbot
47
bin/pyircbot
|
@ -1,47 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import logging
|
||||
import signal
|
||||
from argparse import ArgumentParser
|
||||
from pyircbot.common import load
|
||||
from pyircbot import PyIRCBot
|
||||
from json import loads
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
" logging level and facility "
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format="%(asctime)-15s %(levelname)-8s %(filename)s:%(lineno)d %(message)s")
|
||||
log = logging.getLogger('main')
|
||||
|
||||
" parse command line args "
|
||||
parser = ArgumentParser(description="Run pyircbot")
|
||||
parser.add_argument("-c", "--config", help="Path to config file", required=True)
|
||||
parser.add_argument("--debug", action="store_true", help="Dump raw irc network")
|
||||
parser.add_argument("-q", "--quit-message", help="Quit message if killed by signal",
|
||||
default="received signal {}")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.debug:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
log.debug(args)
|
||||
|
||||
if not args.config:
|
||||
log.critical("No bot config file specified (-c). Exiting.")
|
||||
sys.exit(1)
|
||||
|
||||
botconfig = loads(sys.stdin.read()) if args.config == "-" else load(args.config)
|
||||
|
||||
log.debug(botconfig)
|
||||
|
||||
bot = PyIRCBot(botconfig)
|
||||
|
||||
def signal_handler(signum, stack):
|
||||
print('Received:', signum)
|
||||
bot.kill(message=args.quit_message.format(signum))
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
bot.run()
|
|
@ -1,26 +1,23 @@
|
|||
FROM ubuntu:bionic
|
||||
|
||||
RUN sed -i -E 's/deb http:\/\/(us.)?archive.ubuntu.com/deb http:\/\/192.168.1.119/' /etc/apt/sources.list
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3-pip git && \
|
||||
useradd --home-dir /srv/bot bot && \
|
||||
mkdir -p /srv/bot && \
|
||||
chown bot /srv/bot
|
||||
|
||||
COPY ./requirements.txt /requirements.txt
|
||||
|
||||
RUN pip3 install -r /requirements.txt
|
||||
|
||||
|
||||
COPY ./ /tmp/pyircbot
|
||||
RUN cd /tmp/pyircbot && \
|
||||
python3 setup.py install
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/pyircbot"]
|
||||
WORKDIR /srv/bot/
|
||||
CMD ["-c", "config.json"]
|
||||
ADD requirements.txt /tmp/requirements.txt
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3 python3-setuptools python3-pip sqlite3 git && \
|
||||
pip3 install -r /tmp/requirements.txt && \
|
||||
useradd --home-dir /srv/bot bot && \
|
||||
chown bot /srv/bot && \
|
||||
apt-get remove -y python3-pip perl && \
|
||||
apt-get autoremove -y && \
|
||||
apt-get clean -y && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY . /tmp/pyircbot/
|
||||
|
||||
RUN cd /tmp/pyircbot/ && \
|
||||
python3 setup.py install && \
|
||||
su -c "cp -r /tmp/pyircbot/examples/config.json /tmp/pyircbot/examples/data/ /srv/bot/" bot && \
|
||||
cd / && \
|
||||
rm -rf /tmp/pyircbot
|
||||
|
||||
USER bot
|
||||
|
|
|
@ -1,47 +1,35 @@
|
|||
apipkg==1.4
|
||||
appdirs==1.4.3
|
||||
certifi==2017.4.17
|
||||
attrs==17.4.0
|
||||
backports.functools-lru-cache==1.5
|
||||
certifi==2018.4.16
|
||||
chardet==3.0.4
|
||||
cheroot==5.9.1
|
||||
CherryPy==12.0.1
|
||||
coverage==4.4.2
|
||||
decorator==4.0.11
|
||||
cheroot==6.2.4
|
||||
CherryPy==14.2.0
|
||||
coverage==4.5.1
|
||||
execnet==1.5.0
|
||||
idna==2.5
|
||||
ipdb==0.10.3
|
||||
ipython==6.0.0
|
||||
ipython-genutils==0.2.0
|
||||
jaraco.classes==1.4.3
|
||||
jedi==0.10.2
|
||||
lxml==4.1.1
|
||||
mock==2.0.0
|
||||
-e git+http://gitlab.davepedu.com/dave/pymsgbus.git#egg=msgbus
|
||||
packaging==16.8
|
||||
pbr==3.1.1
|
||||
pexpect==4.2.1
|
||||
pickleshare==0.7.4
|
||||
idna==2.6
|
||||
more-itertools==4.1.0
|
||||
-e git+http://git.davepedu.com/dave/pymsgbus.git@373a9c5f153078fce57bde43f493785859f51de4#egg=msgbus
|
||||
pluggy==0.6.0
|
||||
portend==2.2
|
||||
praw==5.0.1
|
||||
prawcore==0.11.0
|
||||
prompt-toolkit==1.0.14
|
||||
ptyprocess==0.5.1
|
||||
py==1.5.2
|
||||
Pygments==2.2.0
|
||||
PyJWT==1.5.3
|
||||
pyparsing==2.2.0
|
||||
PySocks==1.6.7
|
||||
pytest==3.2.5
|
||||
praw==5.4.0
|
||||
prawcore==0.14.0
|
||||
py==1.5.3
|
||||
PyJWT==1.6.1
|
||||
PyMySQL==0.8.0
|
||||
PySocks==1.6.8
|
||||
pytest==3.5.0
|
||||
pytest-cov==2.5.1
|
||||
pytest-cover==3.0.0
|
||||
pytest-coverage==0.0
|
||||
pytest-forked==0.2
|
||||
pytest-xdist==1.20.1
|
||||
pytz==2017.3
|
||||
pyzmq==16.0.2
|
||||
requests==2.18.1
|
||||
simplegeneric==0.8.1
|
||||
pytest-xdist==1.22.2
|
||||
-e git+https://github.com/jgarzik/python-bitcoinrpc.git@76ced424dc16f997365265487487056e653238c6#egg=python_bitcoinrpc
|
||||
pytz==2018.4
|
||||
pyzmq==17.0.0
|
||||
requests==2.18.4
|
||||
six==1.11.0
|
||||
tempora==1.9
|
||||
traitlets==4.3.2
|
||||
twilio==6.9.0
|
||||
tempora==1.11
|
||||
twilio==6.12.1
|
||||
update-checker==0.16
|
||||
urllib3==1.21.1
|
||||
wcwidth==0.1.7
|
||||
urllib3==1.22
|
||||
|
|
|
@ -1,35 +1,23 @@
|
|||
alabaster==0.7.10
|
||||
Babel==2.5.3
|
||||
certifi==2017.11.5
|
||||
backports.functools-lru-cache==1.5
|
||||
certifi==2018.4.16
|
||||
chardet==3.0.4
|
||||
cheroot==6.0.0
|
||||
CherryPy==13.1.0
|
||||
docutils==0.14
|
||||
cheroot==6.2.4
|
||||
CherryPy==14.2.0
|
||||
idna==2.6
|
||||
imagesize==0.7.1
|
||||
Jinja2==2.10
|
||||
lxml==4.1.1
|
||||
MarkupSafe==1.0
|
||||
more-itertools==4.0.1
|
||||
pyzmq==16.0.3
|
||||
more-itertools==4.1.0
|
||||
-e git+http://git.davepedu.com/dave/pymsgbus.git@373a9c5f153078fce57bde43f493785859f51de4#egg=msgbus
|
||||
portend==2.2
|
||||
praw==5.3.0
|
||||
prawcore==0.13.0
|
||||
Pygments==2.2.0
|
||||
PyJWT==1.5.3
|
||||
praw==5.4.0
|
||||
prawcore==0.14.0
|
||||
PyJWT==1.6.1
|
||||
PyMySQL==0.8.0
|
||||
PySocks==1.6.8
|
||||
-e git+https://github.com/jgarzik/python-bitcoinrpc.git@76ced424dc16f997365265487487056e653238c6#egg=python_bitcoinrpc
|
||||
pytz==2017.3
|
||||
releases==1.4.0
|
||||
pytz==2018.4
|
||||
pyzmq==17.0.0
|
||||
requests==2.18.4
|
||||
semantic-version==2.6.0
|
||||
six==1.11.0
|
||||
snowballstemmer==1.2.1
|
||||
Sphinx==1.6.6
|
||||
sphinxcontrib-websupport==1.0.1
|
||||
tempora==1.10
|
||||
twilio==6.9.0
|
||||
tempora==1.11
|
||||
twilio==6.12.1
|
||||
update-checker==0.16
|
||||
urllib3==1.22
|
||||
|
|
7
setup.py
7
setup.py
|
@ -10,5 +10,10 @@ setup(name='pyircbot',
|
|||
author='dpedu',
|
||||
author_email='dave@davepedu.com',
|
||||
packages=['pyircbot', 'pyircbot.modules'],
|
||||
scripts=['bin/pyircbot'],
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"pyircbot = pyircbot.cli:main",
|
||||
"pubsubbot = pyircbot.clipub:main"
|
||||
]
|
||||
},
|
||||
zip_safe=False)
|
||||
|
|
Loading…
Reference in New Issue