From afb75c496a6a48e1fd217d8766c7a457c32600d8 Mon Sep 17 00:00:00 2001 From: zuckerberg <5-zuckerberg@users.noreply.git.neet.dev> Date: Fri, 23 Jul 2021 21:15:56 -0400 Subject: [PATCH] initial commit --- bot.py | 32 ++++++++++++++++++++++++++++++++ default.nix | 31 +++++++++++++++++++++++++++++++ flake.lock | 41 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 18 ++++++++++++++++++ setup.py | 14 ++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 bot.py create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 setup.py diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..eff3dac --- /dev/null +++ b/bot.py @@ -0,0 +1,32 @@ +import pydle +import requests +import random + +host = "https://collectionapi.metmuseum.org/public/collection/v1/" + +# get the list of artwork +r = requests.get(host + 'objects') +objects = r.json()['objectIDs'] + +def getArt(): + while True: + r = requests.get(host + 'objects/' + str(random.choice(objects))) + j = r.json() + if j['primaryImage']: + return j + +# Simple echo bot. +class RadioBot(pydle.Client): + async def on_connect(self): + await self.join('#dailybot') + await self.join('#dailybuild') + + async def on_message(self, target, source, message): + # don't respond to our own messages, as this leads to a positive feedback loop + if source != self.nickname: + if message.startswith(".art"): + art = getArt() + await self.message(target, '"' + art['title'] + '" ' + art['objectDate'] + '" ' + art['primaryImage']) + +client = RadioBot('ArtBot', realname='ArtBot') +client.run('irc.rizon.net', tls=True, tls_verify=True) diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..f95516d --- /dev/null +++ b/default.nix @@ -0,0 +1,31 @@ +{ pkgs ? import { }, self ? ./. }: + +let + puresasl = pkgs.python3Packages.buildPythonPackage rec { + pname = "puresasl"; + version = "0.6.2"; + + src = builtins.fetchTarball { + url = "https://github.com/thobbs/pure-sasl/archive/refs/tags/0.6.2.tar.gz"; + sha256 = "1xazi5v3s16pzqk1iii7370zdayk04wxp6ng2d5l5bsb0vfijyh0"; + }; + + propagatedBuildInputs = with pkgs.python3Packages; [ pytest kerberos mock ]; + }; + pydle = pkgs.python3Packages.buildPythonPackage rec { + pname = "pydle"; + version = "0.9.4"; + + src = builtins.fetchTarball { + url = "https://github.com/Shizmob/pydle/archive/refs/tags/v0.9.4.tar.gz"; + sha256 = "1gnd28c5m0kpyz6iczzyb0qj82r80mjkzbhck3jb670zinjvxan1"; + }; + + propagatedBuildInputs = with pkgs.python3Packages; [ pytest ]; + }; +in pkgs.python3Packages.buildPythonApplication { + pname = "radio-bot"; + src = self; + version = "0.1"; + propagatedBuildInputs = with pkgs.python3Packages; [ pydle requests puresasl ]; +} \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..93a591e --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1622445595, + "narHash": "sha256-m+JRe6Wc5OZ/mKw2bB3+Tl0ZbtyxxxfnAWln8Q5qs+Y=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7d706970d94bc5559077eb1a6600afddcd25a7c8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1622587467, + "narHash": "sha256-f9tDxAnHKkIA3Bf2PQDKBLxt51+A0tmHSSazYU2Qu9Q=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d9d422285c2183b68a49c01eda179bd48526e6f2", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d14296c --- /dev/null +++ b/flake.nix @@ -0,0 +1,18 @@ +{ + description = "IRC bot for internet radio service"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = nixpkgs.legacyPackages.${system}; in + rec { + packages = flake-utils.lib.flattenTree { + radio-bot = import ./default.nix { inherit pkgs; inherit self; }; + }; + defaultPackage = packages.radio-bot; + apps.radio-bot = flake-utils.lib.mkApp { drv = packages.radio-bot; }; + defaultApp = apps.radio-bot; + } + ); +} diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e94bfe8 --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +requires = ["pydle","requests"] + +setup( + name='art-bot', + version='0.1', + py_modules=[ + 'bot', + ], + entry_points={ + 'console_scripts': ['radio-bot = bot:run'] + }, +)