From c3591f5c5161667af1700a5152ecdd0d150df288 Mon Sep 17 00:00:00 2001 From: Guams Date: Wed, 5 Mar 2025 22:40:39 +0100 Subject: [PATCH] initial commit --- .gitignore | 10 +++++++++ README.md | 3 +++ enums.py | 16 +++++++++++++ main.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 enums.py create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e0ec9d --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +configuration.json +.idea/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..69d5c71 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Gambling BOT + +Readme in progress... \ No newline at end of file diff --git a/enums.py b/enums.py new file mode 100644 index 0000000..6e46ead --- /dev/null +++ b/enums.py @@ -0,0 +1,16 @@ +from enum import Enum + + +class OpCode(int, Enum): + DISPATCH = 0 + HEARTBEAT = 1 + IDENTIFY = 2 + PRESENCE_UPDATE = 3 + VOICE_STATE_UPDATE = 4 + RESUME = 6 + RECONNECT = 7 + REQUEST_GUILD_MEMBERS = 8 + INVALID_SESSION = 9 + HELLO = 10 + HEARTBEAT_ACK = 11 + REQUEST_SOUNDBOARD_SOUNDS = 31 diff --git a/main.py b/main.py new file mode 100644 index 0000000..cf3be6a --- /dev/null +++ b/main.py @@ -0,0 +1,66 @@ +import asyncio +import requests +import websockets +import json +from enums import OpCode + +with open('configuration.json', 'r') as file: + CONFIG = json.load(file) + +GATEWAY_URL = "wss://gateway.discord.gg/?v=10&encoding=json" +API_URL = "https://discord.com/api/v10" +TOKEN = CONFIG["TOKEN"] + + +async def send_message(channel_id: int, message: str): + body = { + "content": message, + "tts": False, + "embeds": [{ + "title": "Hello, Embed!", + "description": "This is an embedded message." + }] + } + + res = await requests.post(url=f"{API_URL}/channels/{channel_id}/messages", json=body) + print(res) + + +async def identify(websocket): + payload = { + "op": OpCode.IDENTIFY, + "d": { + "token": TOKEN, + "properties": { + "os": "windows", + "browser": "gambling", + "device": "gambling" + }, + "intents": 513, + } + } + await websocket.send(json.dumps(payload)) + + +async def heartbeat(websocket, interval): + while True: + await asyncio.sleep(interval / 1000) + await websocket.send(json.dumps({"op": OpCode.HEARTBEAT, "d": None})) + + +async def connect(): + async with websockets.connect(GATEWAY_URL) as websocket: + response = json.loads(await websocket.recv()) + heartbeat_interval = response["d"]["heartbeat_interval"] + + asyncio.create_task(heartbeat(websocket, heartbeat_interval)) + + await identify(websocket) + + while True: + message = json.loads(await websocket.recv()) + print("Received: ", message) + + +asyncio.run(connect()) +# send_message(channel_id=840107060901052426, message="Salut")