forked from Dogo6647/r2chat
bot client
This commit is contained in:
parent
f734201242
commit
8eaa8e3adf
4 changed files with 307 additions and 5 deletions
26
examples/botexample.py
Normal file
26
examples/botexample.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue