コード例 #1
0
        public async Task Random(SocketCommandContext context, string[] _, ServerConfig serverConfig)
        {
            // If the bot is already in a voice channel in the server, then don't play a quote
            if (!((context.Guild.CurrentUser as IGuildUser)?.VoiceChannel is null))
            {
                await context.Reply("I am already doing a quote calm down.");

                return;
            }
            var category = await GetRandomCategory(context.Guild.Id);

            var audio = await GetRandomAudioForCategory(context.Guild.Id, category.Id);

            var channel = (context.User as IGuildUser)?.VoiceChannel;

            if (channel is null)
            {
                await context.Reply("You gotta be in a voice channel");

                return;
            }
            switch (serverConfig.VoiceChannelListType)
            {
            case "ALLOW":
                if (!serverConfig.VoiceChannelList.Contains(channel.Id))
                {
                    await context.Reply("You cannot play quotes in that voice channel!");

                    return;
                }
                break;

            case "BLOCK":
                if (serverConfig.VoiceChannelList.Contains(channel.Id))
                {
                    await context.Reply("You cannot play quotes in that voice channel!");

                    return;
                }
                break;

            default:
                break;
            }
            statsService.AddToHistory(context.Guild.Id, new HistoryEntry
            {
                Category   = category,
                NamedAudio = audio,
            });
            await Play(channel, audio.Audio, CancellationToken.None);
        }
コード例 #2
0
        public async Task Deploy(SocketCommandContext context, string[] command, ServerConfig _)
        {
            if (context.User.Id != botOptions.OwnerValue || context.Channel.Id != botOptions.AnnounceChannelValue || command.Length != 2)
            {
                return;
            }
            string endpoint;

            if (command[1].ToLower() == "bot")
            {
                endpoint = "quotebot";
            }
            else if (command[1].ToLower() == "web")
            {
                endpoint = "quotebotweb";
            }
            else
            {
                return;
            }
            var uri = new Uri($"http://host.docker.internal:8080/{endpoint}");

            var response = await httpClient.GetAsync(uri);

            var result = await response.Content.ReadAsStringAsync();

            await context.Reply(result);
        }
コード例 #3
0
ファイル: InfoModule.cs プロジェクト: MatthewManley/QuoteBot
        public async Task Invite(SocketCommandContext context, string[] _0, ServerConfig _1)
        {
            var app = await discordClient.GetApplicationInfoAsync();

            var invite = $"https://discordapp.com/api/oauth2/authorize?client_id={app.Id}&permissions=0&scope=bot";
            await context.Reply(invite);
        }
コード例 #4
0
        private async Task ListAudioForCategory(SocketCommandContext context, string category, int page)
        {
            var sounds = await quoteBotRepo.GetAudioInCategory(context.Guild.Id, category.ToLowerInvariant()).ToList();

            if (sounds.Count == 0)
            {
                await context.Reply("No sounds found for that category.");

                return;
            }
            var       pageMinusOne  = page - 1;
            const int soundsPerPage = 25;
            var       pages         = sounds.Count / soundsPerPage;

            if (pageMinusOne > pages)
            {
                var errorMsg = pages == 0 ?
                               "There is only 1 page" :
                               $"There are only {pages + 1} pages.";
                await context.Reply(errorMsg);

                return;
            }
            IEnumerable <NamedAudio> display = sounds.OrderBy(x => x.AudioOwner.Name);
            var msg = new StringBuilder();

            msg.Append("Total Quotes: ");
            msg.Append(sounds.Count);
            msg.AppendLine();
            if (pages > 0)
            {
                display = display.Skip(soundsPerPage * pageMinusOne).Take(soundsPerPage);
                msg.Append("Page ");
                msg.Append(page);
                msg.Append('/');
                msg.Append(pages + 1);
                msg.AppendLine();
            }
            msg.Append("----------");
            msg.AppendLine();
            foreach (var sound in display)
            {
                msg.Append(sound.AudioOwner.Name);
                msg.AppendLine();
            }
            await context.Reply(msg.ToString());
        }
コード例 #5
0
        private async Task ListCategories(SocketCommandContext context, int page)
        {
            var categories = await quoteBotRepo.GetCategoriesWithAudio(context.Guild.Id).ToList();

            var       pageMinusOne      = page - 1;
            const int categoriesPerPage = 30;
            var       pages             = categories.Count / categoriesPerPage;

            if (pageMinusOne > pages)
            {
                var errorMsg = pages == 0 ?
                               "There is only 1 page." :
                               $"There are only {pages + 1} pages.";
                await context.Reply(errorMsg);

                return;
            }
            IEnumerable <Category> display = categories.OrderBy(x => x.Name);
            bool displayPageHeader         = false;

            if (pages > 0)
            {
                displayPageHeader = true;
                display           = display.Skip(categoriesPerPage * pageMinusOne).Take(categoriesPerPage);
            }
            var msg = new StringBuilder();

            msg.Append("Total Categories: ");
            msg.Append(categories.Count);
            msg.AppendLine();
            if (displayPageHeader)
            {
                msg.Append("Page ");
                msg.Append(page);
                msg.Append('/');
                msg.Append(pages + 1);
                msg.AppendLine();
            }
            msg.Append("----------");
            msg.AppendLine();
            foreach (var category in display)
            {
                msg.Append(category.Name);
                msg.AppendLine();
            }
            await context.Reply(msg.ToString());
        }
コード例 #6
0
ファイル: InfoModule.cs プロジェクト: MatthewManley/QuoteBot
        public async Task Stats(SocketCommandContext context, string[] command, ServerConfig serverConfig)
        {
            var guilds = await discordClient.GetGuildsAsync();

            var builder = new StringBuilder();

            builder.Append("Uptime: ");
            builder.Append(GetUptimeString());
            builder.AppendLine();
            builder.Append("Messages Seen: ");
            builder.Append(statsService.GetSeenMessages());
            builder.AppendLine();
            builder.Append("Server Count: ");
            builder.Append(guilds.Count);
            await context.Reply(builder.ToString());
        }
コード例 #7
0
        public async Task PlaySound(SocketCommandContext context, string[] command, ServerConfig serverConfig)
        {
            // If the bot is already in a voice channel in the server, then don't play a quote
            if (!((context.Guild.CurrentUser as IGuildUser)?.VoiceChannel is null))
            {
                await context.Reply("I am already doing a quote calm down.");

                return;
            }
            var           msgCategory = command[0].ToLowerInvariant();
            IVoiceChannel channel     = null;
            string        msgQuote    = null;

            for (int i = 1; i < command.Length; i++)
            {
                var part = command[i].ToLower();
                if (part.Equals("-c") || part.Equals("--channel"))
                {
                    if (!(channel is null))
                    {
                        await context.Reply("How many voice channels you think I can take at once??? Cause I think its one...");

                        return;
                    }
                    // Error if there is no channel after -c or its not a proper mention
                    if (i + 1 >= command.Length ||
                        !TryGetVoiceChannel(context, command[i + 1], out var voiceChannel))
                    {
                        await context.Reply("Thats ain't no valid voice channel");

                        return;
                    }
                    i++;      // Skip pass the channel id/name
                    channel = voiceChannel;
                    continue; // Continue onto any remaining arguments
                }
                else if (part.Equals("-q") || part.Equals("--quote") || part.Equals("-f") || part.Equals("--file"))
                {
                    if (!(msgQuote is null))
                    {
                        await context.Reply("Don't be greedy, you only get one quote at a time.");

                        return;
                    }
                    if (i + 1 >= command.Length)
                    {
                        await context.Reply("Don't leave me hanging, say what quote you want played.");

                        return;
                    }
                    i++;
                    msgQuote = command[i].ToLower();
                }
                else if (msgQuote is null)
                {
                    msgQuote = part;
                }
                else
                {
                    await context.Reply("You gave me to much stuff. What am i supposed to do with all that?");

                    return;
                }
            }
            channel ??= (context.User as IGuildUser)?.VoiceChannel;
            if (channel is null)
            {
                await context.Reply("You gotta be in a voice channel or use -c channelName");

                return;
            }
            else if (serverConfig.VoiceChannelListType == "BLOCK")
            {
                if (serverConfig.VoiceChannelList.Contains(channel.Id))
                {
                    await context.Reply("You cannot play quotes in that voice channel!");

                    return;
                }
            }
            else if (serverConfig.VoiceChannelListType == "ALLOW")
            {
                if (!serverConfig.VoiceChannelList.Contains(channel.Id))
                {
                    await context.Reply("You cannot play quotes in that voice channel!");

                    return;
                }
            }
            NamedAudio namedAudio;

            if (msgQuote is null)
            {
                namedAudio = await GetRandomAudioForCategory(context.Guild.Id, msgCategory);
            }
            else
            {
                namedAudio = await quoteBotRepo.GetAudio(context.Guild.Id, msgCategory, msgQuote);

                if (namedAudio is null)
                {
                    await context.Reply("That quote don't exist...");

                    return;
                }
            }
            statsService.AddToHistory(context.Guild.Id, new HistoryEntry
            {
                Category = new Category
                {
                    Name = msgCategory
                },
                NamedAudio = namedAudio
            });
            await Play(channel, namedAudio.Audio, CancellationToken.None);
        }
コード例 #8
0
 public async Task History(SocketCommandContext context, string[] _0, ServerConfig _1)
 {
     var history = statsService.GetHistory(context.Guild.Id);
     await context.Reply(string.Join("\n", history.Select(x => $"{x.Category.Name} {x.NamedAudio.AudioOwner.Name}")));
 }
コード例 #9
0
ファイル: InfoModule.cs プロジェクト: MatthewManley/QuoteBot
 public async Task Ping(SocketCommandContext context, string[] command, ServerConfig serverConfig)
 {
     await context.Reply("Pong!");
 }