update
This commit is contained in:
parent
08d09dc147
commit
e5b2ba55d4
3 changed files with 19 additions and 6 deletions
|
@ -12,6 +12,8 @@ A simple non-puppeting bridge between Matrix and Discord written in Python.
|
||||||
|
|
||||||
* Edit `config.json`
|
* Edit `config.json`
|
||||||
|
|
||||||
|
* Normal Discord bot functionality like commands can be added to the bot via [cogs](https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html), example [here](https://gist.github.com/EvieePy/d78c061a4798ae81be9825468fe146be).
|
||||||
|
|
||||||
NOTE: [Privileged Intents](https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents) must be enabled for your Discord bot.
|
NOTE: [Privileged Intents](https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents) must be enabled for your Discord bot.
|
||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
0
cogs/.keep
Normal file
0
cogs/.keep
Normal file
23
main.py
23
main.py
|
@ -1,3 +1,4 @@
|
||||||
|
import discord.ext.commands
|
||||||
import discord
|
import discord
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
@ -12,6 +13,7 @@ def config_gen(config_file):
|
||||||
"username": "@name:matrix.org",
|
"username": "@name:matrix.org",
|
||||||
"password": "my-secret-password",
|
"password": "my-secret-password",
|
||||||
"token": "my-secret-token",
|
"token": "my-secret-token",
|
||||||
|
"discord_prefix": "my-command-prefix",
|
||||||
"bridge": {"channel_id": "room_id", }
|
"bridge": {"channel_id": "room_id", }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +145,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
self.logger.warning(f"Failed to send message {event_id}: {e}")
|
self.logger.warning(f"Failed to send message {event_id}: {e}")
|
||||||
|
|
||||||
|
|
||||||
class DiscordClient(discord.Client):
|
class DiscordClient(discord.ext.commands.Bot):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -153,13 +155,21 @@ class DiscordClient(discord.Client):
|
||||||
|
|
||||||
self.bg_task = self.loop.create_task(self.matrix_client.create(self))
|
self.bg_task = self.loop.create_task(self.matrix_client.create(self))
|
||||||
|
|
||||||
async def on_ready(self):
|
self.add_cogs()
|
||||||
print(f"Logged in as {self.user}")
|
|
||||||
|
|
||||||
|
def add_cogs(self):
|
||||||
|
for cog in os.listdir("./cogs"):
|
||||||
|
if cog.endswith(".py"):
|
||||||
|
cog = f"cogs.{cog[:-3]}"
|
||||||
|
self.load_extension(cog)
|
||||||
|
|
||||||
|
async def on_ready(self):
|
||||||
for channel in config["bridge"].keys():
|
for channel in config["bridge"].keys():
|
||||||
channel_store[channel] = self.get_channel(int(channel))
|
channel_store[channel] = self.get_channel(int(channel))
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
|
await self.process_commands(message)
|
||||||
|
|
||||||
if message.author.bot or str(message.channel.id) not in \
|
if message.author.bot or str(message.channel.id) not in \
|
||||||
config["bridge"].keys():
|
config["bridge"].keys():
|
||||||
return
|
return
|
||||||
|
@ -372,13 +382,14 @@ class Callbacks(object):
|
||||||
def main():
|
def main():
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
allowed_mentions = discord.AllowedMentions(everyone=False, roles=False)
|
||||||
|
command_prefix = config["discord_prefix"]
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
|
|
||||||
allowed_mentions = discord.AllowedMentions(everyone=False, roles=False)
|
|
||||||
|
|
||||||
DiscordClient(
|
DiscordClient(
|
||||||
intents=intents, allowed_mentions=allowed_mentions
|
allowed_mentions=allowed_mentions,
|
||||||
|
command_prefix=command_prefix, intents=intents
|
||||||
).run(config["token"])
|
).run(config["token"])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue