mirror of
https://github.com/wlinator/keep-online-docker.git
synced 2024-10-02 08:59:07 +00:00
keeponline init
This commit is contained in:
parent
398af44100
commit
55e1c57b49
6 changed files with 112 additions and 0 deletions
8
.env.example
Normal file
8
.env.example
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# your discord token
|
||||||
|
TOKEN=
|
||||||
|
|
||||||
|
# online, dnd or idle
|
||||||
|
MODE_STATUS=online
|
||||||
|
|
||||||
|
# status message
|
||||||
|
CUSTOM_STATUS=Doing something exciting!
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
venv/
|
||||||
|
.idea/
|
||||||
|
__pycache__/
|
||||||
|
|
||||||
|
.env
|
||||||
|
*.log
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
FROM python:3.11
|
||||||
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD [ "python", "./keeponline.py" ]
|
8
docker-compose.yml
Normal file
8
docker-compose.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
services:
|
||||||
|
core:
|
||||||
|
build: .
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
ONLINE_TOKEN: ${TOKEN}
|
||||||
|
ONLINE_MODE_STATUS: ${MODE_STATUS}
|
||||||
|
ONLINE_CUSTOM_STATUS: ${CUSTOM_STATUS}
|
77
keeponline.py
Normal file
77
keeponline.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import requests
|
||||||
|
import websocket
|
||||||
|
|
||||||
|
usertoken = os.environ.get("ONLINE_TOKEN")
|
||||||
|
status = os.environ.get("ONLINE_MODE_STATUS")
|
||||||
|
custom_status = os.environ.get("ONLINE_CUSTOM_STATUS")
|
||||||
|
|
||||||
|
headers = {"Authorization": usertoken, "Content-Type": "application/json"}
|
||||||
|
|
||||||
|
validate = requests.get('https://discordapp.com/api/v9/users/@me', headers=headers)
|
||||||
|
if validate.status_code != 200:
|
||||||
|
print("[ERROR] Your token might be invalid. Please check it again.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
userinfo = requests.get('https://discordapp.com/api/v9/users/@me', headers=headers).json()
|
||||||
|
username = userinfo["username"]
|
||||||
|
discriminator = userinfo["discriminator"]
|
||||||
|
userid = userinfo["id"]
|
||||||
|
|
||||||
|
def onliner(token, status):
|
||||||
|
ws = websocket.WebSocket()
|
||||||
|
ws.connect("wss://gateway.discord.gg/?v=9&encoding=json")
|
||||||
|
start = json.loads(ws.recv())
|
||||||
|
heartbeat = start["d"]["heartbeat_interval"]
|
||||||
|
auth = {
|
||||||
|
"op": 2,
|
||||||
|
"d": {
|
||||||
|
"token": token,
|
||||||
|
"properties": {
|
||||||
|
"$os": "Windows 10",
|
||||||
|
"$browser": "Google Chrome",
|
||||||
|
"$device": "Windows",
|
||||||
|
},
|
||||||
|
"presence": {"status": status, "afk": False},
|
||||||
|
},
|
||||||
|
"s": None,
|
||||||
|
"t": None,
|
||||||
|
}
|
||||||
|
ws.send(json.dumps(auth))
|
||||||
|
cstatus = {
|
||||||
|
"op": 3,
|
||||||
|
"d": {
|
||||||
|
"since": 0,
|
||||||
|
"activities": [
|
||||||
|
{
|
||||||
|
"type": 4,
|
||||||
|
"state": custom_status,
|
||||||
|
"name": "Custom Status",
|
||||||
|
"id": "custom",
|
||||||
|
#Uncomment the below lines if you want an emoji in the status
|
||||||
|
#"emoji": {
|
||||||
|
#"name": "emoji name",
|
||||||
|
#"id": "emoji id",
|
||||||
|
#"animated": False,
|
||||||
|
#},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"status": status,
|
||||||
|
"afk": False,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ws.send(json.dumps(cstatus))
|
||||||
|
online = {"op": 1, "d": "None"}
|
||||||
|
time.sleep(heartbeat / 1000)
|
||||||
|
ws.send(json.dumps(online))
|
||||||
|
|
||||||
|
def run_onliner():
|
||||||
|
print(f"Logged in as {username}#{discriminator} ({userid}).")
|
||||||
|
while True:
|
||||||
|
onliner(usertoken, status)
|
||||||
|
time.sleep(50)
|
||||||
|
|
||||||
|
run_onliner()
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
requests
|
||||||
|
websocket-client
|
Loading…
Reference in a new issue