r2chat/examples/botexample.py
2026-04-11 14:36:49 -07:00

26 lines
519 B
Python

import os, sys
sys.path.append(os.path.abspath("../"))
from botclient import r2bot
import time
bot = r2bot(channel="chat", username="genericbot")
def mainhandler(msg):
if "/test" in msg:
bot.send("hello world")
def mentionhandler(msg):
bot.send("mentioned")
bot.on("on_message", mainhandler)
bot.on("on_mention", mentionhandler)
try:
print("Bot is running.")
while True:
bot.poll()
time.sleep(1)
except KeyboardInterrupt:
print("Stopping bot.")
bot.leave_channel()