diff options
author | vin <git@vineetk.net> | 2024-01-14 23:16:43 -0500 |
---|---|---|
committer | vin <git@vineetk.net> | 2024-01-14 23:16:43 -0500 |
commit | f73e354f6a960c6a5bb36365a61a8a8790ec7f7d (patch) | |
tree | 1ef2f45a4cc3218be72fb99d4105b4f3d1c011bc | |
parent | 1cc61d85c3d9ef0eb39f4f05913e6bc60e909f62 (diff) |
use config.json instead of hardcoding and envvars
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | config.json.sample | 11 | ||||
-rw-r--r-- | main.py | 14 |
3 files changed, 20 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cffcb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json
\ No newline at end of file diff --git a/config.json.sample b/config.json.sample new file mode 100644 index 0000000..1d7a85b --- /dev/null +++ b/config.json.sample @@ -0,0 +1,11 @@ +{ + "discord_token": "goeshere", + "matrix_token": "goeshere", + "matrix_userid": "@examplebot:example.org", + "matrix_homeserver": "https://matrix.example.org", + "rooms": { + "REMOVE_ME": "key is discord channel id as string, value is matrix room" + "123456789": "!yadayada:matrix.example.org", + "133333337": "!yadayadamore:matrix.example.org" + } +} @@ -2,17 +2,19 @@ import asyncio, json, os import hikari import mautrix.client +config = json.load(open("config.json", "r")) + dclient = hikari.GatewayBot( - token=os.getenv("DISCORD_TOKEN"), + token=config["discord_token"], intents=(hikari.Intents.MESSAGE_CONTENT|hikari.Intents.GUILD_MESSAGES) ) mclient = mautrix.client.ClientAPI( - os.getenv("MATRIX_USERID"), - base_url=os.getenv("MATRIX_HOMESERVER"), - token=os.getenv("MATRIX_TOKEN") + config["matrix_userid"], + base_url=config["matrix_homeserver"], + token=config["matrix_token"] ) -rooms = {1196201613132574733: "!eChKdzVweNTyHctaKQ:wired.rehab"} +rooms = config["rooms"] async def matrix_init(): for room in rooms.values(): @@ -32,7 +34,7 @@ async def on_message(event: hikari.GuildMessageCreateEvent) -> None: if not event.content: return - chanid = event.channel_id + chanid = str(event.channel_id) if chanid in rooms.keys(): print(f"<{event.message.author.global_name}> {event.content}") |