Пример #1
0
        public async Task AddModRole(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.Add(role.Id.ToString());
            await _guildSettingsRepoistory.SaveAsync(currentSettings);

            await ReplyAsync("Role added as moderator");
        }
Пример #2
0
        public async Task SetChannelAsync(IChannel channel)
        {
            var guild    = ((SocketGuildChannel)Context.Channel).Guild;
            var settings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (!await CheckPermission.CheckModPermission(
                    guild.OwnerId,
                    Context.User.Id,
                    settings.ModRoles,
                    ((SocketGuildUser)Context.User).Roles.Select(x => x.Id).ToList()
                    ))
            {
                await ReplyAsync("You don't have permission to do this!");

                return;
            }
            var current = await _twitchTeamSettingsRepository.GetAsync(guild.Id);

            if (current == null)
            {
                current = new Bot.Core.TwitchTeamSettings
                {
                    GuildId  = guild.Id.ToString(),
                    TeamName = ""
                };
            }
            current.ChannelId = channel.Id.ToString();

            await _twitchTeamSettingsRepository.SaveAsync(current);

            await ReplyAsync("Channel Set");
        }
Пример #3
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!");
            }
        }
Пример #4
0
        public async Task Start()
        {
            var guild    = ((SocketGuildChannel)Context.Channel).Guild;
            var settings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (!await CheckPermission.CheckModPermission(
                    guild.OwnerId,
                    Context.User.Id,
                    settings.ModRoles,
                    ((SocketGuildUser)Context.User).Roles.Select(x => x.Id).ToList()
                    ))
            {
                await ReplyAsync("You don't have permission to do this!");

                return;
            }
            var current = await _transcriberRepository.GetAsync(guild.Id, Context.Channel.Id);

            if (current == null)
            {
                current = new Bot.Core.Transcriber
                {
                    GuildId   = guild.Id.ToString(),
                    ChannelId = Context.Channel.Id.ToString(),
                    Started   = DateTime.Now,
                    Ended     = DateTime.MinValue,
                    MessageId = Context.Message.Id.ToString()
                };
            }
            else if (current.Ended != DateTime.MinValue)
            {
                current.Started   = DateTime.Now;
                current.Ended     = DateTime.MinValue;
                current.MessageId = Context.Message.Id.ToString();
            }
            else
            {
                await ReplyAsync("Transcriber already running on this channel");

                return;
            }

            await _transcriberRepository.SaveAsync(current);

            await ReplyAsync("Started transcriber on this channel");
        }
Пример #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);
        }
Пример #6
0
        public async Task InformationAsyc(int amount)
        {
            var guild    = ((SocketGuildChannel)Context.Channel).Guild;
            var settings = await _guildSettingsRepoistory.GetAsync(guild.Id);

            if (!await CheckPermission.CheckModPermission(
                    guild.OwnerId,
                    Context.User.Id,
                    settings.ModRoles,
                    ((SocketGuildUser)Context.User).Roles.Select(x => x.Id).ToList()
                    ))
            {
                await ReplyAsync("You don't have permission to do this!");

                return;
            }

            var messagesToPurge = await Context.Channel.GetMessagesAsync(amount).FlattenAsync();

            foreach (var message in messagesToPurge)
            {
                await Context.Channel.DeleteMessageAsync(message);
            }
        }