Various small fixes

This commit is contained in:
Dragory 2018-07-01 04:31:24 +03:00
parent 23c78f2c9c
commit e70f1baa27
7 changed files with 395 additions and 784 deletions

1
.gitignore vendored
View file

@ -61,6 +61,7 @@ typings/
# Knub data # Knub data
/data /data
/config
# PHPStorm # PHPStorm
.idea/ .idea/

View file

@ -1,11 +1,11 @@
### Config format example ### Config format example
Config files are currently located at `data/guilds/<guildId>.yml` (and `data/guilds/global.yml` for global plugins). Config files are currently located at `config/<guildId>.yml` (and `config/global.yml` for global plugins).
```yml ```yml
levels: levels:
50: mod 50: "1234" # Mod role id
100: admin 100: "5678" # Admin role id
plugins: plugins:
mod_plugin: mod_plugin:

View file

@ -1,27 +1,31 @@
exports.up = async function(knex, Promise) { exports.up = async function(knex, Promise) {
await knex.schema.createTableIfNotExists('mod_actions', table => { if (! await knex.schema.hasTable('mod_actions')) {
table.increments('id'); await knex.schema.createTable('mod_actions', table => {
table.bigInteger('guild_id').unsigned().notNullable(); table.increments('id');
table.integer('case_number').unsigned().notNullable(); table.bigInteger('guild_id').unsigned().notNullable();
table.bigInteger('user_id').index().unsigned().notNullable(); table.integer('case_number').unsigned().notNullable();
table.string('user_name', 128).notNullable(); table.bigInteger('user_id').index().unsigned().notNullable();
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null); table.string('user_name', 128).notNullable();
table.string('mod_name', 128).nullable().defaultTo(null); table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
table.string('action_type', 16).notNullable(); table.string('mod_name', 128).nullable().defaultTo(null);
table.bigInteger('audit_log_id').unique().nullable().defaultTo(null); table.string('action_type', 16).notNullable();
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable(); table.bigInteger('audit_log_id').unique().nullable().defaultTo(null);
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable();
table.unique(['guild_id', 'case_number']); table.unique(['guild_id', 'case_number']);
}); });
}
await knex.schema.createTableIfNotExists('mod_action_notes', table => { if (! await knex.schema.hasTable('mod_action_notes')) {
table.increments('id'); await knex.schema.createTable('mod_action_notes', table => {
table.integer('mod_action_id').unsigned().notNullable().index().references('id').inTable('mod_actions').onDelete('CASCADE'); table.increments('id');
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null); table.integer('mod_action_id').unsigned().notNullable().index().references('id').inTable('mod_actions').onDelete('CASCADE');
table.string('mod_name', 128).nullable().defaultTo(null); table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
table.text('body').notNullable(); table.string('mod_name', 128).nullable().defaultTo(null);
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable(); table.text('body').notNullable();
}); table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable();
});
}
}; };
exports.down = async function(knex, Promise) { exports.down = async function(knex, Promise) {

1092
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -30,7 +30,7 @@
"eris": "^0.8.6", "eris": "^0.8.6",
"husky": "^0.14.3", "husky": "^0.14.3",
"knex": "^0.14.6", "knex": "^0.14.6",
"knub": "^9.3.0", "knub": "^9.4.3",
"lint-staged": "^7.2.0", "lint-staged": "^7.2.0",
"mariasql": "^0.2.6", "mariasql": "^0.2.6",
"moment": "^2.20.1", "moment": "^2.20.1",

View file

@ -7,13 +7,14 @@ process.on("unhandledRejection", (reason, p) => {
}); });
import { Client } from "eris"; import { Client } from "eris";
import { Knub } from "knub"; import { Knub, logger } from "knub";
import { BotControlPlugin } from "./plugins/BotControl"; import { BotControlPlugin } from "./plugins/BotControl";
import { ModActionsPlugin } from "./plugins/ModActions"; import { ModActionsPlugin } from "./plugins/ModActions";
import { UtilityPlugin } from "./plugins/Utility"; import { UtilityPlugin } from "./plugins/Utility";
import knex from "./knex"; import knex from "./knex";
// Run latest database migrations // Run latest database migrations
logger.info("Running database migrations");
knex.migrate.latest().then(() => { knex.migrate.latest().then(() => {
const client = new Client(process.env.TOKEN); const client = new Client(process.env.TOKEN);
@ -27,5 +28,6 @@ knex.migrate.latest().then(() => {
} }
}); });
logger.info("Starting the bot");
bot.run(); bot.run();
}); });

View file

@ -150,10 +150,10 @@ export class ModActionsPlugin extends Plugin {
*/ */
@d.event("guildMemberAdd") @d.event("guildMemberAdd")
async onGuildMemberAdd(member: Member) { async onGuildMemberAdd(member: Member) {
if (! this.configValue('alert_on_rejoin')) return; if (!this.configValue("alert_on_rejoin")) return;
const alertChannelId = this.configValue('alert_channel'); const alertChannelId = this.configValue("alert_channel");
if (! alertChannelId) return; if (!alertChannelId) return;
const actions = await this.modActions.getByUserId(member.id); const actions = await this.modActions.getByUserId(member.id);
@ -213,12 +213,14 @@ export class ModActionsPlugin extends Plugin {
* If the argument passed is a case id, display that case * If the argument passed is a case id, display that case
* If the argument passed is a user id, show all cases on that user * If the argument passed is a user id, show all cases on that user
*/ */
@d.command("/showcase|case|cases|usercases/", "<caseNumberOrUserId:string>") @d.command(/showcase|case|cases|usercases/, "<caseNumberOrUserId:string>")
@d.permission("view") @d.permission("view")
async showcaseCmd(msg: Message, args: any) { async showcaseCmd(msg: Message, args: any) {
if (args.caseNumberOrUserId.length >= 17) { if (args.caseNumberOrUserId.length >= 17) {
// Assume user id // Assume user id
const actions = await this.modActions.getByUserId(args.userId); const actions = await this.modActions.getByUserId(
args.caseNumberOrUserId
);
if (actions.length === 0) { if (actions.length === 0) {
msg.channel.createMessage("No cases found for the specified user!"); msg.channel.createMessage("No cases found for the specified user!");
@ -229,7 +231,9 @@ export class ModActionsPlugin extends Plugin {
} }
} else { } else {
// Assume case id // Assume case id
const action = await this.modActions.findByCaseNumber(args.caseNumber); const action = await this.modActions.findByCaseNumber(
args.caseNumberOrUserId
);
if (!action) { if (!action) {
msg.channel.createMessage("Case not found!"); msg.channel.createMessage("Case not found!");
@ -255,7 +259,7 @@ export class ModActionsPlugin extends Plugin {
if (!action) return; if (!action) return;
if (!channelId) { if (!channelId) {
channelId = this.configValue('action_log_channel'); channelId = this.configValue("action_log_channel");
} }
if (!channelId) return; if (!channelId) return;
@ -295,10 +299,12 @@ export class ModActionsPlugin extends Plugin {
if (notes.length) { if (notes.length) {
notes.forEach((note: any) => { notes.forEach((note: any) => {
const noteDate = moment(note.created_at); const noteDate = moment(note.created_at);
embed.addField( embed.fields.push({
`${note.mod_name} at ${noteDate.format("YYYY-MM-DD [at] HH:mm")}:`, name: `${note.mod_name} at ${noteDate.format(
note.body "YYYY-MM-DD [at] HH:mm"
); )}:`,
value: note.body
});
}); });
} else { } else {
embed.addField("!!! THIS CASE HAS NO NOTES !!!", "\u200B"); embed.addField("!!! THIS CASE HAS NO NOTES !!!", "\u200B");