initial commit
This commit is contained in:
commit
afb75c496a
32
bot.py
Normal file
32
bot.py
Normal file
@ -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)
|
31
default.nix
Normal file
31
default.nix
Normal file
@ -0,0 +1,31 @@
|
||||
{ pkgs ? import <nixpkgs> { }, 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 ];
|
||||
}
|
41
flake.lock
generated
Normal file
41
flake.lock
generated
Normal 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
18
flake.nix
Normal 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;
|
||||
}
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user