Created
February 8, 2022 21:25
-
-
Save folkertvanheusden/818c9a73fb264796edfa8510d84dc1ec to your computer and use it in GitHub Desktop.
1e bot using @r3boot's new bot framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
# by FvH, released under Apache License v2.0 | |
# either install 'python3-paho-mqtt' or 'pip3 install paho-mqtt' | |
import paho.mqtt.client as mqtt | |
import time | |
mqtt_server = '192.168.64.1' | |
def on_message(client, userdata, message): | |
text = message.payload.decode('ascii') | |
parts = message.topic.split('/') | |
channel = parts[2] | |
nick = parts[3] | |
if not 'message' in parts: | |
return | |
if text[0:16] == '!zorgverzekering': | |
client.publish(f'to/irc/{channel}/privmsg', 'Het beste neem je een zorgverzekering die je ziektekosten afdekt.') | |
else: | |
print('No match for', text) | |
def on_connect(client, userdata, flags, rc): | |
if rc == 0: | |
client.subscribe('from/irc/#') | |
client = mqtt.Client() | |
client.connect(mqtt_server, port=1883, keepalive=4, bind_address="") | |
client.on_message = on_message | |
client.on_connect = on_connect | |
client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment