use config.json instead of hardcoding and envvars
This commit is contained in:
parent
1cc61d85c3
commit
f73e354f6a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
config.json
|
11
config.json.sample
Normal file
11
config.json.sample
Normal file
@ -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"
|
||||
}
|
||||
}
|
14
main.py
14
main.py
@ -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}")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user