switch to typescript

This commit is contained in:
Matthieu Jolimaitre 2024-11-24 17:07:26 +01:00
parent 0c313f9f48
commit cdec693d39
8 changed files with 104 additions and 32 deletions

2
.gitignore vendored
View file

@ -1,3 +1,3 @@
/token
/data/token
/repo
/venv

View file

@ -1,10 +0,0 @@
{
"token": "discord-account-token",
"status_sequence": [
"online"
],
"clear_enabled": false,
"clear_interval": 0,
"// 12 * 60 * 60 = 43200": "",
"speed_rotator": 43200
}

View file

@ -1 +0,0 @@
emoji2:1243572228868673566

20
run
View file

@ -1,20 +0,0 @@
#!/usr/bin/bash
set -e
cd "$(dirname "$(realpath "$0")")"
[ -d repo ] || git clone https://github.com/RELIHR/Discord-Status-Changer.git repo
[ -d venv ] || python3 -m venv venv
[ -f token ] || echo "token goes here" > token
. ./venv/bin/activate
pip install requests colorama
cp emotes.txt repo/emojis.txt
cp status.txt repo/text.txt
cp config.json repo/config.json
sed -i "s/discord-account-token/$(cat token)/g" repo/config.json
cd repo
python3 main.py

20
run-loop Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/bash
set -e
cd "$(dirname "$(realpath "$0")")"
interval="6h"
while true
do
until ping -c 1 '0.0.0.0' > /dev/null
do echo "[run-loop] waiting for internet connection."
done
./run-rotate
echo "[run-loop] Waiting $interval from"
echo " $(date)"
sleep "$interval"
done

15
run-rotate Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/bash
set -e
cd "$(dirname "$(realpath "$0")")"
[ -f data/token ] || ( echo "[run-rotate] Must place a discord token in '$PWD/data/token'" && exit 1 )
token="$( cat data/token)"
status="$(cat data/status.txt | shuf -n 1)"
emote='feur:1243572228868673566'
echo "[run-rotate] Setting status to '$status'"
./src/discord-status-set.ts "$token" "$status" --emote "$emote"

68
src/discord-status-set.ts Executable file
View file

@ -0,0 +1,68 @@
#!/usr/bin/env -S deno run --allow-net=discord.com --allow-import=deno.land
import { Command } from "https://deno.land/x/cliffy@v1.0.0-rc.4/command/mod.ts";
async function main() {
const args = await parse_args();
const r = await set_status(args.token, args.status, args.emote);
if (!r.ok) {
console.error("[discord-status-set.ts] API Response failure", r.status);
console.error(await r.text());
Deno.exit(1);
}
}
async function parse_args() {
const { args, options } = await new Command()
.name("discord-status-set")
.description("Set the status of your discord profile.")
.arguments("<token> <status>")
.option(
"-e, --emote <emote>",
"Emote to set the status to (format is '<name>:<id>').",
)
.parse();
const [token, status] = args;
let emote = undefined as Emote | undefined;
if (options.emote) {
const [name, id] = options.emote.split(":");
if (id === undefined) {
throw new Error(
`Incorrect emote format: '${options.emote}' instead of '<name>:<id>'`,
);
}
emote = { name, id };
}
return { token, status, emote };
}
async function set_status(
token: string,
status: string,
emote: Emote | undefined = undefined,
) {
return await fetch("https://discord.com/api/v10/users/@me/settings", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"authorization": token,
},
body: JSON.stringify({
"custom_status": {
"text": status,
...emote
? {
"emoji_name": emote.name,
"emoji_id": emote.id,
}
: {},
},
"activities": [],
"status": "online",
}),
});
}
type Emote = { name: string; id: string };
if (import.meta.main) await main();