summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkipper <[email protected]>2025-02-03 11:19:02 +0000
committerSkipper <[email protected]>2025-02-03 11:19:02 +0000
commit0b53c6b864735dbc0ebf675eaa478f1275ae0fa9 (patch)
tree6303cae4a46cc230bfb2c033e3a0862592155794
parentf2189b417b543bea5add24f5a324b328fa8dbfac (diff)
Added discord client
Begun implementation of the discord client. Will exclude the config.py after this - so any changes made during testing (including API keys) will not be copied through - un-ignore if adding new config values.
-rw-r--r--config.py9
-rw-r--r--lib/DiscordClient.py42
-rw-r--r--requirements.txt1
-rw-r--r--testDiscord.py7
4 files changed, 59 insertions, 0 deletions
diff --git a/config.py b/config.py
index ab3b14c..c8cce89 100644
--- a/config.py
+++ b/config.py
@@ -44,3 +44,12 @@ SMOKE_PLANE = True
# Planes smoking minimum life
SMOKE_LIFE = 5
+
+
+#Discord chat integration
+#Make sure to enable read message privilege for the bot.
+
+DISCORD_TOKEN = "YourDiscordBotTOKEN"
+
+# Channel ID for the chat
+CHANNEL_ID = 0 # Channel ID, as an integer
diff --git a/lib/DiscordClient.py b/lib/DiscordClient.py
new file mode 100644
index 0000000..431a1d1
--- /dev/null
+++ b/lib/DiscordClient.py
@@ -0,0 +1,42 @@
+import discord
+import asyncio
+from lib.PacketManager.packets.FSNETCMD_TEXTMESSAGE import FSNETCMD_TEXTMESSAGE
+from config import DISCORD_TOKEN, CHANNEL_ID
+
+class DiscordClient(discord.Client):
+
+ def __init__(self, intents, parent=None):
+ super().__init__(intents=intents)
+ self.parent = parent
+
+ async def on_ready(self):
+ await self.check_messages()
+
+ async def on_message(self, message):
+ if message.channel.id == CHANNEL_ID:
+ if message.author.id == self.user.id:
+ return
+ author = message.author.name
+ content = message.content
+ messageToSendToClients = FSNETCMD_TEXTMESSAGE.encode(author, content)
+ if self.parent:
+ self.parent.send_to_all(messageToSendToClients)
+
+ async def send_message(self, message):
+ channel = self.get_channel(CHANNEL_ID)
+ if channel:
+ message = await channel.send(message)
+
+ async def check_messages(self):
+ while True:
+ if self.parent:
+ for message in self.parent.chatLog:
+ await self.send_message(message)
+ self.parent.chatLog.remove(message)
+ await asyncio.sleep(1)
+
+ def start_bot(self):
+ loop = asyncio.get_event_loop()
+ loop.create_task(self.check_messages())
+ self.run(DISCORD_TOKEN)
+
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..844f49a
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+discord.py
diff --git a/testDiscord.py b/testDiscord.py
new file mode 100644
index 0000000..ca084e8
--- /dev/null
+++ b/testDiscord.py
@@ -0,0 +1,7 @@
+from lib.DiscordClient import DiscordClient
+import discord
+
+intents = discord.Intents.default()
+intents.message_content = True
+client = DiscordClient(intents)
+client.start_bot()