From be8f9f7aa7b3fb2016037c18d06a2b77dd49aa7e Mon Sep 17 00:00:00 2001 From: zuckerberg <5-zuckerberg@users.noreply.git.neet.dev> Date: Tue, 1 Jun 2021 20:18:35 -0400 Subject: [PATCH] basic radio bot --- bot.py | 31 +++++++++++++++++++++++++++++++ default.nix | 20 ++++++++++++++++++++ flake.lock | 41 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 18 ++++++++++++++++++ setup.py | 14 ++++++++++++++ 5 files changed, 124 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..c0ffdb0 --- /dev/null +++ b/bot.py @@ -0,0 +1,31 @@ +import pydle +import requests + +host = "http://localhost:5000/" + +# Simple echo bot. +class RadioBot(pydle.Client): + async def on_connect(self): + await self.join('#dailybot') + + 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(".play "): + pload = {'url': message[len(".play "):]} + r = requests.post(host+"play", data = pload) + await self.message(target, r.text) + if message.startswith(".current"): + r = requests.get(host+"current") + await self.message(target, r.text) + if message.startswith(".skip"): + r = requests.post(host+"skip") + await self.message(target, r.text) + if message.startswith(".queue"): + r = requests.get(host+"queue") + await self.message(target, r.text) + if message.startswith(".stream"): + await self.message(target, "https://nanachi.neet.dev/stream.mp3") + +client = RadioBot('RadioBot', realname='RadioBot') +client.run('irc.rizon.net', tls=True, tls_verify=True) \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..6f83a3d --- /dev/null +++ b/default.nix @@ -0,0 +1,20 @@ +{ pkgs ? import { }, self ? ./. }: + +let + 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 ]; +} \ 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..a70937a --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from setuptools import setup + +requires = ["pydle"] + +setup( + name='bot', + version='0.1', + py_modules=[ + 'bot', + ], + entry_points={ + 'console_scripts': ['radio-bot = bot:run'] + }, +) \ No newline at end of file