From 45077128fb2b20792a16028c5d5a72a3ad493263 Mon Sep 17 00:00:00 2001 From: Brian Patino Date: Fri, 7 Jan 2022 12:43:51 -0500 Subject: [PATCH 1/3] manually assign DSN --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/app/app.ts | 1 + src/app/events/chat/HandlePOAPGM.ts | 2 +- src/app/service/poap/ClaimPOAP.ts | 3 ++- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e764c35f..502e2a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.5.1-RELEASE (2022-01-07) + +1. Manually assign DSN, reference bot for gm message + ## 2.5.0-RELEASE (2022-01-03) 1. Integrate sentry.io diff --git a/package.json b/package.json index 87a3212c..975dc264 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/app/app.ts b/src/app/app.ts index 736fc3dd..57b32c93 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -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, diff --git a/src/app/events/chat/HandlePOAPGM.ts b/src/app/events/chat/HandlePOAPGM.ts index e3aa8d78..d891fad0 100644 --- a/src/app/events/chat/HandlePOAPGM.ts +++ b/src/app/events/chat/HandlePOAPGM.ts @@ -24,7 +24,7 @@ const HandlePOAPGM = async (message: Message): Promise => { try { await claimForDiscord(message.author.id.toString(), null, dmChannel); - await OptInPOAP(message.author, dmChannel); + await OptInPOAP(message.author, dmChannel).catch(Log.error); } catch (e) { if (e instanceof ValidationError) { diff --git a/src/app/service/poap/ClaimPOAP.ts b/src/app/service/poap/ClaimPOAP.ts index 17e3779f..1df79f12 100644 --- a/src/app/service/poap/ClaimPOAP.ts +++ b/src/app/service/poap/ClaimPOAP.ts @@ -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 => { Log.debug(`starting claim for ${ctx.user.username}, with ID: ${ctx.user.id}`); @@ -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, From ba57a51652de0eb45efd07fb16083c0d8a67e699 Mon Sep 17 00:00:00 2001 From: Brian Patino Date: Fri, 7 Jan 2022 13:12:32 -0500 Subject: [PATCH 2/3] add new discord servers on guildCreate event --- CHANGELOG.md | 2 +- src/app/events/GuildCreate.ts | 18 ++++++++++++++++++ src/app/events/chat/HandlePOAPGM.ts | 9 ++++++--- src/app/utils/ServiceUtils.ts | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 src/app/events/GuildCreate.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 502e2a0a..f20142ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 2.5.1-RELEASE (2022-01-07) -1. Manually assign DSN, reference bot for gm message +1. Manually assign DSN, reference bot for gm message, add discord server on event ## 2.5.0-RELEASE (2022-01-03) diff --git a/src/app/events/GuildCreate.ts b/src/app/events/GuildCreate.ts new file mode 100644 index 00000000..ea59cb20 --- /dev/null +++ b/src/app/events/GuildCreate.ts @@ -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 { + try { + await ServiceUtils.addActiveDiscordServer(guild).catch(Log.error); + + } catch (e) { + LogUtils.logError('failed to handle message from user', e); + } + } +} \ No newline at end of file diff --git a/src/app/events/chat/HandlePOAPGM.ts b/src/app/events/chat/HandlePOAPGM.ts index d891fad0..cdfdc0b9 100644 --- a/src/app/events/chat/HandlePOAPGM.ts +++ b/src/app/events/chat/HandlePOAPGM.ts @@ -24,13 +24,16 @@ const HandlePOAPGM = async (message: Message): Promise => { try { await claimForDiscord(message.author.id.toString(), null, dmChannel); - await OptInPOAP(message.author, dmChannel).catch(Log.error); + 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); } diff --git a/src/app/utils/ServiceUtils.ts b/src/app/utils/ServiceUtils.ts index 7f872454..c9c4ad79 100644 --- a/src/app/utils/ServiceUtils.ts +++ b/src/app/utils/ServiceUtils.ts @@ -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 }> { @@ -258,6 +259,23 @@ const ServiceUtils = { return result.isDMEnabled; }, + + addActiveDiscordServer: async (guild: Guild): Promise => { + const db: Db = await MongoDbUtils.connect(constants.DB_NAME_DEGEN); + const discordServerCollection = await db.collection(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; From debc5728d3b35c83f89d3c23e3b17fd8d1c3710a Mon Sep 17 00:00:00 2001 From: Brian Patino Date: Fri, 7 Jan 2022 13:47:36 -0500 Subject: [PATCH 3/3] add claim button --- src/app/events/Ready.ts | 6 +++--- src/app/utils/POAPUtils.ts | 4 ++++ src/app/utils/ServiceUtils.ts | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/events/Ready.ts b/src/app/events/Ready.ts index 5ff91852..f47b83af 100644 --- a/src/app/events/Ready.ts +++ b/src/app/events/Ready.ts @@ -18,7 +18,7 @@ export default class implements DiscordEvent { async execute(client: Client): Promise { 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}`); @@ -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); } @@ -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(), }, { diff --git a/src/app/utils/POAPUtils.ts b/src/app/utils/POAPUtils.ts index 477735a7..7628516a 100644 --- a/src/app/utils/POAPUtils.ts +++ b/src/app/utils/POAPUtils.ts @@ -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') diff --git a/src/app/utils/ServiceUtils.ts b/src/app/utils/ServiceUtils.ts index c9c4ad79..3c992981 100644 --- a/src/app/utils/ServiceUtils.ts +++ b/src/app/utils/ServiceUtils.ts @@ -249,6 +249,7 @@ const ServiceUtils = { isDMEnabledForUser: async (member: GuildMember): Promise => { const db: Db = await MongoDbUtils.connect(constants.DB_NAME_DEGEN); const dbUsers: MongoCollection = await db.collection(constants.DB_COLLECTION_DISCORD_USERS); + await member.fetch(); const result: DiscordUserCollection | null = await dbUsers.findOne({ userId: member.id.toString(), });