a bit of cleanup
This commit is contained in:
		@@ -13,7 +13,7 @@ namespace NadekoBot.Modules.Games
 | 
				
			|||||||
    [NadekoModule("Games", ">")]
 | 
					    [NadekoModule("Games", ">")]
 | 
				
			||||||
    public partial class Games : DiscordModule
 | 
					    public partial class Games : DiscordModule
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private static IEnumerable<string> _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text);
 | 
					        private static string[] _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToArray();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
					        [NadekoCommand, Usage, Description, Aliases]
 | 
				
			||||||
@@ -37,7 +37,7 @@ namespace NadekoBot.Modules.Games
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            await Context.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
 | 
					            await Context.Channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
 | 
				
			||||||
                               .AddField(efb => efb.WithName("❓ Question").WithValue(question).WithIsInline(false))
 | 
					                               .AddField(efb => efb.WithName("❓ Question").WithValue(question).WithIsInline(false))
 | 
				
			||||||
                               .AddField(efb => efb.WithName("🎱 8Ball").WithValue(_8BallResponses.Shuffle().FirstOrDefault()).WithIsInline(false)));
 | 
					                               .AddField(efb => efb.WithName("🎱 8Ball").WithValue(_8BallResponses[new NadekoRandom().Next(0, _8BallResponses.Length)]).WithIsInline(false)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
					        [NadekoCommand, Usage, Description, Aliases]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -833,7 +833,14 @@ namespace NadekoBot.Modules.Music
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.ProviderType == MusicType.Normal)
 | 
					                        if (mp.Autoplay && mp.Playlist.Count == 0 && song.SongInfo.ProviderType == MusicType.Normal)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            await QueueSong(await queuer.Guild.GetCurrentUserAsync(), textCh, voiceCh, (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList().Shuffle().FirstOrDefault(), silent, musicType).ConfigureAwait(false);
 | 
					                            var relatedVideos = (await NadekoBot.Google.GetRelatedVideosAsync(song.SongInfo.Query, 4)).ToList();
 | 
				
			||||||
 | 
					                            if(relatedVideos.Count > 0)
 | 
				
			||||||
 | 
					                            await QueueSong(await queuer.Guild.GetCurrentUserAsync(), 
 | 
				
			||||||
 | 
					                                textCh, 
 | 
				
			||||||
 | 
					                                voiceCh, 
 | 
				
			||||||
 | 
					                                relatedVideos[new NadekoRandom().Next(0, relatedVideos.Count)],
 | 
				
			||||||
 | 
					                                silent, 
 | 
				
			||||||
 | 
					                                musicType).ConfigureAwait(false);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    catch { }
 | 
					                    catch { }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -320,10 +320,10 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
                                        .ConfigureAwait(false);
 | 
					                                        .ConfigureAwait(false);
 | 
				
			||||||
                try
 | 
					                try
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var items = JArray.Parse(response).Shuffle().ToList();
 | 
					                    var items = JArray.Parse(response).ToArray();
 | 
				
			||||||
                    if (items == null)
 | 
					                    if (items == null || items.Length == 0)
 | 
				
			||||||
                        throw new KeyNotFoundException("Cannot find a card by that name");
 | 
					                        throw new KeyNotFoundException("Cannot find a card by that name");
 | 
				
			||||||
                    var item = items[0];
 | 
					                    var item = items[new NadekoRandom().Next(0, items.Length)];
 | 
				
			||||||
                    var storeUrl = await NadekoBot.Google.ShortenUrl(item["store_url"].ToString());
 | 
					                    var storeUrl = await NadekoBot.Google.ShortenUrl(item["store_url"].ToString());
 | 
				
			||||||
                    var cost = item["cost"].ToString();
 | 
					                    var cost = item["cost"].ToString();
 | 
				
			||||||
                    var desc = item["text"].ToString();
 | 
					                    var desc = item["text"].ToString();
 | 
				
			||||||
@@ -378,6 +378,8 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
                    if (items == null)
 | 
					                    if (items == null)
 | 
				
			||||||
                        throw new KeyNotFoundException("Cannot find a card by that name");
 | 
					                        throw new KeyNotFoundException("Cannot find a card by that name");
 | 
				
			||||||
                    foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4))
 | 
					                    foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4))
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        await Task.Run(async () =>
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            using (var sr = await http.GetStreamAsync(item["img"].ToString()))
 | 
					                            using (var sr = await http.GetStreamAsync(item["img"].ToString()))
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
@@ -386,6 +388,7 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
                                imgStream.Position = 0;
 | 
					                                imgStream.Position = 0;
 | 
				
			||||||
                                images.Add(new ImageSharp.Image(imgStream));
 | 
					                                images.Add(new ImageSharp.Image(imgStream));
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					                        }).ConfigureAwait(false);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    string msg = null;
 | 
					                    string msg = null;
 | 
				
			||||||
                    if (items.Count > 4)
 | 
					                    if (items.Count > 4)
 | 
				
			||||||
@@ -393,7 +396,7 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
                        msg = "⚠ Found over 4 images. Showing random 4.";
 | 
					                        msg = "⚠ Found over 4 images. Showing random 4.";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    var ms = new MemoryStream();
 | 
					                    var ms = new MemoryStream();
 | 
				
			||||||
                    images.AsEnumerable().Merge().SaveAsPng(ms);
 | 
					                    await Task.Run(() => images.AsEnumerable().Merge().SaveAsPng(ms));
 | 
				
			||||||
                    ms.Position = 0;
 | 
					                    ms.Position = 0;
 | 
				
			||||||
                    await Context.Channel.SendFileAsync(ms, arg + ".png", msg).ConfigureAwait(false);
 | 
					                    await Context.Channel.SendFileAsync(ms, arg + ".png", msg).ConfigureAwait(false);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -93,24 +93,31 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
                var isAdmin = ((IGuildUser)Context.Message.Author).GuildPermissions.Administrator;
 | 
					                var isAdmin = ((IGuildUser)Context.Message.Author).GuildPermissions.Administrator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                keyword = keyword.ToUpperInvariant();
 | 
					                keyword = keyword.ToUpperInvariant();
 | 
				
			||||||
 | 
					                var sucess = false;
 | 
				
			||||||
                string response;
 | 
					                string response;
 | 
				
			||||||
                using (var uow = DbHandler.UnitOfWork())
 | 
					                using (var uow = DbHandler.UnitOfWork())
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var qs = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword);
 | 
					                    var qs = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword)?.Where(elem => isAdmin || elem.AuthorId == Context.Message.Author.Id).ToArray();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (qs == null || !qs.Any())
 | 
					                    if (qs == null || !qs.Any())
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        await Context.Channel.SendErrorAsync("No quotes found.").ConfigureAwait(false);
 | 
					                        sucess = false;
 | 
				
			||||||
                        return;
 | 
					                        response = "No quotes found which you can remove.";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
                    var q = qs.Shuffle().FirstOrDefault(elem => isAdmin || elem.AuthorId == Context.Message.Author.Id);
 | 
					                    {
 | 
				
			||||||
 | 
					                        var q = qs[new NadekoRandom().Next(0, qs.Length)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        uow.Quotes.Remove(q);
 | 
					                        uow.Quotes.Remove(q);
 | 
				
			||||||
                        await uow.CompleteAsync().ConfigureAwait(false);
 | 
					                        await uow.CompleteAsync().ConfigureAwait(false);
 | 
				
			||||||
 | 
					                        sucess = true;
 | 
				
			||||||
                        response = "🗑 **Deleted a random quote.**";
 | 
					                        response = "🗑 **Deleted a random quote.**";
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if(sucess)
 | 
				
			||||||
                    await Context.Channel.SendConfirmAsync(response);
 | 
					                    await Context.Channel.SendConfirmAsync(response);
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                    await Context.Channel.SendErrorAsync(response);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
					            [NadekoCommand, Usage, Description, Aliases]
 | 
				
			||||||
@@ -126,7 +133,7 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
                using (var uow = DbHandler.UnitOfWork())
 | 
					                using (var uow = DbHandler.UnitOfWork())
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var quotes = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword);
 | 
					                    var quotes = uow.Quotes.GetAllQuotesByKeyword(Context.Guild.Id, keyword);
 | 
				
			||||||
 | 
					                    //todo kwoth please don't be complete retard
 | 
				
			||||||
                    uow.Quotes.RemoveRange(quotes.ToArray());//wtf?!
 | 
					                    uow.Quotes.RemoveRange(quotes.ToArray());//wtf?!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    await uow.CompleteAsync();
 | 
					                    await uow.CompleteAsync();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,6 +15,8 @@ using System.Threading;
 | 
				
			|||||||
using ImageSharp;
 | 
					using ImageSharp;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using Newtonsoft.Json;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
 | 
					using Discord.WebSocket;
 | 
				
			||||||
 | 
					using NadekoBot.Services;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace NadekoBot.Modules.Utility
 | 
					namespace NadekoBot.Modules.Utility
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -113,17 +115,25 @@ namespace NadekoBot.Modules.Utility
 | 
				
			|||||||
            game = game.Trim().ToUpperInvariant();
 | 
					            game = game.Trim().ToUpperInvariant();
 | 
				
			||||||
            if (string.IsNullOrWhiteSpace(game))
 | 
					            if (string.IsNullOrWhiteSpace(game))
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            var arr = (await (Context.Channel as IGuildChannel).Guild.GetUsersAsync())
 | 
					
 | 
				
			||||||
 | 
					            var socketGuild = Context.Guild as SocketGuild;
 | 
				
			||||||
 | 
					            if (socketGuild == null) {
 | 
				
			||||||
 | 
					                _log.Warn("Can't cast guild to socket guild.");
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            var rng = new NadekoRandom();
 | 
				
			||||||
 | 
					            var arr = await Task.Run(() => socketGuild.Users
 | 
				
			||||||
                    .Where(u => u.Game?.Name?.ToUpperInvariant() == game)
 | 
					                    .Where(u => u.Game?.Name?.ToUpperInvariant() == game)
 | 
				
			||||||
                    .Select(u => u.Username)
 | 
					                    .Select(u => u.Username)
 | 
				
			||||||
                    .Shuffle()
 | 
					                    .OrderBy(x => rng.Next())
 | 
				
			||||||
                    .Take(60)
 | 
					                    .Take(60)
 | 
				
			||||||
                    .ToList();
 | 
					                    .ToArray()).ConfigureAwait(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            int i = 0;
 | 
					            int i = 0;
 | 
				
			||||||
            if (!arr.Any())
 | 
					            if (arr.Length == 0)
 | 
				
			||||||
                await Context.Channel.SendErrorAsync("Nobody is playing that game.").ConfigureAwait(false);
 | 
					                await Context.Channel.SendErrorAsync("Nobody is playing that game.").ConfigureAwait(false);
 | 
				
			||||||
            else { 
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
                await Context.Channel.SendConfirmAsync("```css\n" + string.Join("\n", arr.GroupBy(item => (i++) / 2)
 | 
					                await Context.Channel.SendConfirmAsync("```css\n" + string.Join("\n", arr.GroupBy(item => (i++) / 2)
 | 
				
			||||||
                                                                                 .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) + "\n```")
 | 
					                                                                                 .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) + "\n```")
 | 
				
			||||||
                                                                                 .ConfigureAwait(false);
 | 
					                                                                                 .ConfigureAwait(false);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8340,7 +8340,7 @@ namespace NadekoBot.Resources {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        ///    Looks up a localized string similar to `{0}voice+text`.
 | 
					        ///    Looks up a localized string similar to `{0}v+t`.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public static string voiceplustext_usage {
 | 
					        public static string voiceplustext_usage {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -340,7 +340,7 @@
 | 
				
			|||||||
    <value>Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless.</value>
 | 
					    <value>Creates a text channel for each voice channel only users in that voice channel can see.If you are server owner, keep in mind you will see them all the time regardless.</value>
 | 
				
			||||||
  </data>
 | 
					  </data>
 | 
				
			||||||
  <data name="voiceplustext_usage" xml:space="preserve">
 | 
					  <data name="voiceplustext_usage" xml:space="preserve">
 | 
				
			||||||
    <value>`{0}voice+text`</value>
 | 
					    <value>`{0}v+t`</value>
 | 
				
			||||||
  </data>
 | 
					  </data>
 | 
				
			||||||
  <data name="scsc_cmd" xml:space="preserve">
 | 
					  <data name="scsc_cmd" xml:space="preserve">
 | 
				
			||||||
    <value>scsc</value>
 | 
					    <value>scsc</value>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user