commit 0428a8764e128b89885a5e08c66dc04320d980d1
Author: Christoph Lohmann <20h@r-36.net>
Date: Sun, 28 Dec 2025 15:27:27 +0100
initial commit
Diffstat:
| A | vibe.py | | | 96 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 96 insertions(+), 0 deletions(-)
diff --git a/vibe.py b/vibe.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python3
+# coding=utf-8
+#
+# adapted from nurdspace-ircbot-plugin-python-example
+# by 20h, released under GPLv3
+#
+
+import paho.mqtt.client as mqtt
+import threading
+import socket
+import sys
+import time
+import random
+
+mqtt_server = 'mqtt.vm.nurd.space'
+topic_prefix = 'GHBot/'
+channels = ['nurds']
+prefix = '!'
+
+def gen_dance_moves(nmoves=10, vibemove="ascii"):
+ ascii_moves = ["\\o/", "\\o_", "_o_", "_o/", "~o/", "\\o~", "~o~",
+ "-o/", "\\o-", "-o-", "\\o.", ".o/", ".o.",
+ "\\o7", "_o7", "-o7", ".o7", "~o7", "\\^o^/",
+ "\\^o_", "_o^/", "~o^/", "\\^o~", "-o^/",
+ "\\^o-", "\\^o.", ".o^/", "\\^o7",
+ "(>OoO)>", "<(OoO<)", "/o/", "\\o\\"]
+ egyptian_moves = [
+ "𓀀", "𓀁", "𓀂", "𓀃", "𓀉", "𓀊",
+ "𓀋", "𓀏", "𓀐", "𓀒", "𓀓", "𓀔",
+ "𓀕", "𓀖", "𓀞", "𓀟", "𓀠", "𓀡",
+ "𓀢", "𓀣", "𓀤", "𓀥", "𓁌", "𓁎",
+ "𓁏"]
+
+ moves = ascii_moves
+ if vibemove == "egytian":
+ moves = egyptian_moves
+ elif vibemove == "asciiegyptian":
+ moves = egyptian_moves + ascii_moves
+
+ ostr = ""
+ for i in range(nmoves):
+ if len(ostr) > 0:
+ ostr += " "
+ ostr += random.choice(moves)
+ return ostr
+
+def announce_commands(client):
+ target_topic = f'{topic_prefix}to/bot/register'
+ client.publish(target_topic, 'cmd=vibe|descr=vibe like there is no tomorrow')
+
+def on_message(client, userdata, message):
+ global prefix
+ text = message.payload.decode('utf-8')
+ topic = message.topic[len(topic_prefix):]
+ if topic == 'from/bot/command' and text == 'register':
+ announce_commands(client)
+ return
+ if topic == 'from/bot/parameter/prefix':
+ prefix = text
+ return
+ if text[0] != prefix:
+ return
+
+ parts = topic.split('/')
+ channel = parts[2] if len(parts) >= 3 else 'nurds'
+ nick = parts[3] if len(parts) >= 4 else 'jemoeder'
+ if channel in channels or (len(channel) >= 1 and channel[0] == '\\'):
+ tokens = text.split(' ')
+ command = tokens[0][1:]
+ response_topic = f'{topic_prefix}to/irc/{channel}/notice'
+ if command == 'vibe':
+ if len(tokens) > 1:
+ dancemoves = gen_dance_moves(vibemove=token[2])
+ else:
+ dancemoves = gen_dance_moves()
+ client.publish(response_topic, dancemoves)
+
+def on_connect(client, userdata, flags, rc):
+ client.subscribe(f'{topic_prefix}from/irc/#')
+ client.subscribe(f'{topic_prefix}from/bot/command')
+
+def announce_thread(client):
+ while True:
+ try:
+ announce_commands(client)
+ time.sleep(4.1)
+ except Exception as e:
+ print(f'Failed to announce: {e}')
+
+client = mqtt.Client(f'{socket.gethostname()}_{sys.argv[0]}', clean_session=False)
+client.on_message = on_message
+client.on_connect = on_connect
+client.connect(mqtt_server, port=1883, keepalive=4, bind_address="")
+t = threading.Thread(target=announce_thread, args=(client,))
+t.start()
+client.loop_forever()