forked from Dogo6647/r2chat
26 lines
519 B
Python
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()
|