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

Commit

Permalink
PR prep
Browse files Browse the repository at this point in the history
  • Loading branch information
SlinkyPotato committed Jan 13, 2022
1 parent 26aa72b commit 4e2bac2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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)

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
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
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;

0 comments on commit 4e2bac2

Please sign in to comment.