Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various bugs #4

Merged
merged 10 commits into from
Jan 2, 2024
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,19 @@ Once all these are set up:
3. `yarn dev`

### Docker
_TODO: update if needed

If you have docker installed you can simple build the image and run the install from inside the docker container

```shell
docker compose run --rm -it node-cli yarn install
```

The compose file also includes the mongo server needed to run naoko

```shell
# Start the mongo server. The node-cli container will exit on start
docker compose up -d
```

Then start Naoko using `yarn run start` outside the container.
Starting Naoko inside the Docker container will cause problems with the 3D processing commands.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: "3.9"

services:
node-cli:
image: node:18
build:
context: "."
dockerfile: "./Dockerfile"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@otiskujawa/node-canvas-webgl": "^0.2.7",
"@taku.moe/pura": "^1.0.4",
"@taku.moe/utils": "^1.0.9",
"@triptyk/tsyringe": "^4.7.1",
"tsyringe": "^4.8.0",
"axios": "^1.4.0",
"canvas": "^2.11.2",
"chalk": "^5.3.0",
Expand Down
Binary file modified src/assets/images/christmas/snowflakes/overlay2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/images/christmas/snowflakes/overlay3.png
Binary file not shown.
Binary file added src/assets/images/christmas/sprites/sprite1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/christmas/sprites/sprite3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/decorators/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { container, injectable } from "@triptyk/tsyringe";
import { container, injectable } from "tsyringe";
import AbstractPlugin from "../plugins/AbstractPlugin";

type constructor<T = AbstractPlugin> = {
Expand Down
2 changes: 1 addition & 1 deletion src/naoko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ console.clear();

import chalk from "chalk";
import Naoko from "./naoko/Naoko.js";
import { container } from "@triptyk/tsyringe";
import { container } from "tsyringe";
import { fileURLToPath } from "node:url";
import "./naoko/Database";
import { glob } from "glob";
Expand Down
2 changes: 1 addition & 1 deletion src/naoko/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
GEOXOR_LEAVE_LOG_CHANNEL_ID,
GEOXOR_VOICE_CHAT_LOG_CHANNEL_ID,
} from "../constants";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

interface ConfigType {
prefix: string;
Expand Down
2 changes: 1 addition & 1 deletion src/naoko/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Discord from "discord.js";
import mongoose from "mongoose";
import { ActionHistory, HistoryTypes, IBattleUserRewards, IUser } from "../types";
import Config from "./Config";
import { container } from "@triptyk/tsyringe";
import { container } from "tsyringe";

const config = container.resolve(Config);

Expand Down
2 changes: 1 addition & 1 deletion src/naoko/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from "chalk";
import MultiProgress from "multi-progress";
import quotes from "../assets/quotes.json" assert { type: "json" };
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import CommonUtils from "../service/CommonUtils";

/**
Expand Down
2 changes: 1 addition & 1 deletion src/naoko/Naoko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Discord, { Partials } from "discord.js";
import packageJson from "../../package.json" assert { type: "json" };
import { NAOKO_ID } from "../constants";
import { GatewayIntentBits } from "discord.js";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import { PluginManager } from "../plugins/PluginManager";
import MessageCreatePipelineManager from "../pipeline/messageCreate/MessageCreatePipelineManager";
import Logger from "./Logger";
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline/AbstractPipelineElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { Awaitable } from "discord.js";
import AbstractPipelinePayload from "./AbstractPipelinePayload";

export default abstract class AbstractPipelineElement {
abstract execute(payload: AbstractPipelinePayload): Awaitable<boolean>;
abstract execute(payload: AbstractPipelinePayload): Awaitable<true|string>;
}
2 changes: 1 addition & 1 deletion src/pipeline/messageCreate/MessageCreatePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Payload = {
dbUser?: DatabaseUser;
commandName?: string;
args?: string[];
comand?: AbstractCommand;
command?: AbstractCommand;
};

export default class MessageCreatePayload extends AbstractPipelinePayload<Payload> {}
8 changes: 4 additions & 4 deletions src/pipeline/messageCreate/MessageCreatePipelineManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import { Message } from "discord.js";
import MessageCreatePayload from "./MessageCreatePayload";
import AbstractPipelineElement from "../AbstractPipelineElement";
Expand Down Expand Up @@ -32,12 +32,12 @@ export default class MessageCreatePipelineManager {
for (const element of this.pipeline) {
try {
const canContinue = await element.execute(payload);
if (!canContinue) {
this.logger.print(`MessageCreatePipeline ended after ${element.constructor.name}`);
if (canContinue !== true) {
this.logger.print(`MessageCreatePipeline ended after "${element.constructor.name}" - Info: "${canContinue}" - Author: "${message.author.displayName}"`);
return;
}
} catch (error) {
this.logger.error(`Error in messageCreatePipeline. Element: ${element.constructor.name}, Error: "${error}"`);
this.logger.error(`Error in MessageCreatePipeline - Element: ${element.constructor.name} - Error: "${error}"`);
return;
}
}
Expand Down
20 changes: 3 additions & 17 deletions src/pipeline/messageCreate/elements/CheckForSpam.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import AbstractPipelineElement from "../../AbstractPipelineElement";
import MessageCreatePayload from "../MessageCreatePayload";
import Logger from "../../../naoko/Logger";
import SpamCheckService from "../../../service/SpamCheckService";

@singleton()
export default class CheckForSpam extends AbstractPipelineElement {
constructor(
private logger: Logger,
private spamChecker: SpamCheckService,
) {
super();
}

async execute(payload: MessageCreatePayload): Promise<boolean> {
async execute(payload: MessageCreatePayload) {
const message = payload.get("message");
const content = message.content.toLowerCase();

Expand All @@ -25,21 +23,9 @@ export default class CheckForSpam extends AbstractPipelineElement {
const spamResult = this.spamChecker.checkForSpam(content);
if (spamResult.isSpam) {
await message.delete();
this.logger.error(`SpamCheck ${spamResult.failedCheck} failed for ${message.author.username}`);
return false;
return `SpamCheck ${spamResult.failedCheck} failed for ${message.author.username}`;
}

return true;
}

isDiscordInvite(content: string) {
return (
content.includes("discord.gg") &&
!(content.includes("discord.gg/geoxor") && (content.match(/discord.gg/g) || []).length == 1)
);
}

isFreeNitro(content: string) {
return content.includes("nitro") && content.includes("http");
}
}
6 changes: 3 additions & 3 deletions src/pipeline/messageCreate/elements/EnsureGhostRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import AbstractPipelineElement from "../../AbstractPipelineElement";
import MessageCreatePayload from "../MessageCreatePayload";
import { GEOXOR_GUILD_ID, GHOSTS_ROLE_ID } from "../../../constants";
import Logger from "../../../naoko/Logger";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

@singleton()
export default class EnsureGhostRole extends AbstractPipelineElement {
constructor(private logger: Logger) {
super();
}

async execute(payload: MessageCreatePayload): Promise<boolean> {
async execute(payload: MessageCreatePayload): Promise<true> {
const message = payload.get("message");

if (message.member && message.guild?.id === GEOXOR_GUILD_ID) {
if (!message.member.roles.cache.has(GHOSTS_ROLE_ID)) {
try {
await message.member.roles.add(GHOSTS_ROLE_ID);
} catch (error) {
this.logger.error(`Couldn't give Ghosts role to the member: ${error}`);
this.logger.error(`Couldn't give Ghosts role to "${message.member.displayName}": ${error}`);
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/pipeline/messageCreate/elements/ExecuteCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DiscordAPIError, EmbedBuilder, Message, TextBasedChannel, codeBlock } from "discord.js";
import AbstractPipelineElement from "../../AbstractPipelineElement";
import MessageCreatePayload from "../MessageCreatePayload";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import { CommandExecuteResponse } from "../../../types";
import Logger from "../../../naoko/Logger";

Expand All @@ -13,9 +13,9 @@ export default class ExecuteCommand extends AbstractPipelineElement {

private typingLocks: Map<string, ReturnType<typeof setInterval>> = new Map();

async execute(payload: MessageCreatePayload): Promise<boolean> {
async execute(payload: MessageCreatePayload) {
const message = payload.get("message");
const command = payload.get("comand");
const command = payload.get("command");
const commandData = command.commandData;
const timeStart = Date.now();

Expand All @@ -24,7 +24,7 @@ export default class ExecuteCommand extends AbstractPipelineElement {
for (const perm of commandData.permissions) {
if (!message.member?.permissions.has(perm)) {
await message.reply(`You don't have the \`${perm}\` perm cunt`).catch(() => {});
return false;
return `"${message.member?.displayName}" does not have permission to execute "${commandData.name}", missing "${perm}"`;
}
}
}
Expand All @@ -39,7 +39,6 @@ export default class ExecuteCommand extends AbstractPipelineElement {
result = await command.execute(payload);
} catch (error: any) {
this.logger.error(`Command ${commandData.name} failed to execute with error: ${error}`);
console.error(error);
await message.reply({
embeds: [
{
Expand Down Expand Up @@ -75,10 +74,10 @@ export default class ExecuteCommand extends AbstractPipelineElement {
await message.reply({
embeds: [new EmbedBuilder().setColor("#ffcc4d").setDescription("⚠️ when the upload speed")],
});
return false;
return "Failed to reply to user: Discord API status code 500";
}
await message.reply(codeBlock(String(error)));
return false;
return `Failed to reply to user: ${error}`;
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/pipeline/messageCreate/elements/LoadDbUser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import AbstractPipelineElement from "../../AbstractPipelineElement";
import { User } from "../../../naoko/Database";
import MessageCreatePayload from "../MessageCreatePayload";

@singleton()
export default class LoadDbUser extends AbstractPipelineElement {
async execute(payload: MessageCreatePayload): Promise<boolean> {
async execute(payload: MessageCreatePayload): Promise<true> {
const message = payload.get("message");
if (message.member) {
payload.set("dbUser", await User.findOneOrCreate(message.member!));
Expand Down
14 changes: 7 additions & 7 deletions src/pipeline/messageCreate/elements/ParseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MessageMentions } from "discord.js";
import AbstractPipelineElement from "../../AbstractPipelineElement";
import MessageCreatePayload from "../MessageCreatePayload";
import Config from "../../../naoko/Config";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import { PluginManager } from "../../../plugins/PluginManager";

@singleton()
Expand All @@ -14,10 +14,10 @@ export default class ParseCommand extends AbstractPipelineElement {
super();
}

async execute(payload: MessageCreatePayload): Promise<boolean> {
async execute(payload: MessageCreatePayload) {
const message = payload.get("message");
if (message.content.lastIndexOf(this.config.prefix) !== 0 || message.author.bot) {
return false;
return message.author.bot ? "Message was sent by a bot" : "Message did not start with the prefix";
}

// Remove all Mentions -> Remove the Prefix -> Split the message on every whitespace
Expand All @@ -32,16 +32,16 @@ export default class ParseCommand extends AbstractPipelineElement {
"That command doesn't exist!\n" +
`There's this however \`${this.config.prefix}${closestCommand.commandData.name} ${closestCommand.commandData.usage}\``,
);
return false;
} else {
await message.reply("That command doesn't exist");
}

await message.reply("That command doesn't exist");
return false;
return `Command "${command}" not found`;
}

payload.set("args", args);
payload.set("commandName", commandName);
payload.set("comand", command);
payload.set("command", command);

return true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/pipeline/messageCreate/elements/RestrictedChannel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Awaitable } from "discord.js";
import AbstractPipelineElement from "../../AbstractPipelineElement";
import MessageCreatePayload from "../MessageCreatePayload";
import { MOD_ROLE_ID, ADMIN_ROLE_ID, GEOXOR_GENERAL_CHANNEL_ID, GEOXOR_DEV_ROLE_ID } from "../../../constants";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

@singleton()
export default class RestrictedChannel extends AbstractPipelineElement {
private readonly RESTRICTED_CHANNELS = [GEOXOR_GENERAL_CHANNEL_ID];
private readonly WHITELISTED_ROLES = [MOD_ROLE_ID, ADMIN_ROLE_ID, GEOXOR_DEV_ROLE_ID];

execute(payload: MessageCreatePayload): Awaitable<boolean> {
execute(payload: MessageCreatePayload) {
const message = payload.get("message");

// Do not allow Commands in RestrictedChannels
Expand All @@ -25,6 +24,6 @@ export default class RestrictedChannel extends AbstractPipelineElement {
) {
return true;
}
return false;
return `"${message.member.displayName}" tried to execute a command in a restricted channel`;
}
}
2 changes: 1 addition & 1 deletion src/plugins/PluginManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { container, injectAll, singleton } from "@triptyk/tsyringe";
import { container, injectAll, singleton } from "tsyringe";
import AbstractPlugin from "./AbstractPlugin";
import { Client } from "discord.js";
import AbstractCommand from "./AbstractCommand";
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/azur1s/FunFact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import plugin from "../../decorators/plugin";
import { CommandExecuteResponse } from "../../types";
import AbstractCommand, { CommandData } from "../AbstractCommand";
import CommonUtils from "../../service/CommonUtils";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

@singleton()
class FunFactCommand extends AbstractCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/Logging.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import {
ActivityType,
ChannelType,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/Plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inject, delay, singleton } from "@triptyk/tsyringe";
import { inject, delay, singleton } from "tsyringe";
import { COMMAND_CATEGORIES, NAOKO_LOGO } from "../../constants";
import plugin from "../../decorators/plugin";
import { CommandExecuteResponse } from "../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/moderation/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Naoko from "../../../naoko/Naoko";
import { User } from "../../../naoko/Database";
import AbstractCommand, { CommandData } from "../../AbstractCommand";
import Logger from "../../../naoko/Logger";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

@singleton()
export class Ban extends AbstractCommand {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/moderation/Clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import MessageCreatePayload from "../../../pipeline/messageCreate/MessageCreatePayload";
import { CommandExecuteResponse } from "../../../types";
import AbstractCommand, { CommandData } from "../../AbstractCommand";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";
import { ButtonComponent } from "discord.js";

@singleton()
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/moderation/Kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Naoko from "../../../naoko/Naoko";
import MessageCreatePayload from "../../../pipeline/messageCreate/MessageCreatePayload";
import { CommandExecuteResponse } from "../../../types";
import AbstractCommand, { CommandData } from "../../AbstractCommand";
import { singleton } from "@triptyk/tsyringe";
import { singleton } from "tsyringe";

@singleton()
export class Kick extends AbstractCommand {
Expand Down
Loading