Exemplo n.º 1
0
        private async Task ExecuteCommand(CommandContext command, DiscordUser targetUser)
        {
            if (!await Utils.VerifySelfOtherPermission(command, targetUser, "unlink"))
            {
                return;
            }

            if (!Database.TryGetSponsor(targetUser.Id, out Database.SponsorEntry _))
            {
                await command.RespondAsync(new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "This account is not linked."
                });

                return;
            }

            if (Database.TryRemoveSponsor(targetUser.Id))
            {
                await command.RespondAsync(new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Green,
                    Description = "Link removed."
                });
            }
            else
            {
                await command.RespondAsync(new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error occured when attempting to remove sponsor from database."
                });
            }


            DiscordMember member;

            try
            {
                member = await command.Guild.GetMemberAsync(targetUser.Id);
            }
            catch (Exception)
            {
                return;
            }

            await RoleChecker.SyncRoles(member, 0);
        }
Exemplo n.º 2
0
        public async Task OnExecute(CommandContext command, DiscordMember member)
        {
            if (!await Utils.VerifyPermission(command, "recheck"))
            {
                return;
            }

            if (!Database.TryGetSponsor(member.Id, out Database.SponsorEntry sponsorEntry))
            {
                await command.RespondAsync(new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "That user isn't linked to a Github account."
                });

                return;
            }

            await command.RespondAsync(new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "Running recheck on " + member.Mention + "."
            });

            List <Github.Sponsor> sponsors = await Github.GetSponsors();

            ulong sponsorTierRoleID = 0;

            Github.Sponsor sponsor = sponsors.FirstOrDefault(x => x.sponsor.id == sponsorEntry.githubID);
            if (sponsor != null)
            {
                sponsorTierRoleID = Config.tierRoles.GetValueOrDefault(sponsor.dollarAmount);
            }

            await RoleChecker.SyncRoles(member, sponsorTierRoleID);
        }
Exemplo n.º 3
0
        private async Task ExecuteCommand(CommandContext command, DiscordMember targetMember, string githubUsername = null)
        {
            if (!await Utils.VerifySelfOtherPermission(command, targetMember, "link"))
            {
                return;
            }

            if (Database.TryGetSponsor(targetMember.Id, out Database.SponsorEntry _))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "The Discord account <@" + targetMember.Id + "> is already linked to a Github account."
                };
                await command.RespondAsync(error);

                return;
            }

            Github.Account githubAccount = null;
            if (githubUsername != null)             // The username has been provided as a command argument
            {
                githubAccount = await Github.GetUserByUsername(githubUsername);

                if (githubAccount == null)
                {
                    DiscordEmbed notfound = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Could not find Github user '" + githubUsername + "'."
                    };
                    await command.RespondAsync(notfound);

                    return;
                }
            }
            else             // Perform standard two-factor authentication as username has not been provided
            {
                List <Github.Issue> issues = await Github.GetIssues();

                foreach (Github.Issue issue in issues)
                {
                    if (issue.description.Contains(command.Member.Id.ToString()))
                    {
                        githubAccount = issue.author;
                        break;
                    }
                }

                if (githubAccount == null)
                {
                    DiscordEmbed notfound = new DiscordEmbedBuilder
                    {
                        Color       = DiscordColor.Red,
                        Description = "Could not find a recent Github issue containing your Discord ID.\n"
                                      + "You must create an issue containing your Discord ID here:\n" + Config.issueURL
                    };
                    await command.RespondAsync(notfound);

                    return;
                }
            }

            if (Database.TryGetSponsor(githubAccount.id, out Database.SponsorEntry existingSponsor))
            {
                await command.RespondAsync(new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "The Github account '" + githubAccount.name + "' is already linked to <@" + existingSponsor.discordID + ">"
                });

                return;
            }

            if (!Database.TryAddSponsor(new Database.SponsorEntry {
                discordID = targetMember.Id, githubID = githubAccount.id
            }))
            {
                DiscordEmbed error = new DiscordEmbedBuilder
                {
                    Color       = DiscordColor.Red,
                    Description = "Error occured when writing sponsor to database."
                };
                await command.RespondAsync(error);

                return;
            }

            DiscordEmbed message = new DiscordEmbedBuilder
            {
                Color       = DiscordColor.Green,
                Description = "The Github account '" + githubAccount.name + "' is now linked to <@" + targetMember.Id + ">"
            };
            await command.RespondAsync(message);

            List <Github.Sponsor> sponsors = await Github.GetSponsors();

            ulong sponsorTierRoleID = 0;

            Github.Sponsor sponsor = sponsors.FirstOrDefault(x => x.sponsor.id == githubAccount.id);
            if (sponsor != null)
            {
                sponsorTierRoleID = Config.tierRoles.GetValueOrDefault(sponsor.dollarAmount);
            }

            await RoleChecker.SyncRoles(targetMember, sponsorTierRoleID);
        }