From 05d08bfc5f1bfad61f728c796c976bd40eab64cd Mon Sep 17 00:00:00 2001 From: lza_menace Date: Tue, 20 Oct 2020 22:19:36 -0700 Subject: [PATCH] add boilerplate code --- .gitignore | 3 +++ README.md | 13 ++++++++++++ requests.txt | 4 ++++ supportbot/__init__.py | 0 supportbot/__main__.py | 10 +++++++++ supportbot/bot.py | 41 ++++++++++++++++++++++++++++++++++++ supportbot/config.example.py | 17 +++++++++++++++ supportbot/db.py | 15 +++++++++++++ 8 files changed, 103 insertions(+) create mode 100644 requests.txt create mode 100644 supportbot/__init__.py create mode 100644 supportbot/__main__.py create mode 100644 supportbot/bot.py create mode 100644 supportbot/config.example.py create mode 100644 supportbot/db.py diff --git a/.gitignore b/.gitignore index b6e4761..acce484 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Extra data +data diff --git a/README.md b/README.md index 8b643e1..b743e67 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # monerosupport + An IRC bot for helping people on /r/monerosupport + +todo + +``` +# Setup +python3 -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt + +# Run +python3 -m supportbot +``` diff --git a/requests.txt b/requests.txt new file mode 100644 index 0000000..b48962c --- /dev/null +++ b/requests.txt @@ -0,0 +1,4 @@ +praw +peewee +pure-sasl +pydle diff --git a/supportbot/__init__.py b/supportbot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/supportbot/__main__.py b/supportbot/__main__.py new file mode 100644 index 0000000..59e3f15 --- /dev/null +++ b/supportbot/__main__.py @@ -0,0 +1,10 @@ +import logging +from supportbot import run_bot + +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s' +) + +if __name__ == '__main__': + run_bot() diff --git a/supportbot/bot.py b/supportbot/bot.py new file mode 100644 index 0000000..0cf4353 --- /dev/null +++ b/supportbot/bot.py @@ -0,0 +1,41 @@ +import sys, os +import pydle +from supportbot import config +from supportbot import db + + +class IRCBot(pydle.Client): + async def on_connect(self): + for room in config.ROOMS: + await self.join(room) + + async def on_message(self, target, source, message): + if source == self.nickname: + return + else: + print(f"Target: {target} - Source: {source} - Message: {message}") + + if self.nickname in message: + await self.message(target, f"Sup. I'm not very helpful yet, but getting there." + + async def is_admin(self, nickname): + admin = False + if nickname in config.ADMIN_NICKNAMES: + info = await self.whois(nickname) + admin = info['identified'] + print("info: ", info) + return admin + + + +def run_bot(): + try: + print(f"[+] Starting IRC bot connecting to {config.IRC_HOST}...\n") + client = IRCBot(nickname=config.BOT_NICKNAME) + client.run(config.IRC_HOST, tls=True, tls_verify=False) + except KeyboardInterrupt: + print(' - Adios') + try: + sys.exit(0) + except SystemExit: + os._exit(0) diff --git a/supportbot/config.example.py b/supportbot/config.example.py new file mode 100644 index 0000000..b5b5500 --- /dev/null +++ b/supportbot/config.example.py @@ -0,0 +1,17 @@ +# Bot meta +BOT_NICKNAME = 'mybotname' +ROOMS = ['#monero-support'] +ADMIN_NICKNAMES = ['lza_menace', 'needmoney90'] + +# DB +SQLITE_DB_PATH = './data/supportbot.sqlite' + +# IRC +IRC_HOST = 'ajnvpgl6prmkb7yktvue6im5wiedlz2w32uhcwaamdiecdrfpwwgnlqd.onion' + +# Reddit +PRAW_CLIENT_SECRET = 'xxxxxxxx' +PRAW_CLIENT_ID = 'xxxxxxxx' +PRAW_USERNAME = 'xxxxxxxx' +PRAW_PASSWORD = 'xxxxxxxx' +PRAW_USER_AGENT = 'r-monerosupport-dev-python' diff --git a/supportbot/db.py b/supportbot/db.py new file mode 100644 index 0000000..0c4ab54 --- /dev/null +++ b/supportbot/db.py @@ -0,0 +1,15 @@ +import datetime +from peewee import * +import config + + +db = SqliteDatabase(config.SQLITE_DB_PATH) + +class BaseModel(Model): + class Meta: + database = db + +class SupportRequest(BaseModel): + reddit_user = CharField() + solved = BooleanField(default=False) + # todo...