diff --git a/.gitignore b/.gitignore index 0846de3..eea6965 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ res/customKomandy.json res/customAliasy.json zaznamy.dlog zvuky/priVstupu +logs diff --git a/package-lock.json b/package-lock.json index 737c4f0..2cf88f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "denim_3001", - "version": "3001.54.3", + "version": "3001.54.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "denim_3001", - "version": "3001.54.3", + "version": "3001.54.4", "license": "ISC", "dependencies": { "@discordjs/voice": "^0.16.0", diff --git a/package.json b/package.json index 9fd9c34..c7497f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "denim_3001", - "version": "3001.54.3", + "version": "3001.54.4", "description": "Toto je velmi kvalitní bot.", "repository": { "url": "https://github.com/Histmy/Denim-Bot/" diff --git a/src/app.ts b/src/app.ts index 4d7f8b0..64085c8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -39,7 +39,7 @@ const runEvent = (name: string, args: unknown[]) => { } catch (e) { if (process.env.dieOnError) throw e; log("error pri spusteni super listeneru", e as Error); - adminLog(client, "error pri supereventu"); + adminLog(client, "error pri supereventu", e as Error); } } @@ -49,7 +49,7 @@ const runEvent = (name: string, args: unknown[]) => { } catch (e) { if (process.env.dieOnError) throw e; log("error pri spousteni eventu", e as Error); - adminLog(client, "error pri eventu"); + adminLog(client, "error pri eventu", e as Error); } }); }; diff --git a/src/modules/muzika.ts b/src/modules/muzika.ts index 6ad3c1c..fe08411 100644 --- a/src/modules/muzika.ts +++ b/src/modules/muzika.ts @@ -35,7 +35,7 @@ async function playNext(guildId: string, seek?: number) { log(e); const client: Client = module.exports.client; - adminLog(client, "error v hani muziky"); + adminLog(client, "error v hani muziky", e as Error); } } diff --git a/src/modules/zbytek.ts b/src/modules/zbytek.ts index 8099833..b810f6b 100644 --- a/src/modules/zbytek.ts +++ b/src/modules/zbytek.ts @@ -7,6 +7,7 @@ import { Modul } from "../utils/types"; import fetch from "node-fetch"; import { adminLog, formatCas, log, nabidni, sendDM } from "../utils/utils"; import { emouty } from "../utils/emotes"; +import { readFileSync } from "fs"; const zpravy = new Map>(); const dobaOmezení = 20_000; @@ -82,8 +83,7 @@ const exp: Modul = { }, lastuptime: () => { - const index = process.argv.length > 3 ? 3 : 2; - const sekundy = Number(process.argv[index]); + const sekundy = Number(process.argv[3]); if (!sekundy) return "aj forgor 💀"; return `naposled jsem jel ${formatCas(sekundy)}`; } @@ -131,9 +131,12 @@ const exp: Modul = { // Nastavení clienta client = module.exports.client; - // OG onReady + // OG onReady++ log("A jedeš!"); - if (process.argv.length >= 4) adminLog(client, "pošel jsem"); + if (process.argv[2] == "1") { + const duvod = readFileSync("logs/recent2.txt").toString(); + adminLog(client, "pošel jsem", duvod); + } // Server na navrhy createServer((req, res) => { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 4700e57..ecc4dbf 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -68,15 +68,15 @@ export const formatter = new Intl.DateTimeFormat("cs", { day: "numeric", month: export const ping = /^<@!?\d+>$/; -export function adminLog(client: Client, text: string) { +export function adminLog(client: Client, text: string, err?: string | Error) { if (process.env.adminChannel) { const adminChannel = client.channels.cache.get(process.env.adminChannel); if (adminChannel?.type == ChannelType.GuildText) - adminChannel.send(text); + adminChannel.send(!!err ? `${text}\n\`\`\`${err}\`\`\`` : text); } if (process.env.adminID) { const user = client.users.cache.get(process.env.adminID); - if (user) sendDM(user, text); + if (user) sendDM(user, !!err ? `${text}\n\`\`\`${err}\`\`\`` : text); } } diff --git a/start.sh b/start.sh index 5719a08..7e56639 100644 --- a/start.sh +++ b/start.sh @@ -1,26 +1,38 @@ declare -a casy i=0 +posel=0 while true; do cas=$(date +"%s") - if node . $posel $posledni; then + + node . $posel $posledni 2> >(tee logs/aktualni.txt) + kod=$? + posel=0 + + echo [$(date +"%d.%m. %H:%M:%S")]: vyplo sa to + + casDva=$(date +"%s") + posledni=$(($casDva - $cas)) + + cp logs/aktualni.txt logs/recent.txt + if [[ -s "logs/aktualni.txt" ]]; then + cp logs/aktualni.txt logs/$(date +"%d.%m.-%H-%M-%S-%N").txt + fi + + echo exit code byl $kod + + if (($kod == 0 )); then echo stahuju update git stash git pull npm i --omit=dev live-tsc -s src -d out -f cjs - unset posel else - kod=$? - echo [$(date +"%d.%m. %H:%M:%S")]: poslo to - echo exit code byl $kod if (($kod == 69)); then echo jenom restart else posel=1 - casy[$i]=$(date +"%s") - posledni=$(($((casy[$i])) - $cas)) - - if (($i < 3)) || (($((casy[$(($i - 3))])) < $(($((casy[$i])) - 864000)))); then + casy[$i]=$casDva + if (($i < 3)) || (($((casy[$(($i - 3))])) < $(($casDva - 86400)))); then echo Poslo to dostatecne malo, restartuju else echo Poslo to moc, seru na to