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 #302 from BanklessDAO/feature/stability-enhancements
Browse files Browse the repository at this point in the history
Feature/stability enhancements
  • Loading branch information
SlinkyPotato authored Jan 19, 2022
2 parents c93c040 + c00e0da commit 447e7ee
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 105 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
5. Introduce basic `/claim` command and prompt user for opt-in on slash command
6. Increase poap max time to 12 hours
7. Add poap expiration cron job
8. Enhance poap distribution to with ephemeral
- fix timeout reply after poap distribution
- enhance poap distribution loop
- enhance poap end
9. Parse blank strings for msg embed display
10. Prompt users to DM delivery is /claim is executed from channel
11. Message enhancements to twitter flow

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

Expand Down
2 changes: 1 addition & 1 deletion src/app/events/VoiceStateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class implements DiscordEvent {
*/
async execute(oldState: VoiceState, newState: VoiceState): Promise<any> {
try {
await HandleParticipantDuringEvent(oldState, newState).catch(e => LogUtils.logError('failed to handle user in POAP event', e, oldState.guild.id));
await HandleParticipantDuringEvent(oldState, newState).catch(e => LogUtils.logError('failed to handle user in POAP event', e));
} catch (e) {
LogUtils.logError('failed to process event voiceStateUpdate', e);
}
Expand Down
3 changes: 1 addition & 2 deletions src/app/service/account/UnlinkAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const promptToUnlink = async (ctx: CommandContext, guildMember: GuildMember, isD
fields: [
{ name: 'UserId', value: `${twitterUser.twitterUser.id_str}`, inline: false },
{ name: 'Name', value: `${twitterUser.twitterUser.screen_name}`, inline: false },
{ name: 'Description', value: `${twitterUser.twitterUser.description}`, inline: false },
{ name: 'Description', value: `${ServiceUtils.prepEmbedField(twitterUser.twitterUser.description)}`, inline: false },
{ name: 'Profile', value: `https://twitter.com/${twitterUser.twitterUser.screen_name}`, inline: false },
],
},
Expand Down Expand Up @@ -145,7 +145,6 @@ const promptToUnlink = async (ctx: CommandContext, guildMember: GuildMember, isD
];
Log.debug('attempting to send msg to user');
Log.debug(shouldUnlinkMsg);
await ctx.defer(true);
const msgSlashResponse: MessageSlash = await ctx.send(shouldUnlinkMsg) as MessageSlash;
Log.debug('ctx message on user confirmation sent');
shouldUnlinkPromise = new Promise<any>((resolve, _) => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/service/account/VerifyTwitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const VerifyTwitter = async (ctx: CommandContext, guildMember: GuildMember, send
};

export const retrieveVerifiedTwitter = async (guildMember: GuildMember): Promise<VerifiedTwitter | null> => {
Log.debug('starting to link twitter account link');
Log.debug('starting to retrieve twitter account');

const db: Db = await MongoDbUtils.connect(constants.DB_NAME_NEXTAUTH);
const accountsCollection: Collection<NextAuthAccountCollection> = db.collection(constants.DB_COLLECTION_NEXT_AUTH_ACCOUNTS);
Expand All @@ -87,7 +87,7 @@ export const retrieveVerifiedTwitter = async (guildMember: GuildMember): Promise
});

if (twitterCollection == null || twitterCollection.accessToken == null) {
Log.debug('twitter account not linked');
Log.debug('twitter account not found');
return null;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export const retrieveVerifiedTwitter = async (guildMember: GuildMember): Promise
return null;
}

Log.debug('done linking twitter account');
Log.debug('found twitter account');
return {
twitterUser: userCall,
twitterClientV1: userClient,
Expand Down
13 changes: 8 additions & 5 deletions src/app/service/poap/ClaimPOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ const ClaimPOAP = async (ctx: CommandContext, platform: string, guildMember?: Gu
await claimForDiscord(ctx.user.id, ctx);
if (guildMember && ctx) {
try {
const dmChannel: DMChannel = await guildMember.createDM();
await OptInPOAP(guildMember.user, await dmChannel).catch(e => {
Log.error(e);
ServiceUtils.sendOutErrorMessageForDM(dmChannel).catch(Log.error);
});
const isDmOn: boolean = await ServiceUtils.tryDMUser(guildMember, 'gm');
if (isDmOn) {
const dmChannel: DMChannel = await guildMember.createDM();
await OptInPOAP(guildMember.user, dmChannel).catch(e => {
Log.error(e);
ServiceUtils.sendOutErrorMessageForDM(dmChannel).catch(Log.error);
});
}
} catch (e) {
LogUtils.logError('failed to ask for opt-in', e);
}
Expand Down
23 changes: 15 additions & 8 deletions src/app/service/poap/DistributePOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export default async (ctx: CommandContext, guildMember: GuildMember, event: stri

const isDmOn: boolean = await ServiceUtils.tryDMUser(guildMember, 'Hello! I can help you distribute POAPS.');

if (!isDmOn) {
await ctx.sendFollowUp({ content: '⚠ Please make sure this is a private channel. I can help you distribute POAPs but anyone who has access to this channel can see private information! ⚠' });
} else if (ctx) {
await ctx.defer(true);

if (isDmOn) {
await ctx.send({ content: 'Please check your DMs!', ephemeral: true });
} else {
await ctx.send({ content: '⚠ Please make sure this is a private channel. I can help you distribute POAPs but anyone who has access to this channel can see private information! ⚠', ephemeral: true });
}

let participantsList: POAPFileParticipant[] | TwitterPOAPFileParticipant[] = await askForParticipantsList(guildMember, platform, isDmOn, ctx);
Expand All @@ -56,7 +58,7 @@ export default async (ctx: CommandContext, guildMember: GuildMember, event: stri
if (isDmOn) {
await guildMember.send({ content: msg }).catch(Log.error);
} else {
await ctx.send({ content: msg });
await ctx.send({ content: msg, ephemeral: true });
}
throw Error('failed to parse');
}
Expand All @@ -83,15 +85,15 @@ export const askForParticipantsList = async (guildMember: GuildMember, platform:
Log.debug('preparing to ask for participants list csv file');
let csvPrompt = '';
if (platform == constants.PLATFORM_TYPE_DISCORD) {
csvPrompt = 'Please upload participants.csv file with header containing discordUserId. POAPs will be distributed to these degens.';
csvPrompt = 'Please upload distribution file with header containing discordUserId. POAPs will be distributed to these degens.';
} else if (platform == constants.PLATFORM_TYPE_TWITTER) {
csvPrompt = 'Please upload participants.csv file with header containing twitterUserId. POAPs will be distributed to these degens.';
csvPrompt = 'Please upload distribution file with header containing twitterUserId. POAPs will be distributed to these degens.';
}

if (isDmOn) {
await guildMember.send({ content: csvPrompt });
} else {
await ctx.sendFollowUp({ content: csvPrompt });
await ctx.send({ content: csvPrompt, ephemeral: true });
}

Log.debug(`message: '${csvPrompt}' send to user`);
Expand All @@ -104,8 +106,9 @@ export const askForParticipantsList = async (guildMember: GuildMember, platform:
try {
const message: Message | undefined = (await contextChannel.awaitMessages({
max: 1,
time: 180000,
time: 180_000,
errors: ['time'],
filter: m => m.author.id == guildMember.id && m.attachments.size >= 1,
})).first();
if (message == null) {
throw new ValidationError('Invalid message');
Expand All @@ -120,6 +123,10 @@ export const askForParticipantsList = async (guildMember: GuildMember, platform:
const fileResponse = await axios.get(participantAttachment.url);
participantsList = ServiceUtils.parseCSVFile(fileResponse.data);

if (!isDmOn) {
await message.delete();
}

if ((participantsList as POAPFileParticipant[])[0].discordUserId == null) {
if ((participantsList as TwitterPOAPFileParticipant[])[0].twitterUserId == null) {
throw new Error('missing ID');
Expand Down
4 changes: 2 additions & 2 deletions src/app/service/poap/SchedulePOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ const SchedulePOAP = async (ctx: CommandContext, guildMember: GuildMember, numbe
{ name: 'Event Title', value: request.name },
{ name: 'Event Description', value: request.description },
{ name: 'Virtual Event', value: (request.virtual_event ? 'yes' : 'no'), inline: true },
{ name: 'City', value: `${request.city} `, inline: true },
{ name: 'Country', value: `${request.country} `, inline: true },
{ name: 'City', value: `${ServiceUtils.prepEmbedField(request.city)}`, inline: true },
{ name: 'Country', value: `${ServiceUtils.prepEmbedField(request.country)}`, inline: true },
{ name: 'Event Start', value: request.start_date, inline: true },
{ name: 'Event End', value: request.end_date, inline: true },
{ name: 'Event URL', value: `${request.event_url} `, inline: true },
Expand Down
10 changes: 8 additions & 2 deletions src/app/service/poap/end/EndTwitterFlow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
GuildMember,
MessageAttachment,
MessageOptions,
TextChannel,
} from 'discord.js';
import {
Expand All @@ -19,6 +20,7 @@ import POAPUtils, { TwitterPOAPFileParticipant } from '../../../utils/POAPUtils'
import { Buffer } from 'buffer';
import { POAPDistributionResults } from '../../../types/poap/POAPDistributionResults';
import channelIds from '../../constants/channelIds';
import { MessageOptions as MessageOptionsSlash } from 'slash-create/lib/structures/interfaces/messageInteraction';

const EndTwitterFlow = async (guildMember: GuildMember, db: Db, ctx?: CommandContext): Promise<any> => {
Log.debug('starting twitter poap end flow...');
Expand Down Expand Up @@ -81,7 +83,8 @@ const EndTwitterFlow = async (guildMember: GuildMember, db: Db, ctx?: CommandCon
}

const bufferFile: Buffer = ServiceUtils.generateCSVStringBuffer(listOfParticipants);
const embedTwitterEnd = {
const fileName = `twitter_participants_${numberOfParticipants}.csv`;
let embedTwitterEnd: MessageOptionsSlash | MessageOptions = {
embeds: [
{
title: 'Twitter Event Ended',
Expand All @@ -92,11 +95,14 @@ const EndTwitterFlow = async (guildMember: GuildMember, db: Db, ctx?: CommandCon
],
},
],
files: [{ name: `twitter_participants_${numberOfParticipants}.csv`, attachment: bufferFile }],
};
if (isDmOn) {
embedTwitterEnd = embedTwitterEnd as MessageOptions;
embedTwitterEnd.files = [{ name: fileName, attachment: bufferFile }];
await guildMember.send(embedTwitterEnd);
} else if (ctx) {
embedTwitterEnd = embedTwitterEnd as MessageOptionsSlash;
embedTwitterEnd.file = [{ name: fileName, file: bufferFile }];
await ctx.send(embedTwitterEnd);
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/service/poap/start/StartChannelFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const StartChannelFlow = async (
Log.debug('starting channel flow for poap start');
const voiceChannels: Collection<string, VoiceChannel | StageChannel> = ServiceUtils.getAllVoiceChannels(guildMember);

await ctx.sendFollowUp({ content: '⚠ **Please make sure this is a private channel.** I can help you setup the poap event! ⚠' });
const embedsVoiceChannels = generateVoiceChannelEmbedMessage(voiceChannels) as MessageEmbedOptionsSlash[];
const message = await ctx.sendFollowUp({ embeds: embedsVoiceChannels });

Expand All @@ -45,13 +44,13 @@ const StartChannelFlow = async (

if (poapSettingsDoc !== null && poapSettingsDoc.isActive) {
Log.warn('unable to start due to active event');
await ctx.sendFollowUp(`\`${channelChoice.name}\` is already active. Please reach out to <@${poapSettingsDoc.discordUserId}> to end event.`);
await ctx.send({ content: `\`${channelChoice.name}\` is already active. Please reach out to <@${poapSettingsDoc.discordUserId}> to end event.`, ephemeral: true });
return;
}

await setActiveEventInDb(guildMember, db, channelChoice, event, duration, ctx.channelID);

await ctx.sendFollowUp({
await ctx.send({
embeds: [
{
title: 'Event Started',
Expand All @@ -65,9 +64,10 @@ const StartChannelFlow = async (
],
},
],
ephemeral: true,
});

await ctx.sendFollowUp(({ content: 'Everything is set, catch you later!' }));
await ctx.sendFollowUp(({ content: 'Everything is set, catch you later!', ephemeral: true }));
};

export default StartChannelFlow;
2 changes: 2 additions & 0 deletions src/app/service/poap/start/StartPOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default async (ctx: CommandContext, guildMember: GuildMember, platform: s

Log.debug('poap start validated');

await ctx.defer();

if (platform == constants.PLATFORM_TYPE_TWITTER) {
await StartTwitterFlow(ctx, guildMember, db, event, duration);
return;
Expand Down
8 changes: 2 additions & 6 deletions src/app/service/poap/start/StartTwitterFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,10 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d
return;
}

if (!isDmOn) {
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'];
Log.debug(`twitter spaces event active: ${twitterSpaceId}`);

await ctx.send({ content: `Something really special is starting...:bird: https://twitter.com/i/spaces/${twitterSpaceId}` });
await ctx.send({ content: `Twitter Spaces :bird: is live at https://twitter.com/i/spaces/${twitterSpaceId}` });

const poapTwitterSettings: Collection<POAPTwitterSettings> = db.collection(constants.DB_COLLECTION_POAP_TWITTER_SETTINGS);
const activeSettings: POAPTwitterSettings | null = await poapTwitterSettings.findOne({
Expand All @@ -74,7 +70,7 @@ const StartTwitterFlow = async (ctx: CommandContext, guildMember: GuildMember, d
Log.debug('unable to start twitter event due to active event');
const msg = 'Looks like you have an active twitter spaces event!';
if (isDmOn) {
await ctx.send({ content: msg });
await ctx.send({ content: msg, ephemeral: true });
}
throw new ValidationError(msg);
}
Expand Down
Loading

0 comments on commit 447e7ee

Please sign in to comment.