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 #298 from BanklessDAO/hotfix/2.6.2
Browse files Browse the repository at this point in the history
Hotfix/2.6.2
  • Loading branch information
SlinkyPotato authored Jan 13, 2022
2 parents e47515d + 4e2bac2 commit fd1ef9d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 54 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2.6.2-RELEASE (2022-01-13)

1. Handle twitter spaces exceptions
- update twitter settings schema validation
- add log msg for twitter flow
- stability enhancements

## 2.6.1-RELEASE (2022-01-11)

1. Fix prod keys
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": "2.6.1",
"version": "2.6.2",
"description": "Administrative and Utilitarian bot for the Bankless Discord Server.",
"main": "app.js",
"private": true,
Expand Down
1 change: 0 additions & 1 deletion src/app/events/poap/HandleParticipantDuringEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const HandleParticipantDuringEvent = async (oldState: VoiceState, newState: Voic
}

if (isUserDeaf(newState)) {
Log.log(`user is deaf, userId: ${newState.id}`);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/schema/poap/poapTwitterParticipants.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"$jsonSchema": {
"bsonType": "object",
"required": [
"twitterId",
"twitterUserId",
"twitterSpaceId",
"dateOfTweet"
],
"properties": {
"twitterId": {
"twitterUserId": {
"bsonType": "string",
"description": "The twitter ID of the user."
},
Expand Down
10 changes: 7 additions & 3 deletions src/app/schema/poap/poapTwitterSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"isActive",
"twitterSpaceId",
"discordUserId",
"twitterId",
"twitterUserId",
"discordServerId",
"startDate",
"endDate",
"startTime",
"endTime",
"channelExecutionId"
],
"properties": {
Expand All @@ -32,6 +32,10 @@
"bsonType": "string",
"description": "Discord Id of the user that is configured to use this command."
},
"twitterUserId": {
"bsonType": "string",
"description": "Twitter Id of the user that started the event."
},
"voiceChannelId": {
"bsonType": "string",
"description": "Identifier for the voice/stage channel"
Expand Down
45 changes: 27 additions & 18 deletions src/app/service/poap/OptInPOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import MongoDbUtils from '../../utils/MongoDbUtils';
import constants from '../constants/constants';
import { DiscordUserCollection } from '../../types/discord/DiscordUserCollection';
import Log from '../../utils/Log';
import Log, { LogUtils } from '../../utils/Log';
import {
DMChannel,
Message,
Expand Down Expand Up @@ -44,7 +44,6 @@ const OptInPOAP = async (user: User, dmChannel: DMChannel): Promise<void> => {
}

if (!isAllowedToGetDMs) {
Log.debug('user has DMs option turned off, now asking user for opt-in to get DM POAPs');
const row: MessageActionRow = new MessageActionRow()
.addComponents(
new MessageButton()
Expand All @@ -56,28 +55,38 @@ const OptInPOAP = async (user: User, dmChannel: DMChannel): Promise<void> => {
.setLabel('No')
.setStyle('SECONDARY'),
);
Log.debug('user has DMs option turned off, now asking user for opt-in to get DM POAPs');
const message: Message = await dmChannel.send({
content: 'I can send you POAPs directly to you. Would you like me to do that going forward?',
components: [row],
});
// 5 minute timeout
await message.awaitMessageComponent({
filter: args => (args.customId == buttonIds.POAP_OPT_IN_YES
|| args.customId == buttonIds.POAP_OPT_IN_NO) && args.user.id == user.id.toString(),
time: 300_000,
}).then((interaction) => {
if (interaction.customId == buttonIds.POAP_OPT_IN_YES) {
isAllowedToGetDMs = true;
} else {
message.edit({ content: 'No problem!', components: [] });
}
}).catch(error => {
message.edit({ content: 'Timeout reached, please reach out to us with any questions!', components: [] }).catch(e => {
Log.warn(e);
return;
try {
await message.awaitMessageComponent({
filter: args => (args.customId == buttonIds.POAP_OPT_IN_YES
|| args.customId == buttonIds.POAP_OPT_IN_NO) && args.user.id == user.id.toString(),
time: 300_000,
}).then((interaction) => {
if (interaction.customId == buttonIds.POAP_OPT_IN_YES) {
isAllowedToGetDMs = true;
} else {
message.edit({ content: 'No problem!', components: [] });
}
}).catch(error => {
try {
message.edit({ content: 'Timeout reached, please reach out to us with any questions!', components: [] }).catch(e => {
Log.warn(e);
return;
});
Log.debug(error?.message);
} catch (e) {
LogUtils.logError('gm opt-in message edit occurred', e);
}
});
Log.debug(error?.message);
});
} catch (e) {
LogUtils.logError('gm opt-in time/error occurred', e);
return;
}

if (isAllowedToGetDMs) {
await userSettingsCol.updateOne({
Expand Down
2 changes: 2 additions & 0 deletions src/app/service/poap/end/EndTwitterFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const EndTwitterFlow = async (guildMember: GuildMember, db: Db, ctx?: CommandCon
await ctx.send(embedTwitterEnd);
}

Log.debug('POAP end message sent to organizer!');

const poapLinksFile: MessageAttachment = await POAPUtils.askForPOAPLinks(guildMember, isDmOn, numberOfParticipants, ctx);
const listOfPOAPLinks: string[] = await POAPUtils.getListOfPoapLinks(poapLinksFile);
const distributionResults: POAPDistributionResults = await POAPUtils.sendOutTwitterPoapLinks(listOfParticipants, activeTwitterSettings.event, listOfPOAPLinks);
Expand Down
45 changes: 30 additions & 15 deletions src/app/service/poap/start/StartTwitterFlow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { CommandContext } from 'slash-create';
import { GuildMember } from 'discord.js';
import {
GuildMember,
MessageOptions,
} from 'discord.js';
import { Collection, Db, FindAndModifyWriteOpResultObject } from 'mongodb';
import Log, { LogUtils } from '../../../utils/Log';
import VerifyTwitter, { VerifiedTwitter } from '../../account/VerifyTwitter';
Expand All @@ -13,6 +16,7 @@ import dayjs, { Dayjs } from 'dayjs';
import POAPService from '../POAPService';
import { POAPTwitterParticipants } from '../../../types/poap/POAPTwitterParticipants';
import channelIds from '../../constants/channelIds';
import { MessageOptions as MessageOptionsSlash } from 'slash-create/lib/structures/interfaces/messageInteraction';

const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, db: Db, event: string, duration: number): Promise<any> => {
Log.debug('starting twitter poap flow...');
Expand Down Expand Up @@ -45,7 +49,7 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d
}

if (!isDmOn) {
await ctx.sendFollowUp({ content: '⚠ **Please make sure this is a private channel.** I can help you setup the poap event! ⚠' });
await ctx.send({ content: '⚠ **Please make sure this is a private channel.** I can help you setup the poap event! ⚠', ephemeral: true });
}

const twitterSpaceId: string = twitterSpaceResult.data[0]['id'];
Expand All @@ -62,7 +66,11 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d

if (activeSettings != null) {
Log.debug('unable to start twitter event due to active event');
throw new ValidationError('Looks like you have an active twitter spaces event!');
const msg = 'Looks like you have an active twitter spaces event!';
if (isDmOn) {
await ctx.send({ content: msg });
}
throw new ValidationError(msg);
}

Log.debug('setting up active twitter event in db');
Expand Down Expand Up @@ -99,24 +107,30 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d
const claimURL = `${apiKeys.twitterClaimPage}/${twitterSpaceId}`;

const claimUrlMsg = `POAP event setup! Please hand out ${claimURL} to your participants!`;
const eventStartedEmbed = {
title: 'Twitter Event Started',
fields: [
{ name: 'Event', value: `${event}`, inline: true },
{ name: 'Organizer', value: `${guildMember.user.tag}`, inline: true },
{ name: 'Discord Server', value: `${guildMember.guild.name}`, inline: true },
{ name: 'Platform', value: 'Twitter', inline: true },
{ name: 'Duration', value: `${duration} minutes`, inline: true },
{ name: 'POAP Participation Claim Link', value: claimUrlMsg, inline: false },
const eventStartedEmbed: MessageOptionsSlash | MessageOptions = {
embeds: [
{
title: 'Twitter Event Started',
fields: [
{ name: 'Event', value: `${event}`, inline: true },
{ name: 'Organizer', value: `${guildMember.user.tag}`, inline: true },
{ name: 'Discord Server', value: `${guildMember.guild.name}`, inline: true },
{ name: 'Platform', value: 'Twitter', inline: true },
{ name: 'Duration', value: `${duration} minutes`, inline: true },
{ name: 'POAP Participation Claim Link', value: claimUrlMsg, inline: false },
],
},
],
};
if (isDmOn) {
await guildMember.send({ embeds: [ eventStartedEmbed ] });
await guildMember.send(eventStartedEmbed as MessageOptions);
} else {
await ctx.send({ content: claimUrlMsg });
await ctx.send({ embeds: [eventStartedEmbed] });
await ctx.send(eventStartedEmbed as MessageOptionsSlash);
}

Log.debug('POAP Twitter spaces event start message sent');

const poapTwitterParticipants: Collection<POAPTwitterParticipants> = db.collection(constants.DB_COLLECTION_POAP_TWITTER_PARTICIPANTS);
const result: FindAndModifyWriteOpResultObject<any> = await poapTwitterParticipants.findOneAndReplace({
twitterSpaceId: twitterSpaceId,
Expand All @@ -132,7 +146,8 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d
if (result.ok != 1) {
throw new ValidationError('POAP event started but there was an issue with your claim...');
}
Log.debug('POAP Twitter spaces event start message sent');

Log.debug('poap organizer added to participants db');
};

export default StartTwitterFlow;
32 changes: 18 additions & 14 deletions src/app/utils/Log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,24 @@ export const LogUtils = {

logError(message: string, error: Error | any, guildId?: string): void {
try {
Sentry.captureException(error, {
tags: {
guildId: guildId,
},
});
Log.error(message, {
indexMeta: true,
meta: {
name: error?.name,
message: error?.message,
stack: error?.stack,
guildId: guildId,
},
});
if (error != null && error instanceof Error) {
Sentry.captureException(error, {
tags: {
guildId: guildId,
},
});
Log.error(message, {
indexMeta: true,
meta: {
name: error?.name,
message: error?.message,
stack: error?.stack,
guildId: guildId,
},
});
} else {
Log.error(message);
}
} catch (e) {
Log.warn(message);
}
Expand Down

0 comments on commit fd1ef9d

Please sign in to comment.