Compare commits
No commits in common. "2da355c73937c2d297bd5ccf0b1f2486de8883fc" and "b18f6a409124fe01ae0f3b6db9ec4ed294aafc3a" have entirely different histories.
2da355c739
...
b18f6a4091
5 changed files with 44 additions and 49 deletions
26
config.py
Normal file
26
config.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import toml
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
command_prefix: str
|
||||||
|
|
||||||
|
matrix_homeserver: str
|
||||||
|
matrix_user: str
|
||||||
|
matrix_access_token: str
|
||||||
|
|
||||||
|
spaceping_token: str
|
||||||
|
|
||||||
|
def __init__(self, path=None):
|
||||||
|
if path is None:
|
||||||
|
path = "/etc/itsyndikat-bot.toml"
|
||||||
|
|
||||||
|
config = toml.load(path)
|
||||||
|
|
||||||
|
self.command_prefix = config['app']['command_prefix']
|
||||||
|
|
||||||
|
matrix = config['matrix']
|
||||||
|
self.matrix_homeserver = matrix['homeserver']
|
||||||
|
self.matrix_username = matrix['username']
|
||||||
|
self.matrix_access_token = matrix['access_token']
|
||||||
|
|
||||||
|
self.spaceping_token = config['spaceping']['api_token']
|
|
@ -1,7 +1,6 @@
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from .config import Config
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class ItSyndikatApi:
|
class ItSyndikatApi:
|
||||||
base_url: str
|
base_url: str
|
||||||
|
@ -16,11 +15,10 @@ class ItSyndikatApi:
|
||||||
async with session.get(self.base_url + "status.php") as response:
|
async with session.get(self.base_url + "status.php") as response:
|
||||||
return await response.json()
|
return await response.json()
|
||||||
|
|
||||||
|
|
||||||
async def ping(self):
|
async def ping(self):
|
||||||
params = {"apikey": self.config.spaceping_token}
|
params = {"apikey": self.config.spaceping_token}
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.post(
|
async with session.post(self.base_url + "ping.php", params=params) as response:
|
||||||
self.base_url + "ping.php", params=params
|
|
||||||
) as response:
|
|
||||||
await response.text()
|
await response.text()
|
|
@ -1,15 +0,0 @@
|
||||||
import argparse
|
|
||||||
|
|
||||||
from . import ItSyndikatBot
|
|
||||||
from .config import Config
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="IT-Syndikat matrix bot")
|
|
||||||
parser.add_argument(
|
|
||||||
"-c",
|
|
||||||
"--config",
|
|
||||||
help="path to the config file",
|
|
||||||
)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
ItSyndikatBot(Config(args.config))
|
|
|
@ -1,26 +0,0 @@
|
||||||
import toml
|
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
command_prefix: str
|
|
||||||
|
|
||||||
matrix_homeserver: str
|
|
||||||
matrix_user: str
|
|
||||||
matrix_access_token: str
|
|
||||||
|
|
||||||
spaceping_token: str
|
|
||||||
|
|
||||||
def __init__(self, path=None):
|
|
||||||
if path is None:
|
|
||||||
path = "/etc/itsyndikat-bot.toml"
|
|
||||||
|
|
||||||
config = toml.load(path)
|
|
||||||
|
|
||||||
self.command_prefix = config["app"]["command_prefix"]
|
|
||||||
|
|
||||||
matrix = config["matrix"]
|
|
||||||
self.matrix_homeserver = matrix["homeserver"]
|
|
||||||
self.matrix_username = matrix["username"]
|
|
||||||
self.matrix_access_token = matrix["access_token"]
|
|
||||||
|
|
||||||
self.spaceping_token = config["spaceping"]["api_token"]
|
|
18
its_matrix_bot/__init__.py → main.py
Executable file → Normal file
18
its_matrix_bot/__init__.py → main.py
Executable file → Normal file
|
@ -1,10 +1,11 @@
|
||||||
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
from nio.rooms import MatrixRoom
|
from nio.rooms import MatrixRoom
|
||||||
from nio.events.room_events import RoomMessage
|
from nio.events.room_events import RoomMessage
|
||||||
import simplematrixbotlib as botlib
|
import simplematrixbotlib as botlib
|
||||||
|
|
||||||
from .its_api import ItSyndikatApi
|
from its_api import ItSyndikatApi
|
||||||
from .config import Config
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class ItSyndikatBot:
|
class ItSyndikatBot:
|
||||||
|
@ -20,7 +21,6 @@ class ItSyndikatBot:
|
||||||
config.matrix_homeserver,
|
config.matrix_homeserver,
|
||||||
config.matrix_username,
|
config.matrix_username,
|
||||||
access_token=config.matrix_access_token,
|
access_token=config.matrix_access_token,
|
||||||
session_stored_file="",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.its_api = ItSyndikatApi(config)
|
self.its_api = ItSyndikatApi(config)
|
||||||
|
@ -77,3 +77,15 @@ class ItSyndikatBot:
|
||||||
async def spaceping(self, room: MatrixRoom, message: RoomMessage):
|
async def spaceping(self, room: MatrixRoom, message: RoomMessage):
|
||||||
await self.its_api.ping()
|
await self.its_api.ping()
|
||||||
await self.reply(room, message, "Hello Space!")
|
await self.reply(room, message, "Hello Space!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="IT-Syndikat matrix bot")
|
||||||
|
parser.add_argument(
|
||||||
|
"-c", "--config",
|
||||||
|
help="path to the config file",
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
ItSyndikatBot(Config(args.config))
|
Loading…
Reference in a new issue