Merge remote-tracking branch 'refs/remotes/Kwoth/1.0' into math
This commit is contained in:
		@@ -23,7 +23,6 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ////todo owner only
 | 
			
		||||
        //[LocalizedCommand, LocalizedDescription, LocalizedSummary]
 | 
			
		||||
        //[RequireContext(ContextType.Guild)]
 | 
			
		||||
@@ -445,6 +444,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
        public async Task Prune(IMessage msg, int count)
 | 
			
		||||
        {
 | 
			
		||||
            var channel = msg.Channel as ITextChannel;
 | 
			
		||||
            await msg.DeleteAsync();
 | 
			
		||||
            while (count > 0)
 | 
			
		||||
            {
 | 
			
		||||
                int limit = (count < 100) ? count : 100;
 | 
			
		||||
@@ -646,7 +646,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            foreach (var role in roles)
 | 
			
		||||
            { 
 | 
			
		||||
                send += $"\n`{role.Name}`\n";
 | 
			
		||||
                send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct());
 | 
			
		||||
                send += string.Join(", ", (await channel.Guild.GetUsersAsync()).Where(u => u.Roles.Contains(role)).Distinct().Select(u=>u.Mention));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            while (send.Length > 2000)
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                {
 | 
			
		||||
                    var channel = imsg.Channel as ITextChannel;
 | 
			
		||||
 | 
			
		||||
                    if (channel == null || await imsg.IsAuthor(_client))
 | 
			
		||||
                    if (channel == null || await imsg.IsAuthor())
 | 
			
		||||
                        return;
 | 
			
		||||
                    ConcurrentDictionary<ulong, DateTime> userTimePair;
 | 
			
		||||
                    if (!RatelimitingChannels.TryGetValue(channel.Id, out userTimePair)) return;
 | 
			
		||||
 
 | 
			
		||||
@@ -196,7 +196,7 @@ namespace NadekoBot.Modules.Gambling
 | 
			
		||||
 | 
			
		||||
                private async Task Client_MessageReceived(IMessage imsg)
 | 
			
		||||
                {
 | 
			
		||||
                    if (await imsg.IsAuthor(NadekoBot.Client) || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
 | 
			
		||||
                    if (await imsg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)
 | 
			
		||||
                        return;
 | 
			
		||||
                    messagesSinceGameStarted++;
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ namespace NadekoBot.Modules.Gambling
 | 
			
		||||
 | 
			
		||||
            role = role ?? channel.Guild.EveryoneRole;
 | 
			
		||||
 | 
			
		||||
            var members = (await role.Members()).Where(u => u.Status == UserStatus.Online);
 | 
			
		||||
            var members = role.Members().Where(u => u.Status == UserStatus.Online);
 | 
			
		||||
            var membersArray = members as IUser[] ?? members.ToArray();
 | 
			
		||||
            var usr = membersArray[new Random().Next(0, membersArray.Length)];
 | 
			
		||||
            await channel.SendMessageAsync($"**Raffled user:** {usr.Username} (id: {usr.Id})").ConfigureAwait(false);
 | 
			
		||||
 
 | 
			
		||||
@@ -73,8 +73,8 @@ namespace NadekoBot.Modules.Searches
 | 
			
		||||
                var channel = imsg.Channel as ITextChannel;
 | 
			
		||||
                using (var http = new HttpClient())
 | 
			
		||||
                {
 | 
			
		||||
                    var response = await http.GetStringAsync("http://tambal.azurewebsites.net/joke/random").ConfigureAwait(false);
 | 
			
		||||
                    await channel.SendMessageAsync("`" + JObject.Parse(response)["joke"].ToString() + "` 😆").ConfigureAwait(false);
 | 
			
		||||
                    var response = await http.GetStringAsync("http://api.icndb.com/jokes/random/").ConfigureAwait(false);
 | 
			
		||||
                    await channel.SendMessageAsync("`" + JObject.Parse(response)["value"]["joke"].ToString() + "` 😆").ConfigureAwait(false);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -59,8 +59,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
 | 
			
		||||
                await channel.SendMessageAsync("No results found for that query.");
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            var shortUrl = await result.ShortenUrl().ConfigureAwait(false);
 | 
			
		||||
            await channel.SendMessageAsync(shortUrl).ConfigureAwait(false);
 | 
			
		||||
            await channel.SendMessageAsync(result).ConfigureAwait(false);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [LocalizedCommand, LocalizedDescription, LocalizedSummary]
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,6 @@ namespace NadekoBot
 | 
			
		||||
                AudioMode = Discord.Audio.AudioMode.Incoming,
 | 
			
		||||
                LargeThreshold = 200,
 | 
			
		||||
                LogLevel = LogSeverity.Warning,
 | 
			
		||||
                MessageCacheSize = 10,
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            //initialize Services
 | 
			
		||||
@@ -105,7 +104,7 @@ namespace NadekoBot
 | 
			
		||||
                }
 | 
			
		||||
                else if (!t.IsSuccess && t.Error != CommandError.UnknownCommand)
 | 
			
		||||
                {
 | 
			
		||||
                    _log.Warn("Command errored!\n\tFull Message: {0}\n\tError:{1}", imsg.Content, t.Error);
 | 
			
		||||
                    _log.Warn("Command errored!\n\tFull Message: {0}\n\tError:{1}", imsg.Content, t.ErrorReason);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ namespace NadekoBot.Services
 | 
			
		||||
        string Token { get; }
 | 
			
		||||
        string GoogleApiKey { get; }
 | 
			
		||||
        ulong[] OwnerIds { get; }
 | 
			
		||||
        IEnumerable<string> MashapeKey { get; }
 | 
			
		||||
        string MashapeKey { get; }
 | 
			
		||||
        string LoLApiKey { get; }
 | 
			
		||||
 | 
			
		||||
        bool IsOwner(IUser u);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
 | 
			
		||||
        public string GoogleApiKey { get; }
 | 
			
		||||
 | 
			
		||||
        public IEnumerable<string> MashapeKey { get; }
 | 
			
		||||
        public string MashapeKey { get; }
 | 
			
		||||
 | 
			
		||||
        public string Token { get; }
 | 
			
		||||
 | 
			
		||||
@@ -35,6 +35,8 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
                Token = cm.Token;
 | 
			
		||||
                OwnerIds = cm.OwnerIds;
 | 
			
		||||
                LoLApiKey = cm.LoLApiKey;
 | 
			
		||||
                GoogleApiKey = cm.GoogleApiKey;
 | 
			
		||||
                MashapeKey = cm.MashapeKey;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
                _log.Fatal("credentials.json is missing. Failed to start.");
 | 
			
		||||
@@ -44,6 +46,8 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
            public string Token { get; set; }
 | 
			
		||||
            public ulong[] OwnerIds { get; set; }
 | 
			
		||||
            public string LoLApiKey { get; set; }
 | 
			
		||||
            public string GoogleApiKey { get; set; }
 | 
			
		||||
            public string MashapeKey { get; set; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,27 +4,12 @@ namespace NadekoBot.Services
 | 
			
		||||
{
 | 
			
		||||
    public class Localization : ILocalization
 | 
			
		||||
    {
 | 
			
		||||
        public string this[string key] {
 | 
			
		||||
            get {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    return Resources.ResponseStrings.ResourceManager.GetString(key);
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception) {
 | 
			
		||||
                    return key;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        public string this[string key] => LoadCommandString(key);
 | 
			
		||||
 | 
			
		||||
        public static string LoadCommandString(string key)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                return Resources.CommandStrings.ResourceManager.GetString(key);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception) {
 | 
			
		||||
                return key;
 | 
			
		||||
            }
 | 
			
		||||
            string toReturn = Resources.CommandStrings.ResourceManager.GetString(key);
 | 
			
		||||
            return string.IsNullOrWhiteSpace(toReturn) ? key : toReturn;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //private static string GetCommandString(string key)
 | 
			
		||||
 
 | 
			
		||||
@@ -22,8 +22,14 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
        }
 | 
			
		||||
        public async Task<IEnumerable<string>> FindPlaylistIdsByKeywordsAsync(string keywords, int count = 1)
 | 
			
		||||
        {
 | 
			
		||||
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(keywords));
 | 
			
		||||
            Contract.Requires<ArgumentOutOfRangeException>(count > 0);
 | 
			
		||||
            //Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(keywords));
 | 
			
		||||
            //Contract.Requires<ArgumentOutOfRangeException>(count > 0);
 | 
			
		||||
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(keywords))
 | 
			
		||||
                throw new ArgumentNullException(nameof(keywords));
 | 
			
		||||
 | 
			
		||||
            if (count <= 0)
 | 
			
		||||
                throw new ArgumentOutOfRangeException(nameof(count));
 | 
			
		||||
 | 
			
		||||
            var match = new Regex("(?:youtu\\.be\\/|list=)(?<id>[\\da-zA-Z\\-_]*)").Match(keywords);
 | 
			
		||||
            if (match.Length > 1)
 | 
			
		||||
@@ -39,8 +45,11 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
 | 
			
		||||
        public async Task<IEnumerable<string>> FindRelatedVideosAsync(string id, int count = 1)
 | 
			
		||||
        {
 | 
			
		||||
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(id));
 | 
			
		||||
            Contract.Requires<ArgumentOutOfRangeException>(count > 0);
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(id))
 | 
			
		||||
                throw new ArgumentNullException(nameof(id));
 | 
			
		||||
 | 
			
		||||
            if (count <= 0)
 | 
			
		||||
                throw new ArgumentOutOfRangeException(nameof(count));
 | 
			
		||||
 | 
			
		||||
            var match = new Regex("(?:youtu\\.be\\/|v=)(?<id>[\\da-zA-Z\\-_]*)").Match(id);
 | 
			
		||||
            if (match.Length > 1)
 | 
			
		||||
@@ -56,8 +65,11 @@ namespace NadekoBot.Services.Impl
 | 
			
		||||
 | 
			
		||||
        public async Task<IEnumerable<string>> FindVideosByKeywordsAsync(string keywords, int count = 1)
 | 
			
		||||
        {
 | 
			
		||||
            Contract.Requires<ArgumentNullException>(!string.IsNullOrWhiteSpace(keywords));
 | 
			
		||||
            Contract.Requires<ArgumentOutOfRangeException>(count > 0);
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(keywords))
 | 
			
		||||
                throw new ArgumentNullException(nameof(keywords));
 | 
			
		||||
 | 
			
		||||
            if (count <= 0)
 | 
			
		||||
                throw new ArgumentOutOfRangeException(nameof(count));
 | 
			
		||||
 | 
			
		||||
            var query = yt.Search.List("snippet");
 | 
			
		||||
            query.MaxResults = count;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,11 +26,11 @@ namespace NadekoBot.Extensions
 | 
			
		||||
        public static async Task<IMessage> Reply(this IMessage msg, string content) => 
 | 
			
		||||
            await msg.Channel.SendMessageAsync(content).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
        public static Task<bool> IsAuthor(this IMessage msg, DiscordSocketClient client) =>
 | 
			
		||||
            Task.FromResult(client.GetCurrentUser().Id == msg.Author.Id);
 | 
			
		||||
        public static Task<bool> IsAuthor(this IMessage msg) =>
 | 
			
		||||
            Task.FromResult(NadekoBot.Client.GetCurrentUser().Id == msg.Author.Id);
 | 
			
		||||
 | 
			
		||||
        public static async Task<IEnumerable<IUser>> Members(this IRole role) =>
 | 
			
		||||
            await role.Members();
 | 
			
		||||
        public static IEnumerable<IUser> Members(this IRole role) =>
 | 
			
		||||
            NadekoBot.Client.GetGuilds().Where(g => g.Id == role.GuildId).FirstOrDefault()?.GetUsers().Where(u => u.Roles.Contains(role)) ?? Enumerable.Empty<IUser>();
 | 
			
		||||
 | 
			
		||||
        public static async Task<IMessage[]> ReplyLong(this IMessage msg, string content, string breakOn = "\n", string addToEnd = "", string addToStart = "")
 | 
			
		||||
        {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user