Skip to content

Commit

Permalink
Added command aliasing and data dm commands
Browse files Browse the repository at this point in the history
  • Loading branch information
SayakMukhopadhyay committed Feb 6, 2021
1 parent 6d541bd commit 7c86153
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 20 deletions.
53 changes: 43 additions & 10 deletions src/modules/discord/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,55 @@ export class DiscordClient {
}

private initiateCommands(): void {
let myGuild = new MyGuild();
let bgsRole = new BGSRole();
let adminRoles = new AdminRoles();
let forbiddenRoles = new ForbiddenRoles();
let bgaChannel = new BGSChannel();
let monitorSystems = new MonitorSystems();
let monitorFactions = new MonitorFactions();
let systemStatus = new SystemStatus();
let systemStatusDm = new SystemStatus(true);
let factionStatus = new FactionStatus();
let factionStatusDm = new FactionStatus(true);
let bgsReport = new BGSReport();
let bgsReportDm = new BGSReport(true);

this.commandsMap.set("hi", new Hi());
this.commandsMap.set("help", new Help());
this.commandsMap.set("myguild", new MyGuild());
this.commandsMap.set("bgsrole", new BGSRole());
this.commandsMap.set("adminroles", new AdminRoles());
this.commandsMap.set("forbiddenroles", new ForbiddenRoles());
this.commandsMap.set("bgschannel", new BGSChannel());
this.commandsMap.set("monitorsystems", new MonitorSystems());
this.commandsMap.set("monitorfactions", new MonitorFactions());
this.commandsMap.set("systemstatus", new SystemStatus());
this.commandsMap.set("factionstatus", new FactionStatus());
this.commandsMap.set("bgsreport", new BGSReport());
this.commandsMap.set("myguild", myGuild);
this.commandsMap.set("mgd", myGuild);
this.commandsMap.set("bgsrole", bgsRole);
this.commandsMap.set("brl", bgsRole);
this.commandsMap.set("adminroles", adminRoles);
this.commandsMap.set("arl", adminRoles);
this.commandsMap.set("forbiddenroles", forbiddenRoles);
this.commandsMap.set("frl", forbiddenRoles);
this.commandsMap.set("bgschannel", bgaChannel);
this.commandsMap.set("bcl", bgaChannel);
this.commandsMap.set("monitorsystems", monitorSystems);
this.commandsMap.set("ms", monitorSystems);
this.commandsMap.set("monitorfactions", monitorFactions);
this.commandsMap.set("mf", monitorFactions);
this.commandsMap.set("systemstatus", systemStatus);
this.commandsMap.set("ss", systemStatus);
this.commandsMap.set("systemstatusdm", systemStatusDm);
this.commandsMap.set("ssdm", systemStatusDm);
this.commandsMap.set("factionstatus", factionStatus);
this.commandsMap.set("fs", factionStatus);
this.commandsMap.set("factionstatusdm", factionStatusDm);
this.commandsMap.set("fsdm", factionStatusDm);
this.commandsMap.set("bgsreport", bgsReport);
this.commandsMap.set("bgsreport", bgsReport);
this.commandsMap.set("brt", bgsReport);
this.commandsMap.set("bgsreportdm", bgsReportDm);
this.commandsMap.set("brtdm", bgsReportDm);
this.commandsMap.set("sort", new Sort());
this.commandsMap.set("chart", new Chart());
this.commandsMap.set("chartdm", new Chart(true));
this.commandsMap.set("theme", new Theme());
this.commandsMap.set("tick", new Tick());
this.commandsMap.set("tickdm", new Tick(true));
}

private initiateCustom(): void {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/discord/commands/adminRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class AdminRoles {
try {
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -48,6 +49,17 @@ export class AdminRoles {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'a':
return 'add';
case 'r':
return 'remove';
case 'l':
return 'list';
}
}

async add(message: Message, argsArray: string[]) {
// Only the server admins can set the admin roles
let member = message.guild.member(message.author);
Expand Down
12 changes: 12 additions & 0 deletions src/modules/discord/commands/bgsChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class BGSChannel {
try {
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -48,6 +49,17 @@ export class BGSChannel {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 's':
return 'set';
case 'r':
return 'remove';
case 'sh':
return 'show';
}
}

async set(message: Message, argsArray: string[]) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.FORBIDDEN]);
Expand Down
25 changes: 23 additions & 2 deletions src/modules/discord/commands/bgsReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import { Tick } from './tick';
export class BGSReport {
db: DB;
tickTime: string;
dm: boolean;

constructor() {
constructor(dm = false) {
this.db = App.db;
this.tickTime = "";
this.dm = dm;
}

exec(message: Message, commandArguments: string): void {
Expand All @@ -43,6 +45,7 @@ export class BGSReport {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -53,6 +56,19 @@ export class BGSReport {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'g':
return 'get';
case 'st':
return 'settime';
case 'sh':
return 'showtime';
case 'u':
return 'unsettime';
}
}

async get(message: Message, argsArray: string[]) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.BGS, Access.FORBIDDEN]);
Expand All @@ -63,7 +79,12 @@ export class BGSReport {
if (message.guild.me.permissionsIn(message.channel).has([flags.EMBED_LINKS])) {
let embedArray = await this.getBGSReportEmbed(guildId, message.channel as TextChannel);
for (let index = 0; index < embedArray.length; index++) {
await message.channel.send(embedArray[index]);
if (this.dm) {
message.channel.send("I have DM'd the result to you");
message.member.send(embedArray[index]);
} else {
message.channel.send(embedArray[index]);
}
}
} else {
try {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/discord/commands/bgsRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class BGSRole {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -44,6 +45,17 @@ export class BGSRole {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 's':
return 'set';
case 'r':
return 'remove';
case 'sh':
return 'show';
}
}

async set(message: Message, argsArray: string[]) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.FORBIDDEN]);
Expand Down
11 changes: 9 additions & 2 deletions src/modules/discord/commands/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import { Access } from '../access';

export class Chart {
db: DB;
dm: boolean;

constructor() {
constructor(dm = false) {
this.db = App.db;
this.dm = dm;
}

exec(message: Message, commandArguments: string): void {
Expand Down Expand Up @@ -86,7 +88,12 @@ export class Chart {
let response: FullResponse = await request.get(requestOptions);
if (response.statusCode === 200) {
let attachment = new MessageAttachment(response.body as Buffer, contentDisposition.parse(response.headers['content-disposition']).parameters.filename);
message.channel.send(attachment);
if (this.dm) {
message.channel.send("I have DM'd the result to you");
message.member.send(attachment);
} else {
message.channel.send(attachment);
}
} else {
App.bugsnagClient.call(response.statusMessage, {
metaData: {
Expand Down
19 changes: 17 additions & 2 deletions src/modules/discord/commands/factionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import { Tick } from './tick';
export class FactionStatus {
db: DB;
tickTime: string;
dm: boolean;

constructor() {
constructor(dm = false) {
this.db = App.db;
this.tickTime = "";
this.dm = dm;
}

exec(message: Message, commandArguments: string): void {
Expand All @@ -43,6 +45,7 @@ export class FactionStatus {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -53,6 +56,13 @@ export class FactionStatus {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'g':
return 'get';
}
}

async get(message: Message, argsArray: string[]) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.BGS, Access.FORBIDDEN]);
Expand Down Expand Up @@ -224,7 +234,12 @@ export class FactionStatus {
embed.addField(fieldRecord[recordIndex].fieldTitle, fieldRecord[recordIndex].fieldDescription);
}
try {
message.channel.send(embed);
if (this.dm) {
message.channel.send("I have DM'd the result to you");
message.member.send(embed);
} else {
message.channel.send(embed);
}
} catch (err) {
App.bugsnagClient.call(err, {
metaData: {
Expand Down
12 changes: 12 additions & 0 deletions src/modules/discord/commands/forbiddenRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class ForbiddenRoles {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -44,6 +45,17 @@ export class ForbiddenRoles {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'a':
return 'add';
case 'r':
return 'remove';
case 'l':
return 'list';
}
}

async add(message: Message, argsArray: string[]) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.FORBIDDEN], true);
Expand Down
14 changes: 14 additions & 0 deletions src/modules/discord/commands/monitorFactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MonitorFactions {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -47,6 +48,19 @@ export class MonitorFactions {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'a':
return 'add';
case 'ap':
return 'addprimary';
case 'r':
return 'remove';
case 'l':
return 'list';
}
}

async add(message: Message, argsArray: string[], primary: boolean = false) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.BGS, Access.FORBIDDEN]);
Expand Down
14 changes: 14 additions & 0 deletions src/modules/discord/commands/monitorSystems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class MonitorSystems {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -47,6 +48,19 @@ export class MonitorSystems {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 'a':
return 'add';
case 'ap':
return 'addprimary';
case 'r':
return 'remove';
case 'l':
return 'list';
}
}

async add(message: Message, argsArray: string[], primary: boolean = false) {
try {
await Access.has(message.author, message.guild, [Access.ADMIN, Access.BGS, Access.FORBIDDEN]);
Expand Down
10 changes: 10 additions & 0 deletions src/modules/discord/commands/myGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class MyGuild {
}
if (argsArray.length > 0) {
let command = argsArray[0].toLowerCase();
command = this.checkAndMapAlias(command);
if (this[command]) {
this[command](message, argsArray);
} else {
Expand All @@ -44,6 +45,15 @@ export class MyGuild {
}
}

checkAndMapAlias(command: string) {
switch (command) {
case 's':
return 'set';
case 'r':
return 'remove';
}
}

async set(message: Message, argsArray: string[]) {
// Only the server admins can set the guild
let member = await message.guild.member(message.author)
Expand Down
Loading

0 comments on commit 7c86153

Please sign in to comment.