Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DemonWayne committed May 30, 2022
1 parent 01c8fe1 commit 65a42b5
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 55 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@sapphire",
"rules": {
"@typescript-eslint/no-base-to-string": 0,
"@typescript-eslint/no-throw-literal": 0
},
"parserOptions": {
"warnOnUnsupportedTypeScriptVersion": false
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"mongoose": "^6.3.2"
},
"devDependencies": {
"@sapphire/eslint-config": "^4.3.5",
"@sapphire/prettier-config": "^1.4.3",
"@sapphire/ts-config": "^3.3.4",
"@types/node": "^17.0.33",
Expand Down
2 changes: 1 addition & 1 deletion src/arguments/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class duration extends Argument {
if (!isNaN(date.getTime()) && date.getTime() > Date.now()) return this.ok(date);
return this.error({ parameter, identifier: 'StringNotDuration', context });
}
};
}

declare module '@sapphire/framework' {
interface ArgType {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Developers/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApplyOptions } from '@sapphire/decorators';
import { Args, Command } from '@sapphire/framework';
import { sendLocalized } from '@sapphire/plugin-i18next';
import type { Message } from 'discord.js';
const { sendArgsError } = require('#utils/index');
import { sendArgsError } from '#utils/index';

@ApplyOptions<Command.Options>({ description: 'Test command', preconditions: ['devOnly'] })
export class UserCommand extends Command {
Expand All @@ -11,6 +11,6 @@ export class UserCommand extends Command {
const arg = await args.pick('string').catch(() => sendArgsError(message, Arguments));
if (!arg) return;

sendLocalized(message, { keys: 'test:success', formatOptions: { arg: arg } });
await sendLocalized(message, { keys: 'test:success', formatOptions: { arg } });
}
}
8 changes: 4 additions & 4 deletions src/commands/General/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EmbedFieldData, Message, MessageEmbed } from 'discord.js';

@ApplyOptions<Command.Options>({ description: 'Help command' })
export class UserCommand extends Command {
public messageRun(message: Message) {
public async messageRun(message: Message) {
const commandsWithoutSort = this.container.stores.get('commands');

const DEVS = process.env.DEVS;
const { DEVS } = process.env;
const isDev = DEVS!.includes(message.author.id);
const fields: Array<EmbedFieldData> = [];
commandsWithoutSort.forEach(cmd => {
Expand All @@ -18,11 +18,11 @@ export class UserCommand extends Command {
name: `${cmd.category}`,
value: `${cmd.enabled ? '🟢' : '🔴'} ${cmd.name} - ${cmd.description}`,
});
} else {
} else if (field) {
field.value += `\n${cmd.enabled ? '🟢' : '🔴'} ${cmd.name} - ${cmd.description}`;
}
});

message.reply({ embeds: [new MessageEmbed().setTitle('Help').setFields(fields)] });
await message.reply({ embeds: [new MessageEmbed().setTitle('Help').setFields(fields)] });
}
}
12 changes: 6 additions & 6 deletions src/commands/Moderation/mute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ApplyOptions } from '@sapphire/decorators';
import { Args, Command } from '@sapphire/framework';
import { sendLocalized } from '@sapphire/plugin-i18next';
import type { Message } from 'discord.js';
const infractions = require('#models/infractions');
const { sendArgsError, resolveDuration } = require('#utils/index');
import infractions from '#models/infractions';
import { sendArgsError, resolveDuration } from '#utils/index';

@ApplyOptions<Command.Options>({ description: 'Mute command', preconditions: ['GuildOnly', 'modOnly'] })
export class UserCommand extends Command {
Expand All @@ -23,16 +23,16 @@ export class UserCommand extends Command {
const duration = resolveDuration(durationString);

if (!member.moderatable) {
sendLocalized(message, {
await sendLocalized(message, {
keys: 'mute:erorr',
});
return;
}

if (member.isCommunicationDisabled()) {
sendLocalized(message, {
await sendLocalized(message, {
keys: 'mute:erorr_muted',
formatOptions: { timestamp: `<t:${Math.ceil(member.communicationDisabledUntil / 1000)}:F>` },
formatOptions: { timestamp: `<t:${Math.ceil(member.communicationDisabledUntilTimestamp / 1000)}:F>` },
});
return;
}
Expand All @@ -47,7 +47,7 @@ export class UserCommand extends Command {
reason: reason.toString(),
});

sendLocalized(message, {
await sendLocalized(message, {
keys: 'mute:success',
formatOptions: {
user: member.toString(),
Expand Down
6 changes: 3 additions & 3 deletions src/commands/Moderation/mutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Args, Command } from '@sapphire/framework';
import { fetch, FetchResultTypes, FetchMethods } from '@sapphire/fetch';
import { resolveKey } from '@sapphire/plugin-i18next';
import { Message, MessageEmbed } from 'discord.js';
const { sendArgsError } = require('#utils/index');
import { sendArgsError } from '#utils/index';

@ApplyOptions<Command.Options>({ description: 'Mutes list', preconditions: ['GuildOnly', 'modOnly'] })
export class UserCommand extends Command {
Expand All @@ -13,7 +13,7 @@ export class UserCommand extends Command {
const member = await args.pick('member').catch(() => sendArgsError(message, Arguments));
if (!member) return;

const { mutes } = await fetch(
const { mutes }: any = await fetch(
'http://localhost:4000/mutes',
{
method: FetchMethods.Post,
Expand All @@ -28,7 +28,7 @@ export class UserCommand extends Command {
FetchResultTypes.JSON,
);

message.reply({
await message.reply({
embeds: [
new MessageEmbed()
.setTitle(`${await resolveKey(message, 'mutes:title')} ${member.displayName || member.user.username}`)
Expand Down
14 changes: 6 additions & 8 deletions src/commands/Moderation/unmute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ApplyOptions } from '@sapphire/decorators';
import { Args, Command } from '@sapphire/framework';
import { sendLocalized } from '@sapphire/plugin-i18next';
import type { Message } from 'discord.js';
const { sendArgsError } = require('#utils/index');
const infractions = require('#models/infractions');
import { sendArgsError } from '#utils/index';
import infractions from '#models/infractions';

@ApplyOptions<Command.Options>({ description: 'Unmute command', preconditions: ['GuildOnly', 'modOnly'] })
export class UserCommand extends Command {
Expand All @@ -13,22 +13,20 @@ export class UserCommand extends Command {
if (!member) return;

if (!member.isCommunicationDisabled()) {
sendLocalized(message, {
keys: 'unmute:erorr_nomute',
});
await sendLocalized(message, 'unmute:erorr_nomute');
return;
}

const mute = await infractions.find({
const mutes: Array<object> = await infractions.find({
guildId: message.guild!.id,
user: member.id,
});

await infractions.deleteOne(mute.pop());
await infractions.deleteOne(mutes.pop());

member.timeout(null, `Unmuted by ${message.author.tag}`);

sendLocalized(message, {
await sendLocalized(message, {
keys: 'unmute:success',
formatOptions: {
user: member.toString(),
Expand Down
24 changes: 10 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import '#lib/setup';
const { AdvancedClient } = require('#lib/AdvancedClient');
import { AdvancedClient } from '#lib/AdvancedClient';

const client = new AdvancedClient();

const main = async () => {
try {
client.logger.info('Logging in');
await client.login(process.env.DISCORD_TOKEN);
client.logger.info('logged in');
} catch (error) {
client.logger.fatal(error);
client.destroy();
process.exit(1);
}
};

main();
(async () => {
client.logger.info('Logging in');
await client.login().catch();
client.logger.info('logged in');
})().catch(error => {
client.logger.fatal(error);
client.destroy();
process.exit(1);
});
6 changes: 3 additions & 3 deletions src/lib/AdvancedClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SapphireClient } from '@sapphire/framework';
import type { InternationalizationContext } from '@sapphire/plugin-i18next';
import { connect } from 'mongoose';
import guild from '../models/guild';
import guild from '#models/guild';

export class AdvancedClient extends SapphireClient {
public constructor() {
Expand Down Expand Up @@ -41,8 +41,8 @@ export class AdvancedClient extends SapphireClient {
});
}

public async login(token?: string) {
public login() {
this.connectDatabase();
return await super.login(token);
return super.login();
}
}
2 changes: 1 addition & 1 deletion src/listeners/commands/commandDenied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class CommandDeniedListener extends Listener<typeof Events.CommandDenied>
}
if (error.identifier === 'preconditionCooldown') {
const context = error.context as any;
const timeLeft = parseInt(context.remaining) / 1000;
const timeLeft = parseInt(context.remaining, 10) / 1000;
await sendLocalized(message, {
keys: 'preconditions:cooldown',
formatOptions: {
Expand Down
4 changes: 2 additions & 2 deletions src/listeners/guildCreate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Listener } from '@sapphire/framework';
import type { Guild } from 'discord.js';
const Guilds = require('../models/guild');
import Guilds from '#models/guild';

export class GulidCreateListener extends Listener {
public async run(guild: Guild) {
const guildDB = await Guilds.findOsne({ guildId: guild.id });
const guildDB = await Guilds.findOne({ guildId: guild.id });
if (guild && !guildDB) {
await Guilds.create({ guildId: guild.id });
this.container.logger.info(`${guild.name} added to DataBase`);
Expand Down
2 changes: 1 addition & 1 deletion src/listeners/guildDelete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Listener } from '@sapphire/framework';
import type { Guild } from 'discord.js';
const Guilds = require('../models/guild');
import Guilds from '#models/guild';

export class GulidDeleteListener extends Listener {
public async run(guild: Guild) {
Expand Down
4 changes: 2 additions & 2 deletions src/preconditions/modOnly.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Precondition } from '@sapphire/framework';
import { resolveKey } from '@sapphire/plugin-i18next';
import type { Message } from 'discord.js';
const Guild = require('../models/guild');
import Guild from '#models/guild';

export class modOnly extends Precondition {
public async run(message: Message) {
const guild = await Guild.findOne({ guildId: message.guildId });
return message.member!.permissions.has(8n) || guild.modRoles.includes(message.author.id)
return message.member!.permissions.has(8n) || guild!.modRoles.includes(message.author.id)
? this.ok()
: this.error({ message: await resolveKey(message, 'preconditions:mod') });
}
Expand Down
6 changes: 3 additions & 3 deletions src/routes/mutes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApplyOptions } from '@sapphire/decorators';
import { ApiRequest, ApiResponse, methods, Route } from '@sapphire/plugin-api';
const infractions = require('#models/infractions');
import infractions from '#models/infractions';

@ApplyOptions<Route.Options>({ route: 'mutes' })
export class MutesRoute extends Route {
Expand All @@ -19,9 +19,9 @@ export class MutesRoute extends Route {
}

public async [methods.POST](_request: ApiRequest, response: ApiResponse) {
const body: any = _request.body;
const { body }: any = _request;
const { guild, user } = body;
const mutes = await infractions.find({ guildId: guild, type: 0, user: user });
const mutes = await infractions.find({ guildId: guild, type: 0, user });
response.json({
mutes: mutes.map(
(mute: any) => `${mute.reason} | ${mute.createdAt.toLocaleString()} | ${mute.expiresAt.toLocaleString()}`,
Expand Down
3 changes: 2 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"#models/*": ["models/*"],
"#root/*": ["*"]
},
"composite": true
"composite": true,
"moduleResolution": "Node",
},
"include": [".", "./**/*.json"],
"exclude": ["./tsconfig.json"]
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MessageEmbed } from 'discord.js';
import type { Message } from 'discord.js';
import { resolveKey } from '@sapphire/plugin-i18next';

exports.sendArgsError = async (message: Message, Args: any) => {
export const sendArgsError = async (message: Message, Args: any) => {
const args = [];
for (const arg of Args) {
if (arg && arg.name) args.push(arg);
Expand All @@ -20,7 +20,7 @@ exports.sendArgsError = async (message: Message, Args: any) => {
lastString.push(`**__\`${a.name}\`__:** \`${await resolveKey(message, `args:${a.type}`)}\``);
}

channel.send({
void channel.send({
embeds: [
new MessageEmbed()
.setColor('RED')
Expand All @@ -30,6 +30,6 @@ exports.sendArgsError = async (message: Message, Args: any) => {
});
};

exports.resolveDuration = (duration: String) =>
parseInt(duration.slice(0, -1)) *
export const resolveDuration = (duration: string) =>
parseInt(duration.slice(0, -1), 10) *
{ ms: 1, s: 1000, m: 1000 * 60, h: 1000 * 60 * 60, d: 1000 * 60 * 60 * 24 }[duration[duration.length - 1]]!;
7 changes: 7 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@sapphire/ts-config",
"compilerOptions": {
"target": "ESNext",
"removeComments": true
}
}
8 changes: 8 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true
},
"include": ["src"]
}

0 comments on commit 65a42b5

Please sign in to comment.