Compare commits
3 commits
b18f6a4091
...
2da355c739
Author | SHA1 | Date | |
---|---|---|---|
2da355c739 | |||
9987bb87db | |||
421fc9b98a |
5 changed files with 49 additions and 44 deletions
26
config.py
26
config.py
|
@ -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
main.py → its_matrix_bot/__init__.py
Normal file → Executable file
18
main.py → its_matrix_bot/__init__.py
Normal file → Executable file
|
@ -1,11 +1,10 @@
|
||||||
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:
|
||||||
|
@ -21,6 +20,7 @@ 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,15 +77,3 @@ 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))
|
|
15
its_matrix_bot/__main__.py
Normal file
15
its_matrix_bot/__main__.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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))
|
26
its_matrix_bot/config.py
Normal file
26
its_matrix_bot/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,6 +1,7 @@
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
|
||||||
class ItSyndikatApi:
|
class ItSyndikatApi:
|
||||||
base_url: str
|
base_url: str
|
||||||
|
@ -15,10 +16,11 @@ 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(self.base_url + "ping.php", params=params) as response:
|
async with session.post(
|
||||||
|
self.base_url + "ping.php", params=params
|
||||||
|
) as response:
|
||||||
await response.text()
|
await response.text()
|
Loading…
Reference in a new issue