Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #167 from BanklessDAO/hotfix/1.6.2
Browse files Browse the repository at this point in the history
Hotfix/1.6.2
  • Loading branch information
Joshua Alexander authored Oct 1, 2021
2 parents 4554f0c + 8e8d7ad commit 734f1b1
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 75 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.6.2-RELEASE (2021-10-01)

1. Enhance stability of DEGEN

## 1.6.1-RELEASE (2021-10-01)

1. Reference production environment files
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "degen",
"version": "1.6.1",
"version": "1.6.2",
"description": "Administrative and Utilitarian bot for the Bankless Discord Server.",
"main": "app.js",
"private": true,
Expand Down
22 changes: 13 additions & 9 deletions src/app/events/GuildBanRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export default class implements DiscordEvent {
once = false;

async execute(ban: GuildBan): Promise<any> {
// Add unbanned users to allowlist so they don't get auto-banned by the bot
const db: Db = await dbInstance.dbConnect(constants.DB_NAME_DEGEN);
const dbAllowlist = db.collection(constants.DB_COLLECTION_ALLOWLIST);
try {
// Add unbanned users to allowlist so they don't get auto-banned by the bot
const db: Db = await dbInstance.dbConnect(constants.DB_NAME_DEGEN);
const dbAllowlist = db.collection(constants.DB_COLLECTION_ALLOWLIST);

const result: InsertOneWriteOpResult<Allowlist> = await dbAllowlist.insertOne({
discordUserId: ban.user.id,
discordServerId: ban.guild.id,
});
if (result == null || result.insertedCount !== 1) {
throw new MongoError(`failed to insert ${ban.user.id} into allowlist`);
const result: InsertOneWriteOpResult<Allowlist> = await dbAllowlist.insertOne({
discordUserId: ban.user.id,
discordServerId: ban.guild.id,
});
if (result == null || result.insertedCount !== 1) {
throw new MongoError(`failed to insert ${ban.user.id} into allowlist`);
}
} catch (e) {
console.error(e);
}
}
}
8 changes: 6 additions & 2 deletions src/app/events/GuildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ export default class implements DiscordEvent {
once = false;

async execute(member: GuildMember): Promise<any> {
if (await ServiceUtils.runUsernameSpamFilter(member)) {
return;
try {
if (await ServiceUtils.runUsernameSpamFilter(member)) {
return;
}
} catch (e) {
console.error(e);
}
}
}
36 changes: 19 additions & 17 deletions src/app/events/GuildMemberUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ export default class implements DiscordEvent {
if (newMember.partial) {
newMember = await newMember.fetch();
}

if (oldMember.nickname !== newMember.nickname && await ServiceUtils.runUsernameSpamFilter(newMember as GuildMember)) {
return;
}

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));
if (removedRoles.size > 0) {
console.debug(`The roles ${removedRoles.map(r => r.name)} were removed from ${oldMember.displayName}.`);
this.handleRolesRemoved(newMember as GuildMember, removedRoles);
return;
}

const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));
if (addedRoles.size > 0) {
console.debug(`The roles ${addedRoles.map(r => r.name)} were added to ${oldMember.displayName}.`);
this.handleRolesAdded(newMember as GuildMember, addedRoles);
}

} catch (e) {
console.error(e);
console.error('Retrieving member partial failed');
return;
}

if (oldMember.nickname !== newMember.nickname && await ServiceUtils.runUsernameSpamFilter(newMember as GuildMember)) {
return;
}

const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));
if (removedRoles.size > 0) {
console.debug(`The roles ${removedRoles.map(r => r.name)} were removed from ${oldMember.displayName}.`);
this.handleRolesRemoved(newMember as GuildMember, removedRoles);
return;
}

const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));
if (addedRoles.size > 0) {
console.debug(`The roles ${addedRoles.map(r => r.name)} were added to ${oldMember.displayName}.`);
this.handleRolesAdded(newMember as GuildMember, addedRoles);
}
}

/**
Expand Down
21 changes: 14 additions & 7 deletions src/app/events/MessageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
import messageCreateOnBountyBoard from './bounty/MessageCreateOnBountyBoard';
import { Message } from 'discord.js';
import { DiscordEvent } from '../types/discord/DiscordEvent';
import MessageCreateOnDEGEN from './chat/MessageCreateOnDEGEN';

export default class implements DiscordEvent {
name = 'messageCreate';
once = false;

execute(message: Message): Promise<any> {
if(message.author.bot && message.webhookId === null) return;
const greetings = ['Hello', 'Howdy', 'Hey', 'Go Bankless,', 'Nice to meet you,', 'It\'s great to see you,', 'Ahoy,'];
if (message.content.toLowerCase().match('^.*degen$')) {
message.channel.send({ content: `${greetings[Math.floor(Math.random() * greetings.length)]} ${message.author.username}!` });
try {
if(message.author.bot && message.webhookId === null) return;

// DEGEN says hello
MessageCreateOnDEGEN(message).catch(e => {
console.error('ERROR: ', e);
});
// Run for webhook
messageCreateOnBountyBoard(message).catch(e => {
console.error('ERROR: ', e);
});
} catch (e) {
console.error(e);
}
messageCreateOnBountyBoard(message).catch(e => {
console.error('ERROR: ', e);
});
}
}
37 changes: 17 additions & 20 deletions src/app/events/MessageReactionAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ export default class implements DiscordEvent {
once = false;

async execute(reaction: MessageReaction, user: User | PartialUser): Promise<any> {
// When a reaction is received, check if the structure is partial
if (reaction.partial) {
// If the message this reaction belongs to was removed, the fetching might result in an API error which should be handled
try {
try {
// When a reaction is received, check if the structure is partial
if (reaction.partial) {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
return;
}
}

if (user.partial) {
try {
await user.fetch();
} catch (error) {
console.error('Something is not working for pulling the user, maybe account was removed? lol');

if (user.partial) {
try {
await user.fetch();
} catch (error) {
console.error('Something is not working for pulling the user, maybe account was removed? lol');
return;
}
}

if (user.bot) {
return;
}
await messageReactionAddBounty(reaction, user as User);
} catch (e) {
console.error(e);
}

if (user.bot) {
return;
}

await messageReactionAddBounty(reaction, user as User);
}
}
24 changes: 14 additions & 10 deletions src/app/events/Ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export default class implements DiscordEvent {
once = true;

async execute(client: Client): Promise<any> {
console.log('The Sun will never set on the DAO. Neither will I. DEGEN & Serendipity are ready for service.');
client.user.setActivity('Going Bankless, Doing the DAO');
client.guilds.cache.forEach((guild: Guild) => {
console.log(`DEGEN active for: ${guild.id}, ${guild.name}`);
});
await connect(constants.DB_NAME_DEGEN);

if (client.guilds.cache.some((guild) => guild.id == discordServerIds.banklessDAO || guild.id == discordServerIds.discordBotGarage)) {
await connect(constants.DB_NAME_BOUNTY_BOARD);
await GuestPassService(client);
try {
console.log('The Sun will never set on the DAO. Neither will I. DEGEN & Serendipity are ready for service.');
client.user.setActivity('Going Bankless, Doing the DAO');
client.guilds.cache.forEach((guild: Guild) => {
console.log(`DEGEN active for: ${guild.id}, ${guild.name}`);
});
await connect(constants.DB_NAME_DEGEN);

if (client.guilds.cache.some((guild) => guild.id == discordServerIds.banklessDAO || guild.id == discordServerIds.discordBotGarage)) {
await connect(constants.DB_NAME_BOUNTY_BOARD);
await GuestPassService(client);
}
} catch (e) {
console.error(e);
}
}
}
15 changes: 7 additions & 8 deletions src/app/events/UserUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ export default class implements DiscordEvent {
if (newUser.partial) {
newUser = await newUser.fetch();
}
if (oldUser.username !== newUser.username) {
const guildMember = await ServiceUtils.getGuildMemberFromUser(newUser as User, process.env.DISCORD_SERVER_ID);
if (await ServiceUtils.runUsernameSpamFilter(guildMember)) {
return;
}
}
} catch (e) {
console.error('Retrieving user partial failed');
console.error(e);
return;
}

if (oldUser.username !== newUser.username) {
const guildMember = await ServiceUtils.getGuildMemberFromUser(newUser as User, process.env.DISCORD_SERVER_ID);
if (await ServiceUtils.runUsernameSpamFilter(guildMember)) {
return;
}
}
}
}
1 change: 0 additions & 1 deletion src/app/events/VoiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export default class implements DiscordEvent {
} catch (e) {
console.error(e);
}
return;
}
}
11 changes: 11 additions & 0 deletions src/app/events/chat/MessageCreateOnDEGEN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Message } from 'discord.js';

const MessageCreateOnDEGEN = async (message: Message): Promise<any> => {
const greetings = ['Hello', 'Howdy', 'Hey', 'Go Bankless,', 'Nice to meet you,', 'It\'s great to see you,', 'Ahoy,'];
if (message.content.toLowerCase().match('^.*degen$')) {
message.channel.send({ content: `${greetings[Math.floor(Math.random() * greetings.length)]} ${message.author.username}!` });
}
return;
};

export default MessageCreateOnDEGEN;

0 comments on commit 734f1b1

Please sign in to comment.