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 #290 from BanklessDAO/hotfix/2.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SlinkyPotato authored Jan 7, 2022
2 parents c3460cd + debc572 commit 50f9d86
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.5.1-RELEASE (2022-01-07)

1. Manually assign DSN, reference bot for gm message, add discord server on event

## 2.5.0-RELEASE (2022-01-03)

1. Integrate sentry.io
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-tbd",
"version": "2.5.0",
"version": "2.5.1",
"description": "Administrative and Utilitarian bot for the Bankless Discord Server.",
"main": "app.js",
"private": true,
Expand Down
1 change: 1 addition & 0 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function initializeClient(): Client {

function initializeSentryIO() {
Sentry.init({
dsn: `${apiKeys.sentryDSN}`,
tracesSampleRate: 1.0,
release: `${constants.APP_NAME}@${constants.APP_VERSION}`,
environment: process.env.SENTRY_ENVIRONMENT,
Expand Down
18 changes: 18 additions & 0 deletions src/app/events/GuildCreate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DiscordEvent } from '../types/discord/DiscordEvent';
import { Guild } from 'discord.js';
import Log, { LogUtils } from '../utils/Log';
import ServiceUtils from '../utils/ServiceUtils';

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

async execute(guild: Guild): Promise<any> {
try {
await ServiceUtils.addActiveDiscordServer(guild).catch(Log.error);

} catch (e) {
LogUtils.logError('failed to handle message from user', e);
}
}
}
6 changes: 3 additions & 3 deletions src/app/events/Ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class implements DiscordEvent {

async execute(client: Client): Promise<any> {
try {
Log.info('Starting up degen-tbd');
Log.info(`Starting up ${constants.APP_NAME}`);

if (client.user) {
Log.debug(`setting status: ${process.env.DISCORD_BOT_ACTIVITY}`);
Expand All @@ -30,7 +30,7 @@ export default class implements DiscordEvent {
await POAPService.runAutoEndSetup(client, constants.PLATFORM_TYPE_TWITTER).catch(Log.error);
await POAPService.clearExpiredPOAPs();

Log.info('degen-tbd is ready!');
Log.info(`${constants.APP_NAME} is ready!`);
} catch (e) {
LogUtils.logError('Error processing event ready', e);
}
Expand All @@ -46,7 +46,7 @@ const updateActiveDiscordServers = async (client: Client, db: Db) => {
},
});
for await (const guild of guilds.values()) {
Log.info(`DEGEN active for: ${guild.id}, ${guild.name}`);
Log.info(`${constants.APP_NAME} active for: ${guild.id}, ${guild.name}`);
await discordServerCollection.updateOne({
serverId: guild.id.toString(),
}, {
Expand Down
9 changes: 6 additions & 3 deletions src/app/events/chat/HandlePOAPGM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ const HandlePOAPGM = async (message: Message): Promise<void> => {

try {
await claimForDiscord(message.author.id.toString(), null, dmChannel);
await OptInPOAP(message.author, dmChannel);
await OptInPOAP(message.author, dmChannel).catch(e => {
Log.error(e);
ServiceUtils.sendOutErrorMessageForDM(dmChannel).catch(Log.error);
});

} catch (e) {
if (e instanceof ValidationError) {
await ServiceUtils.sendOutErrorMessageForDM(dmChannel, e?.message);
await ServiceUtils.sendOutErrorMessageForDM(dmChannel, e?.message).catch(Log.error);
} else {
await ServiceUtils.sendOutErrorMessageForDM(dmChannel);
await ServiceUtils.sendOutErrorMessageForDM(dmChannel).catch(Log.error);
}
LogUtils.logError('failed to claim poap in DM', e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/service/poap/ClaimPOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
MessageEmbedOptions as MessageEmbedOptionsSlash,
} from 'slash-create/lib/structures/message';
import POAPUtils from '../../utils/POAPUtils';
import apiKeys from '../constants/apiKeys';

const ClaimPOAP = async (ctx: CommandContext, platform: string, guildMember?: GuildMember): Promise<any> => {
Log.debug(`starting claim for ${ctx.user.username}, with ID: ${ctx.user.id}`);
Expand Down Expand Up @@ -66,7 +67,7 @@ export const claimForDiscord = async (userId: string, ctx?: CommandContext | nul

if (ctx) {
Log.debug('sending message in channel');
await ctx.send({ content: 'POAP claimed using `/poap claim`. Thank you!' });
await ctx.send({ content: `POAP claimed! Consider sending \`gm\` to <@${apiKeys.DISCORD_BOT_ID}>` });
const embeds: MessageEmbedOptionsSlash[] = await generatePOAPClaimEmbedMessages(numberOfPOAPs, unclaimedParticipants) as MessageEmbedOptionsSlash[];
await ctx.send({
embeds: embeds,
Expand Down
4 changes: 4 additions & 0 deletions src/app/utils/POAPUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ const POAPUtils = {
content: `Thank you for participating in the ${event} from ${guildName}! Here is your POAP: ${poapLink}`,
components: [
new MessageActionRow().addComponents(
new MessageButton()
.setLabel('Claim')
.setURL(`${poapLink}`)
.setStyle('LINK'),
new MessageButton()
.setCustomId(buttonIds.POAP_REPORT_SPAM)
.setLabel('Report')
Expand Down
19 changes: 19 additions & 0 deletions src/app/utils/ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import MongoDbUtils from './MongoDbUtils';
import constants from '../service/constants/constants';
import { DiscordUserCollection } from '../types/discord/DiscordUserCollection';
import { DiscordServerCollection } from '../types/discord/DiscordServerCollection';

const ServiceUtils = {
async getGuildAndMember(guildId: string, userId: string): Promise<{ guild: Guild, guildMember: GuildMember }> {
Expand Down Expand Up @@ -248,6 +249,7 @@ const ServiceUtils = {
isDMEnabledForUser: async (member: GuildMember): Promise<boolean> => {
const db: Db = await MongoDbUtils.connect(constants.DB_NAME_DEGEN);
const dbUsers: MongoCollection<DiscordUserCollection> = await db.collection(constants.DB_COLLECTION_DISCORD_USERS);
await member.fetch();
const result: DiscordUserCollection | null = await dbUsers.findOne({
userId: member.id.toString(),
});
Expand All @@ -258,6 +260,23 @@ const ServiceUtils = {

return result.isDMEnabled;
},

addActiveDiscordServer: async (guild: Guild): Promise<void> => {
const db: Db = await MongoDbUtils.connect(constants.DB_NAME_DEGEN);
const discordServerCollection = await db.collection<DiscordServerCollection>(constants.DB_COLLECTION_DISCORD_SERVERS);
Log.info(`DEGEN active for: ${guild.id}, ${guild.name}`);
await discordServerCollection.updateOne({
serverId: guild.id.toString(),
}, {
$set: {
serverId: guild.id.toString(),
name: guild.name,
isDEGENActive: true,
},
}, {
upsert: true,
});
},
};

export default ServiceUtils;

0 comments on commit 50f9d86

Please sign in to comment.