Various small fixes
This commit is contained in:
parent
23c78f2c9c
commit
e70f1baa27
7 changed files with 395 additions and 784 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -61,6 +61,7 @@ typings/
|
|||
|
||||
# Knub data
|
||||
/data
|
||||
/config
|
||||
|
||||
# PHPStorm
|
||||
.idea/
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
### 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
|
||||
levels:
|
||||
50: mod
|
||||
100: admin
|
||||
50: "1234" # Mod role id
|
||||
100: "5678" # Admin role id
|
||||
|
||||
plugins:
|
||||
mod_plugin:
|
||||
|
|
|
@ -1,27 +1,31 @@
|
|||
exports.up = async function(knex, Promise) {
|
||||
await knex.schema.createTableIfNotExists('mod_actions', table => {
|
||||
table.increments('id');
|
||||
table.bigInteger('guild_id').unsigned().notNullable();
|
||||
table.integer('case_number').unsigned().notNullable();
|
||||
table.bigInteger('user_id').index().unsigned().notNullable();
|
||||
table.string('user_name', 128).notNullable();
|
||||
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
|
||||
table.string('mod_name', 128).nullable().defaultTo(null);
|
||||
table.string('action_type', 16).notNullable();
|
||||
table.bigInteger('audit_log_id').unique().nullable().defaultTo(null);
|
||||
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable();
|
||||
if (! await knex.schema.hasTable('mod_actions')) {
|
||||
await knex.schema.createTable('mod_actions', table => {
|
||||
table.increments('id');
|
||||
table.bigInteger('guild_id').unsigned().notNullable();
|
||||
table.integer('case_number').unsigned().notNullable();
|
||||
table.bigInteger('user_id').index().unsigned().notNullable();
|
||||
table.string('user_name', 128).notNullable();
|
||||
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
|
||||
table.string('mod_name', 128).nullable().defaultTo(null);
|
||||
table.string('action_type', 16).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 => {
|
||||
table.increments('id');
|
||||
table.integer('mod_action_id').unsigned().notNullable().index().references('id').inTable('mod_actions').onDelete('CASCADE');
|
||||
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
|
||||
table.string('mod_name', 128).nullable().defaultTo(null);
|
||||
table.text('body').notNullable();
|
||||
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable();
|
||||
});
|
||||
if (! await knex.schema.hasTable('mod_action_notes')) {
|
||||
await knex.schema.createTable('mod_action_notes', table => {
|
||||
table.increments('id');
|
||||
table.integer('mod_action_id').unsigned().notNullable().index().references('id').inTable('mod_actions').onDelete('CASCADE');
|
||||
table.bigInteger('mod_id').index().unsigned().nullable().defaultTo(null);
|
||||
table.string('mod_name', 128).nullable().defaultTo(null);
|
||||
table.text('body').notNullable();
|
||||
table.dateTime('created_at').index().defaultTo(knex.raw('NOW()')).notNullable();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.down = async function(knex, Promise) {
|
||||
|
|
1092
package-lock.json
generated
1092
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -30,7 +30,7 @@
|
|||
"eris": "^0.8.6",
|
||||
"husky": "^0.14.3",
|
||||
"knex": "^0.14.6",
|
||||
"knub": "^9.3.0",
|
||||
"knub": "^9.4.3",
|
||||
"lint-staged": "^7.2.0",
|
||||
"mariasql": "^0.2.6",
|
||||
"moment": "^2.20.1",
|
||||
|
|
|
@ -7,13 +7,14 @@ process.on("unhandledRejection", (reason, p) => {
|
|||
});
|
||||
|
||||
import { Client } from "eris";
|
||||
import { Knub } from "knub";
|
||||
import { Knub, logger } from "knub";
|
||||
import { BotControlPlugin } from "./plugins/BotControl";
|
||||
import { ModActionsPlugin } from "./plugins/ModActions";
|
||||
import { UtilityPlugin } from "./plugins/Utility";
|
||||
import knex from "./knex";
|
||||
|
||||
// Run latest database migrations
|
||||
logger.info("Running database migrations");
|
||||
knex.migrate.latest().then(() => {
|
||||
const client = new Client(process.env.TOKEN);
|
||||
|
||||
|
@ -27,5 +28,6 @@ knex.migrate.latest().then(() => {
|
|||
}
|
||||
});
|
||||
|
||||
logger.info("Starting the bot");
|
||||
bot.run();
|
||||
});
|
||||
|
|
|
@ -150,10 +150,10 @@ export class ModActionsPlugin extends Plugin {
|
|||
*/
|
||||
@d.event("guildMemberAdd")
|
||||
async onGuildMemberAdd(member: Member) {
|
||||
if (! this.configValue('alert_on_rejoin')) return;
|
||||
if (!this.configValue("alert_on_rejoin")) return;
|
||||
|
||||
const alertChannelId = this.configValue('alert_channel');
|
||||
if (! alertChannelId) return;
|
||||
const alertChannelId = this.configValue("alert_channel");
|
||||
if (!alertChannelId) return;
|
||||
|
||||
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 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")
|
||||
async showcaseCmd(msg: Message, args: any) {
|
||||
if (args.caseNumberOrUserId.length >= 17) {
|
||||
// Assume user id
|
||||
const actions = await this.modActions.getByUserId(args.userId);
|
||||
const actions = await this.modActions.getByUserId(
|
||||
args.caseNumberOrUserId
|
||||
);
|
||||
|
||||
if (actions.length === 0) {
|
||||
msg.channel.createMessage("No cases found for the specified user!");
|
||||
|
@ -229,7 +231,9 @@ export class ModActionsPlugin extends Plugin {
|
|||
}
|
||||
} else {
|
||||
// Assume case id
|
||||
const action = await this.modActions.findByCaseNumber(args.caseNumber);
|
||||
const action = await this.modActions.findByCaseNumber(
|
||||
args.caseNumberOrUserId
|
||||
);
|
||||
|
||||
if (!action) {
|
||||
msg.channel.createMessage("Case not found!");
|
||||
|
@ -255,7 +259,7 @@ export class ModActionsPlugin extends Plugin {
|
|||
if (!action) return;
|
||||
|
||||
if (!channelId) {
|
||||
channelId = this.configValue('action_log_channel');
|
||||
channelId = this.configValue("action_log_channel");
|
||||
}
|
||||
|
||||
if (!channelId) return;
|
||||
|
@ -295,10 +299,12 @@ export class ModActionsPlugin extends Plugin {
|
|||
if (notes.length) {
|
||||
notes.forEach((note: any) => {
|
||||
const noteDate = moment(note.created_at);
|
||||
embed.addField(
|
||||
`${note.mod_name} at ${noteDate.format("YYYY-MM-DD [at] HH:mm")}:`,
|
||||
note.body
|
||||
);
|
||||
embed.fields.push({
|
||||
name: `${note.mod_name} at ${noteDate.format(
|
||||
"YYYY-MM-DD [at] HH:mm"
|
||||
)}:`,
|
||||
value: note.body
|
||||
});
|
||||
});
|
||||
} else {
|
||||
embed.addField("!!! THIS CASE HAS NO NOTES !!!", "\u200B");
|
||||
|
|
Loading…
Add table
Reference in a new issue