Skip to content

Commit

Permalink
Updated Discord js
Browse files Browse the repository at this point in the history
  • Loading branch information
SayakMukhopadhyay committed Nov 7, 2020
1 parent 1f4e21b commit 55f46c8
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 172 deletions.
110 changes: 80 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgsbot",
"version": "3.0.2",
"version": "3.1.0",
"license": "Apache-2.0",
"scripts": {
"start": "gulp scripts && cross-env PORT=4002 pm2 start process.json --env production",
Expand All @@ -12,7 +12,7 @@
"content-disposition": "^0.5.3",
"cron": "^1.8.2",
"debug": "^4.2.0",
"discord.js": "^11.5.1",
"discord.js": "^12.4.1",
"express": "^4.17.1",
"moment": "^2.29.1",
"mongoose": "^5.10.13",
Expand All @@ -29,7 +29,7 @@
"@types/mongoose": "^5.7.37",
"@types/mongoose-paginate": "^5.0.8",
"@types/morgan": "^1.9.2",
"@types/node": "^13.1.8",
"@types/node": "^12.19.3",
"@types/request-promise-native": "^1.0.17",
"cross-env": "^7.0.2",
"gulp": "^4.0.2",
Expand Down
19 changes: 8 additions & 11 deletions src/modules/cron/autoReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import { CronJob } from 'cron';
import { IGuildModel } from '../../db/models/index';
import { IGuildModel } from '../../db/models';
import { Client, GuildChannel, TextChannel } from 'discord.js';
import { CronJobStore } from '../../interfaces/typings';
import { BGSReport } from '../discord/commands/bgsReport';
import { BGSReport } from '../discord/commands';
import App from '../../server';

export class AutoReport {
Expand All @@ -32,7 +32,7 @@ export class AutoReport {
let cronJob = new CronJob(cronPattern, async () => {
try {
console.log('CRONjob execute');
let bgsChannel: GuildChannel = client.guilds.get(guild.guild_id).channels.get(guild.bgs_channel_id);
let bgsChannel: GuildChannel = client.guilds.cache.get(guild.guild_id).channels.cache.get(guild.bgs_channel_id);
if (bgsChannel && bgsChannel.type === 'text') {
let bgsReport = new BGSReport();
let embedArray = await bgsReport.getBGSReportEmbed(guild.guild_id, bgsChannel as TextChannel);
Expand All @@ -57,8 +57,7 @@ export class AutoReport {
time: guild.bgs_time
});
cronJob.start();
}
catch (err) {
} catch (err) {
App.bugsnagClient.call(err, {
metaData: {
time: guild.bgs_time,
Expand All @@ -80,7 +79,7 @@ export class AutoReport {
try {
let cronPattern = `${guild.bgs_time.split(':')[2]} ${guild.bgs_time.split(':')[1]} ${guild.bgs_time.split(':')[0]} * * *`;
let cronJob = new CronJob(cronPattern, async () => {
let bgsChannel: GuildChannel = client.guilds.get(guild.guild_id).channels.get(guild.bgs_channel_id);
let bgsChannel: GuildChannel = client.guilds.cache.get(guild.guild_id).channels.cache.get(guild.bgs_channel_id);
if (bgsChannel && bgsChannel.type === 'text') {
let bgsReport = new BGSReport();
let embedArray = await bgsReport.getBGSReportEmbed(guild.guild_id, bgsChannel as TextChannel);
Expand All @@ -97,8 +96,7 @@ export class AutoReport {
time: guild.bgs_time
});
cronJob.start();
}
catch (err) {
} catch (err) {
App.bugsnagClient.call(err, {
metaData: {
time: guild.bgs_time,
Expand All @@ -121,7 +119,7 @@ export class AutoReport {
try {
let cronPattern = `${guild.bgs_time.split(':')[2]} ${guild.bgs_time.split(':')[1]} ${guild.bgs_time.split(':')[0]} * * *`;
let cronJob = new CronJob(cronPattern, async () => {
let bgsChannel: GuildChannel = client.guilds.get(guild.guild_id).channels.get(guild.bgs_channel_id);
let bgsChannel: GuildChannel = client.guilds.cache.get(guild.guild_id).channels.cache.get(guild.bgs_channel_id);
if (bgsChannel && bgsChannel.type === 'text') {
let bgsReport = new BGSReport();
let embedArray = await bgsReport.getBGSReportEmbed(guild.guild_id, bgsChannel as TextChannel);
Expand All @@ -135,8 +133,7 @@ export class AutoReport {
this.jobs[indexOfJob].cronJob = cronJob;
this.jobs[indexOfJob].time = guild.bgs_time;
cronJob.start();
}
catch (err) {
} catch (err) {
App.bugsnagClient.call(err, {
metaData: {
time: guild.bgs_time,
Expand Down
14 changes: 7 additions & 7 deletions src/modules/discord/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as discord from 'discord.js';
import { Guild, User } from 'discord.js';
import App from '../../server';

export class Access {
Expand All @@ -23,15 +23,15 @@ export class Access {
public static readonly BGS: string = "bgs";
public static readonly FORBIDDEN: string = "forbidden";

public static async has(author: discord.User, guild: discord.Guild, perms: string[], allowAdmin = false): Promise<boolean> {
let member = await guild.fetchMember(author)
public static async has(author: User, guild: Guild, perms: string[], allowAdmin = false): Promise<boolean> {
let member = guild.member(author)
if (allowAdmin && member.hasPermission("ADMINISTRATOR")) {
return true;
} else {
let db = App.db;
let guildId = member.guild.id;
let roles = member.roles;
let guild = await db.model.guild.findOne({ guild_id: guildId });
let guild = await db.model.guild.findOne({guild_id: guildId});
let bool = false;
if (guild) {
perms.forEach((permission, index) => {
Expand All @@ -43,22 +43,22 @@ export class Access {
case "admin": {
let adminRoles = guild.admin_roles_id;
adminRoles.forEach((role, index) => {
if (roles.has(role)) {
if (roles.cache.has(role)) {
bool = true;
}
});
}
break;
case "bgs": {
let bgsRole = guild.bgs_role_id;
if (roles.has(bgsRole)) {
if (roles.cache.has(bgsRole)) {
bool = true;
}
}
case "forbidden": {
let forbiddenRoles = guild.forbidden_roles_id;
forbiddenRoles.forEach((role, index) => {
if (roles.has(role)) {
if (roles.cache.has(role)) {
bool = false;
}
});
Expand Down
Loading

0 comments on commit 55f46c8

Please sign in to comment.