fix merge conflict

merge-requests/13/head
Matthew 2020-07-06 03:17:03 -04:00
commit eb5159806d
No known key found for this signature in database
GPG Key ID: 210AF32ADE3B5C4B
35 changed files with 1865 additions and 1708 deletions

View File

@ -2,7 +2,7 @@ import eris from 'eris';
import mongoose from 'mongoose';
import { promises as fs } from 'fs';
import { Collection, Command, Util, ServerManagement, Event } from '.';
import { Member, MemberInterface, Moderation, ModerationInterface, PagerNumber, PagerNumberInterface, Redirect, RedirectInterface } from '../models';
import { Member, MemberInterface, Moderation, ModerationInterface, PagerNumber, PagerNumberInterface, Rank, RankInterface, Redirect, RedirectInterface } from '../models';
export default class Client extends eris.Client {
public config: { token: string, prefix: string, guildID: string, mongoDB: string, emailPass: string, };
@ -17,14 +17,14 @@ export default class Client extends eris.Client {
public serverManagement: ServerManagement;
public db: { Member: mongoose.Model<MemberInterface>, Moderation: mongoose.Model<ModerationInterface>, PagerNumber: mongoose.Model<PagerNumberInterface>, Redirect: mongoose.Model<RedirectInterface> };
public db: { Member: mongoose.Model<MemberInterface>, Moderation: mongoose.Model<ModerationInterface>, PagerNumber: mongoose.Model<PagerNumberInterface>, Rank: mongoose.Model<RankInterface>, Redirect: mongoose.Model<RedirectInterface> };
constructor(token: string, options?: eris.ClientOptions) {
super(token, options);
this.commands = new Collection<Command>();
this.events = new Collection<Event>();
this.intervals = new Collection<NodeJS.Timeout>();
this.db = { Member, Moderation, PagerNumber, Redirect };
this.db = { Member, Moderation, PagerNumber, Rank, Redirect };
}
public async loadDatabase() {

45
src/commands/addrank.ts Normal file
View File

@ -0,0 +1,45 @@
import { Message } from 'eris';
import { Client, Command } from '../class';
export default class AddRank extends Command {
constructor(client: Client) {
super(client);
this.name = 'addrank';
this.description = 'Makes a role self-assignable.';
this.usage = `${this.client.config.prefix}addrank <role> <permissions, pass 0 for everyone. separate role IDs with ':'> <description>`;
this.permissions = 6;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
if (!args[1]) return this.error(message.channel, 'Permissions are required.');
if (!args[2]) return this.error(message.channel, 'A description is required');
const role = this.client.util.resolveRole(args[0], this.client.guilds.get(this.client.config.guildID));
if (!role) return this.error(message.channel, 'The role you specified doesn\'t appear to exist.');
const check = await this.client.db.Rank.findOne({ roleID: role.id });
if (check) return this.error(message.channel, 'This role is already self-assignable.');
let permissions: string[];
if (args[1] === '0') {
permissions = ['0'];
} else {
permissions = args[1].split(':');
}
const entry = new this.client.db.Rank({
name: role.name,
roleID: role.id,
permissions,
description: args.slice(2).join(' '),
});
await entry.save();
return this.success(message.channel, `Role ${role.name} is now self-assignable.`);
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

30
src/commands/delrank.ts Normal file
View File

@ -0,0 +1,30 @@
import { Message } from 'eris';
import { Client, Command } from '../class';
export default class DelRank extends Command {
constructor(client: Client) {
super(client);
this.name = 'delrank';
this.description = 'Deletes an existing self-assignable role. This doesn\'t delete the role itself.';
this.usage = `${this.client.config.prefix}delrank <role>`;
this.permissions = 6;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) return this.client.commands.get('help').run(message, [this.name]);
const role = this.client.util.resolveRole(args[0], this.client.guilds.get(this.client.config.guildID));
if (!role) return this.error(message.channel, 'The role you specified doesn\'t appear to exist.');
const check = await this.client.db.Rank.findOne({ roleID: role.id });
if (!check) return this.error(message.channel, 'The entry doesn\'t appear to exist.');
await this.client.db.Rank.deleteOne({ roleID: role.id });
return this.success(message.channel, `Role ${role.name} is no longer self-assignable.`);
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

View File

@ -1,7 +1,9 @@
export { default as additem } from './additem';
export { default as addrank } from './addrank';
export { default as addredirect } from './addredirect';
export { default as ban } from './ban';
export { default as delitem } from './delitem';
export { default as delrank } from './delrank';
export { default as delredirect } from './delredirect';
export { default as djs } from './djs';
export { default as eval } from './eval';
@ -13,6 +15,7 @@ export { default as listredirects } from './listredirects';
export { default as npm } from './npm';
export { default as page } from './page';
export { default as ping } from './ping';
export { default as rank } from './rank';
export { default as roleinfo } from './roleinfo';
export { default as unban } from './unban';
export { default as whois } from './whois';

62
src/commands/rank.ts Normal file
View File

@ -0,0 +1,62 @@
import { Message, Role } from 'eris';
import { Client, Command, RichEmbed } from '../class';
export default class Rank extends Command {
constructor(client: Client) {
super(client);
this.name = 'rank';
this.description = 'Joins/leaves a self-assignable rank. Run this command without arguments to get a list of self-assignable roles.';
this.usage = `${this.client.config.prefix}rank <rank>`;
this.permissions = 0;
this.guildOnly = true;
this.enabled = true;
}
public async run(message: Message, args: string[]) {
try {
if (!args[0]) {
const roles = await this.client.db.Rank.find();
const embed = new RichEmbed();
embed.setTitle('Ranks');
embed.setDescription(`Use \`${this.client.config.prefix}rank <rank name> to join/leave the rank.\``);
for (const rank of roles.sort((a, b) => a.name.localeCompare(b.name))) {
let perms: string;
if (rank.permissions.includes('0')) {
perms = 'Everyone';
} else {
const rolesArray: Role[] = [];
rank.permissions.forEach((r) => {
rolesArray.push(this.client.guilds.get(this.client.config.guildID).roles.get(r));
});
perms = rolesArray.map((r) => message.guild.roles.get(r.id)).sort((a, b) => b.position - a.position).map((r) => `<@&${r.id}>`).join(', ');
}
embed.addField(rank.name, `__Description:__ ${rank.description}\n__Permissions:__ ${perms}`);
}
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
}
const role = this.client.util.resolveRole(args[0], this.client.guilds.get(this.client.config.guildID));
if (!role) return this.error(message.channel, 'The role you specified doesn\'t exist.');
const entry = await this.client.db.Rank.findOne({ roleID: role.id }).lean().exec();
if (!entry) return this.error(message.channel, 'The rank you specified doesn\'t exist.');
if (!message.member.roles.includes(entry.roleID)) {
let permCheck: boolean;
if (entry.permissions.includes('0')) {
permCheck = true;
} else {
permCheck = entry.permissions.some((item) => message.member.roles.includes(item));
}
if (!permCheck) return this.error(message.channel, 'Permission denied.');
await message.member.addRole(entry.roleID, `User ${message.author.username}#${message.author.discriminator} self-assigned this role.`);
this.success(message.channel, `You have self-assigned ${entry.name}.`);
} else if (message.member.roles.includes(entry.roleID)) {
await message.member.removeRole(entry.roleID, `User ${message.author.username}#${message.author.discriminator} has removed a self-assignable role.`);
this.success(message.channel, `You have removed ${entry.name}.`);
}
return null;
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}

View File

@ -3,7 +3,6 @@
*/
import { parse } from 'yaml';
import { promises as fs } from 'fs';
import { TextChannel } from 'eris';
import { Client } from './class';
import * as eventFiles from './events';
import * as commandFiles from './commands';

17
src/models/Rank.ts Normal file
View File

@ -0,0 +1,17 @@
import { Document, Schema, model } from 'mongoose';
export interface RankInterface extends Document {
name: string,
roleID: string,
permissions: string[],
description: string,
}
const Rank: Schema = new Schema({
name: String,
roleID: String,
permissions: Array,
description: String,
});
export default model<RankInterface>('Rank', Rank);

View File

@ -1,4 +1,5 @@
export { default as Member, MemberInterface } from './Member';
export { default as Moderation, ModerationInterface } from './Moderation';
export { default as PagerNumber, PagerNumberInterface, PagerNumberRaw } from './PagerNumber';
export { default as Rank, RankInterface } from './Rank';
export { default as Redirect, RedirectInterface, RedirectRaw } from './Redirect';