Skip to content
Snippets Groups Projects
Commit 162bacb8 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Update chatbot

parent edc06e11
No related branches found
No related tags found
No related merge requests found
...@@ -15,6 +15,7 @@ Options: ...@@ -15,6 +15,7 @@ Options:
""" """
import re import re
import toml import toml
from rocketchat_API.rocketchat import RocketChat
from RocketChatBot import RocketChatBot from RocketChatBot import RocketChatBot
URL = "https://chat.km3net.de" URL = "https://chat.km3net.de"
...@@ -24,6 +25,19 @@ with open(CONFIG, 'r') as fobj: ...@@ -24,6 +25,19 @@ with open(CONFIG, 'r') as fobj:
config = toml.load(fobj) config = toml.load(fobj)
BOTNAME = config['Alerts']['botname'] BOTNAME = config['Alerts']['botname']
PASSWORD = config['Alerts']['password'] PASSWORD = config['Alerts']['password']
CHANNEL = config['Alerts']['channel']
def get_channel_id(channel):
rocket = RocketChat(BOTNAME, PASSWORD, server_url=URL)
channels = rocket.channels_list().json()['channels']
for c in channels:
if c['name'] == channel:
return c['_id']
CHANNEL_ID = get_channel_id(CHANNEL)
def run(): def run():
...@@ -38,12 +52,21 @@ def spawn_bot(): ...@@ -38,12 +52,21 @@ def spawn_bot():
def register_handlers(bot): def register_handlers(bot):
def greet(msg, user, channel_id): def greet(msg, user, channel_id):
if channel_id != CHANNEL_ID:
print("skipping")
return
bot.send_message('hello @' + user, channel_id) bot.send_message('hello @' + user, channel_id)
def status(msg, user, channel_id): def status(msg, user, channel_id):
if channel_id != CHANNEL_ID:
print("skipping")
return
bot.send_message('erm... smooth datataking... for sure', channel_id) bot.send_message('erm... smooth datataking... for sure', channel_id)
def shifters(msg, user, channel_id): def shifters(msg, user, channel_id):
if channel_id != CHANNEL_ID:
print("skipping")
return
try: try:
with open(CONFIG, 'r') as fobj: with open(CONFIG, 'r') as fobj:
config = toml.load(fobj) config = toml.load(fobj)
...@@ -59,6 +82,9 @@ def register_handlers(bot): ...@@ -59,6 +82,9 @@ def register_handlers(bot):
channel_id) channel_id)
def help(msg, user, channel_id): def help(msg, user, channel_id):
if channel_id != CHANNEL_ID:
print("skipping", channel_id)
return
help_str = f""" help_str = f"""
Hi @{user} I was built to take care of the monitoring alerst. Hi @{user} I was built to take care of the monitoring alerst.
Here is how you can use me: Here is how you can use me:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment