basic radio bot

This commit is contained in:
zuckerberg 2021-06-01 20:18:35 -04:00
commit be8f9f7aa7
5 changed files with 124 additions and 0 deletions

31
bot.py Normal file
View File

@ -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)

20
default.nix Normal file
View File

@ -0,0 +1,20 @@
{ pkgs ? import <nixpkgs> { }, 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 ];
}

41
flake.lock generated Normal file
View File

@ -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
}

18
flake.nix Normal file
View File

@ -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;
}
);
}

14
setup.py Normal file
View File

@ -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']
},
)