mirror of
https://github.com/keanuplayz/TravBot-v3.git
synced 2024-08-15 02:33:12 +00:00
Added gulp auto-clean instruction
This commit is contained in:
parent
077164ed23
commit
9d4610249d
9 changed files with 5316 additions and 13 deletions
|
@ -17,6 +17,8 @@ This is a brief overview that'll describe where and how to add new features to T
|
|||
|
||||
*Note: Make sure to avoid using `npm run build`! This will remove all your dev dependencies (in order to reduce space used). Instead, use `npm run once` to compile and build in non-dev mode.*
|
||||
|
||||
*Note: `npm run dev` will automatically delete any leftover files, preventing errors that might occur because of it. However, sometimes you'd like to test stuff without that build step. To do that, run `npm run dev-fast`. You'll then have to manually delete the `dist` folder to clear any old files.*
|
||||
|
||||
*Note: If you update one of the APIs or utility functions, make sure to update the [documentation](Documentation.md).*
|
||||
|
||||
# Adding a new command
|
||||
|
@ -80,6 +82,4 @@ All calls to `console.error`, `console.warn`, `console.log`, and `console.debug`
|
|||
- `Info`: Used for general events such as joining/leaving guilds for example, but try not to go overboard on logging everything.
|
||||
- `Verbose`: This is used as a sort of separator for logging potentially error-prone events so that if an error occurs, you can find the context that error originated from.
|
||||
- In order to make reading the logs easier, context should be provided with each call. For example, if a call is being made from the storage module, you'd do something like `console.log("[storage]", "the message")`.
|
||||
- `[name]` indicates a module
|
||||
- `:name:` indicates a command
|
||||
- If a message is clear enough as to what the context was though, it's probably unnecessary to include this prefix. However, you should definitely attach context prefixes to error objects, who knows where those might originate.
|
||||
|
|
3
gulpfile.js
Normal file
3
gulpfile.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const gulp = require("gulp");
|
||||
const del = require("del");
|
||||
gulp.task("default", () => del(["dist/**/*"]));
|
5289
package-lock.json
generated
5289
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -4,10 +4,12 @@
|
|||
"description": "TravBot Discord bot.",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.prod.json && npm prune --production",
|
||||
"build": "gulp && tsc --project tsconfig.prod.json && npm prune --production",
|
||||
"start": "node .",
|
||||
"once": "tsc && npm start",
|
||||
"dev": "tsc-watch --onSuccess \"node . dev\"",
|
||||
"dev": "tsc-watch --onSuccess \"npm run dev-instance\"",
|
||||
"dev-fast": "tsc-watch --onSuccess \"node . dev\"",
|
||||
"dev-instance": "gulp && tsc && node . dev",
|
||||
"test": "jest",
|
||||
"format": "prettier --write **/*",
|
||||
"postinstall": "husky install"
|
||||
|
@ -38,6 +40,8 @@
|
|||
"@types/ms": "^0.7.31",
|
||||
"@types/node": "^14.14.20",
|
||||
"@types/ws": "^7.4.0",
|
||||
"del": "^6.0.0",
|
||||
"gulp": "^4.0.2",
|
||||
"husky": "^5.0.6",
|
||||
"jest": "^26.6.3",
|
||||
"prettier": "2.1.2",
|
||||
|
|
|
@ -3,6 +3,7 @@ import {clean} from "../../lib";
|
|||
import {Config, Storage} from "../../structures";
|
||||
import {Permissions, TextChannel, User, Role, Channel} from "discord.js";
|
||||
import {logs} from "../../modules/globals";
|
||||
import {inspect} from "util";
|
||||
|
||||
function getLogBuffer(type: string) {
|
||||
return {
|
||||
|
@ -332,11 +333,11 @@ export default new NamedCommand({
|
|||
// You have to bring everything into scope to use them. AFAIK, there isn't a more maintainable way to do this, but at least TS will let you know if anything gets removed.
|
||||
async run({send, message, channel, guild, author, member, client, args, combined}) {
|
||||
try {
|
||||
let evaled = eval(combined);
|
||||
let evaled: unknown = eval(combined);
|
||||
// If promises like message.channel.send() are invoked, await them so unnecessary error reports don't leak into the command handler.
|
||||
// Also, it's more useful to see the value rather than Promise { <pending> }.
|
||||
if (evaled instanceof Promise) evaled = await evaled;
|
||||
if (typeof evaled !== "string") evaled = require("util").inspect(evaled);
|
||||
if (typeof evaled !== "string") evaled = inspect(evaled);
|
||||
// Also await this send call so that if the message is empty, it doesn't leak into the command handler.
|
||||
await send(clean(evaled), {code: "js", split: true});
|
||||
} catch (err) {
|
||||
|
|
|
@ -82,7 +82,7 @@ export function searchNearestEmote(query: string, additionalEmotes?: GuildEmoji[
|
|||
if (directMatchEmote) return directMatchEmote.toString();
|
||||
}
|
||||
|
||||
// Find all similar emote candidates within certian threshold and select Nth top one according to the selector.
|
||||
// Find all similar emote candidates within certain threshold and select Nth top one according to the selector.
|
||||
const similarEmotes = searchSimilarEmotes(query);
|
||||
if (similarEmotes.length > 0) {
|
||||
selector = Math.min(selector, similarEmotes.length - 1);
|
||||
|
|
|
@ -114,7 +114,7 @@ export function select<T>(value: any, fallback: T, type: Function, isArray = fal
|
|||
}
|
||||
}
|
||||
|
||||
export function clean(text: any) {
|
||||
export function clean(text: unknown) {
|
||||
if (typeof text === "string")
|
||||
return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
|
||||
else return text;
|
||||
|
|
|
@ -10,14 +10,15 @@ process.on("unhandledRejection", (reason: any) => {
|
|||
const isLavalinkError = reason?.code === "ECONNREFUSED";
|
||||
const isDiscordError = reason?.name === "DiscordAPIError";
|
||||
|
||||
if (!isLavalinkError)
|
||||
if (!isDiscordError || lastEvent !== "message")
|
||||
// If it's a DiscordAPIError on a message event, I'll make the assumption that it comes from the command handler.
|
||||
if (!isLavalinkError && (!isDiscordError || lastEvent !== "message"))
|
||||
console.error(`@${lastEvent}\n${reason.stack}`);
|
||||
});
|
||||
|
||||
// This will dynamically attach all known events instead of doing it manually.
|
||||
// As such, it needs to be placed after all other events are attached or the tracking won't be done properly.
|
||||
for (const event of client.eventNames()) {
|
||||
client.on(event, () => (lastEvent = event.toString()));
|
||||
client.on(event, () => {
|
||||
lastEvent = event.toString();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import {client} from "../index";
|
||||
|
||||
// Potentially port CE's intercept module to here?
|
||||
// - ` ${text} `.test(/[ \.,\?!]hon[ \.,\?!]/)
|
||||
// - "oil" will remain the same though, it's better that way (anything even remotely "oil"-related calls the image)
|
||||
// - Also uwu and owo penalties
|
||||
|
||||
client.on("message", (message) => {
|
||||
if (message.content.toLowerCase().includes("remember to drink water")) {
|
||||
message.react("🚱");
|
||||
|
|
Loading…
Reference in a new issue