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 #130 from BanklessDAO/feature/allow-lvl-2-contribu…
Browse files Browse the repository at this point in the history
…tors

Feature/allow lvl 2 contributors
  • Loading branch information
Joshua Alexander authored Sep 1, 2021
2 parents 07ea269 + a330545 commit 6527ab5
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
2. Use mongodb connection pools
3. Expand bounty copies to lvl2+
4. Add Pradhumna Pancholi#3700 to POAP manager list
5. Allow lvl2+ contributors, admin, and genesis squad to use /poap command

## 1.3.2-RELEASE (2021-08-27)

Expand Down
6 changes: 3 additions & 3 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const creator = new SlashCreator({
token: process.env.DISCORD_BOT_TOKEN,
});

creator.on('debug', (message) => console.log(message));
creator.on('warn', (message) => console.warn(message));
creator.on('error', (error) => console.error(error));
creator.on('debug', (message) => console.log(`debug: ${ message }`));
creator.on('warn', (message) => console.warn(`warn: ${ message }`));
creator.on('error', (error) => console.error(`error: ${ error }`));
creator.on('synced', () => console.info('Commands synced!'));
creator.on('commandRegister', (command) => console.info(`Registered command ${command.commandName}`));
creator.on('commandError', (command, error) => console.error(`Command ${command.commandName}:`, error));
Expand Down
10 changes: 10 additions & 0 deletions src/app/commands/bounty/Bounty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ export default class Bounty extends SlashCommand {
id: roleIds.level4,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.admin,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.genesisSquad,
permission: true,
},
],
},
});
Expand Down
54 changes: 49 additions & 5 deletions src/app/commands/poap/poap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import EndPOAP from '../../service/poap/EndPOAP';
import ValidationError from '../../errors/ValidationError';
import poapEvents from '../../service/constants/poapEvents';
import DistributePOAP from '../../service/poap/DistributePOAP';
import roleIds from '../../service/constants/roleIds';

module.exports = class poap extends SlashCommand {
constructor(creator: SlashCreator) {
Expand Down Expand Up @@ -106,18 +107,44 @@ module.exports = class poap extends SlashCommand {
},
defaultPermission: false,
permissions: {
[process.env.DISCORD_SERVER_ID]: getAllowedUsers(),
[process.env.DISCORD_SERVER_ID]: [
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.level2,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.level3,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.level4,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.admin,
permission: true,
},
{
type: ApplicationCommandPermissionType.ROLE,
id: roleIds.genesisSquad,
permission: true,
},
],
},
});
}

async run(ctx: CommandContext) {
if (ctx.user.bot) return;
console.log(`start /poap ${ctx.user.username}#${ctx.user.discriminator}`);

const { guildMember } = await ServiceUtils.getGuildAndMember(ctx);
let command: Promise<any>;

try {
switch (ctx.subcommands[0]) {
case 'start':
Expand Down Expand Up @@ -172,4 +199,21 @@ export const getAllowedUsers = (): ApplicationCommandPermissions[] =>{
permission: true,
});
return allowedPermissions;
};
};

// TODO: pass this as a DM conversation... looks like client is not available until after slash commands are set
// export const getAllVoiceChannels = async (): Promise<any[]> => {
// // const voiceChannels: Collection<string, Channel> = client.channels.cache.filter(guildChannel => guildChannel.type === ChannelTypes.GUILD_VOICE.toString());
// // const choices = [];
// // for (const channel of voiceChannels.values()) {
// // choices.push({
// // name: channel.type,
// // value: channel.id,
// // });
// // }
// // return choices;
// return [{
// name: 'blank',
// value: 'asdfsdf',
// }];
// };
4 changes: 1 addition & 3 deletions src/app/service/help/HowToPOAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export default (): MessageOptions => {
fields: [
{
name: '-> /poap start',
value: 'Start keeping track of attendees in the voice channel. The voice channel depends on the event.\n\n ' +
'Community Call: Community Calls (stage)\n' +
'Dev Guild: dev workroom',
value: 'Start keeping track of attendees in the voice channel. Once started it must be stopped by the same user.',
inline: false,
},
{
Expand Down
9 changes: 1 addition & 8 deletions src/app/utils/BountyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ const BountyUtils = {
},

validateNumberOfCopies(guildMember: GuildMember, copies: number): void {
const isLevel2 = ServiceUtils.isLevel2(guildMember);
const isLevel3 = ServiceUtils.isLevel3(guildMember);
const isLevel4 = ServiceUtils.isLevel4(guildMember);
const isAdmin = ServiceUtils.isAdmin(guildMember);

if (!(isLevel2 || isLevel3 || isLevel4 || isAdmin)) {
throw new ValidationError('Must be `level 2+` to publish multiple copies.');
}
ServiceUtils.validateLevel2AboveMembers(guildMember);

if (copies > 100) {
throw new ValidationError('Max number of copies is `100`.');
Expand Down
17 changes: 17 additions & 0 deletions src/app/utils/ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CommandContext } from 'slash-create';
import { Guild, GuildMember, Role, RoleManager } from 'discord.js';
import client from '../app';
import roleIDs from '../service/constants/roleIds';
import ValidationError from '../errors/ValidationError';

const ServiceUtils = {
async getGuildAndMember(ctx: CommandContext): Promise<{ guild: Guild, guildMember: GuildMember }> {
Expand Down Expand Up @@ -41,6 +42,10 @@ const ServiceUtils = {
return guildMember.roles.cache.some(role => role.id === roleIDs.level4);
},

isGenesisSquad(guildMember: GuildMember): boolean {
return guildMember.roles.cache.some(role => role.id === roleIDs.genesisSquad);
},

isAnyLevel(guildMember: GuildMember): boolean {
console.log(guildMember.roles.cache);
return guildMember.roles.cache.some(role => role.id === roleIDs.level1
Expand All @@ -56,6 +61,18 @@ const ServiceUtils = {
};
return (new Date(dateIso)).toLocaleString('en-US', options);
},

validateLevel2AboveMembers(guildMember: GuildMember): void {
const isLevel2 = ServiceUtils.isLevel2(guildMember);
const isLevel3 = ServiceUtils.isLevel3(guildMember);
const isLevel4 = ServiceUtils.isLevel4(guildMember);
const isGenesisSquad = ServiceUtils.isGenesisSquad(guildMember);
const isAdmin = ServiceUtils.isAdmin(guildMember);

if (!(isLevel2 || isLevel3 || isLevel4 || isAdmin || isGenesisSquad)) {
throw new ValidationError('Must be `level 2` or above member.');
}
},
};

export default ServiceUtils;

0 comments on commit 6527ab5

Please sign in to comment.