示例#1
0
        public async Task RemoveModRole(IRole role)
        {
            var guild = ((SocketGuildChannel)Context.Channel).Guild;

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id))
            {
                await ReplyAsync("You are not the owner of this discord so cannot add credentials");

                return;
            }
            var currentSettings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (currentSettings == null)
            {
                currentSettings = new Bot.Core.GuildSettings
                {
                    GuildId  = guild.Id.ToString(),
                    ModRoles = new List <string>()
                };
            }

            currentSettings.ModRoles.Remove(role.Id.ToString());
            await _guildSettingsRepoistory.SaveAsync(currentSettings);

            await ReplyAsync("Role removed as moderator");
        }
示例#2
0
        public async Task AddCredentialsAsync()
        {
            var guild = ((SocketGuildChannel)Context.Channel).Guild;

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id))
            {
                await ReplyAsync("You are not the owner of this discord so cannot add credentials");

                return;
            }

            var state = new StateModel
            {
                UserId    = Context.User.Id,
                ChannelId = Context.Channel.Id,
                GuildId   = guild.Id
            };

            var serialisedState = System.Text.Json.JsonSerializer.Serialize(state);

            var encryptedSerialisedState = _cypher.Encrypt(serialisedState);

            var dmChannel = await Context.User.GetOrCreateDMChannelAsync();

            await dmChannel.SendMessageAsync("To add your user credentials so we can access bits & subscriber " +
                                             "information use the following link to get access " +
                                             $"https://id.twitch.tv/oauth2/authorize?client_id={_config.TwitchClientId}&response_type=code&redirect_uri={_config.TwitchRedirectUrl}&scope=channel:read:subscriptions+bits:read+user:read:email&state={encryptedSerialisedState}");

            await ReplyAsync("I sent you a DM, better go check!");
        }
示例#3
0
        public async Task InstallGitHubCredentialsAsync()
        {
            var guild = ((SocketGuildChannel)Context.Channel).Guild;

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id))
            {
                await ReplyAsync("You are not the owner of this discord so cannot add credentials");

                return;
            }

            var state = new StateModel
            {
                UserId    = Context.User.Id,
                ChannelId = Context.Channel.Id,
                GuildId   = guild.Id
            };

            var serialisedState = System.Text.Json.JsonSerializer.Serialize(state);

            var encryptedSerialisedState = _cypher.Encrypt(serialisedState);

            //var authLink = await _gitHubService.GetAuthUrlAsync(encryptedSerialisedState);
            var dmChannel = await Context.User.GetOrCreateDMChannelAsync();

            await dmChannel.SendMessageAsync("To add your user credentials so we can access bits & subscriber " +
                                             "information use the following link to get access " +
                                             $"https://github.com/apps/alfred-discord/installations/new?state={encryptedSerialisedState}");

            await ReplyAsync("I sent you a DM, better go check!");
        }
示例#4
0
        public async Task ListOrgsAsync([Remainder] string orgName = "")
        {
            var guild    = ((SocketGuildChannel)Context.Channel).Guild;
            var settings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id
                    ))
            {
                await ReplyAsync("You don't have permission to do this!");

                return;
            }

            var current = await _ownerGitHubCredentialRepository.GetAsync(Context.User.Id);

            if (current == null)
            {
                await ReplyAsync("no github credentials set for you");

                return;
            }

            if (string.IsNullOrEmpty(orgName))
            {
                var allOrgs = await _gitHubService.GetGitHubOrgsAsync(current.AccessToken);

                if (allOrgs.Count() == 0)
                {
                    await ReplyAsync("Alfred is not installed in any of your Organisations");
                }
                var embed = new EmbedBuilder()
                            .WithTitle("GitHub Organisations")
                            .WithDescription("re-run `!github set-org` with the name of the organisation e.g. `!github set-org MyOrgName`")
                            .AddField("Organisation Names", string.Join(" \r\n", allOrgs.Select(x => x.Login)), true)
                            .Build();

                await ReplyAsync(embed : embed);
            }
            else
            {
                var installs = await _gitHubService.GetGitHubInstallationsAsync(current.AccessToken);

                var install = installs.Installations
                              .Where(x => x.TargetType == AccountType.Organization)
                              .Where(x => x.Account.Login.ToLower() == orgName.ToLower())
                              .FirstOrDefault();
                if (install == null)
                {
                    await ReplyAsync("Alfred is not installed in any of your Organisations");
                }
                settings.GitHubInstallationID = install.Id.ToString();
                await _guildSettingsRepoistory.SaveAsync(settings);
                await ReplyAsync("Organisation set!");
            }
        }
示例#5
0
        public async Task ListOrgsAsync(ITextChannel channel, [Remainder] string browserSourceUrl = "")
        {
            var guild    = ((SocketGuildChannel)Context.Channel).Guild;
            var settings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id
                    ))
            {
                await ReplyAsync("You don't have permission to do this!");

                return;
            }

            if (string.IsNullOrEmpty(browserSourceUrl))
            {
                await ReplyAsync("please enter your featured chat browser source url");

                return;
            }

            var current = await _featuredChatSettingsRepository.GetAsync(guild.Id);

            if (current == null)
            {
                current = new Bot.Core.FeaturedChatSettings
                {
                    GuildId = guild.Id.ToString()
                };
            }

            current.ChannelId        = channel.Id.ToString();
            current.BrowserSourceUrl = browserSourceUrl;

            await _featuredChatSettingsRepository.SaveAsync(current);
        }