-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee36a8e
commit 5562c08
Showing
6 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,16 @@ | ||
import { Webhook } from "@vermaysha/discord-webhook"; | ||
import { LogMessage } from "common/types"; | ||
import { stringify } from "./stringify"; | ||
|
||
const hook = new Webhook(process.env.DISCORD_WEBHOOK!); | ||
hook.setUsername("Swarm Control"); | ||
|
||
export function log(message: string) { | ||
function log(message: string) { | ||
console.error(message); | ||
hook.setContent(message); | ||
hook.send().then(); | ||
} | ||
|
||
export function logImportant(message: string) { | ||
log(`<@183249892712513536>\n${message}`); | ||
} | ||
|
||
export class LogBuilder { | ||
public constructor() {} | ||
|
||
private data = ""; | ||
|
||
public send(important: boolean) { | ||
if (!important) log(this.data); | ||
else logImportant(this.data); | ||
} | ||
|
||
public addField(header: string, content?: any): LogBuilder { | ||
if (content) { | ||
let contentStr = content.toString(); | ||
if (contentStr == "[object Object]") contentStr = JSON.stringify(content, null, 4); | ||
this.data += `### ${header}\n\`\`\`${contentStr}\`\`\`\n`; | ||
} else { | ||
this.data += `### ${header}\n`; | ||
} | ||
return this; | ||
} | ||
export function logToDiscord(logMessage: LogMessage, isFromBackend: boolean) { | ||
log(stringify(logMessage, isFromBackend)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LogMessage } from "common/types"; | ||
|
||
export function stringify(logMessage: LogMessage, isFromBackend: boolean) { | ||
let data = ""; | ||
|
||
if (logMessage.important) data += "<@183249892712513536>\n"; | ||
|
||
data += `${logMessage.userIdInsecure} | ${logMessage.transactionToken} | ${isFromBackend ? "Backend" : "Extension"}`; | ||
|
||
for (const field of logMessage.fields) { | ||
if (field.content) { | ||
let contentStr = field.content.toString(); | ||
if (contentStr == "[object Object]") contentStr = JSON.stringify(field.content, null, 4); | ||
data += `### ${field.header}\n\`\`\`${contentStr}\`\`\`\n`; | ||
} else { | ||
data += `### ${field.header}\n`; | ||
} | ||
} | ||
|
||
return data; | ||
} |