diff --git a/NadekoBot/Modules/Administration/AdministrationModule.cs b/NadekoBot/Modules/Administration/AdministrationModule.cs index 57a68dc6..922bdc00 100644 --- a/NadekoBot/Modules/Administration/AdministrationModule.cs +++ b/NadekoBot/Modules/Administration/AdministrationModule.cs @@ -6,9 +6,7 @@ using NadekoBot.DataModels; using NadekoBot.Extensions; using NadekoBot.Modules.Administration.Commands; using NadekoBot.Modules.Permissions.Classes; -using Newtonsoft.Json.Linq; using System; -using System.IO; using System.Linq; using System.Threading.Tasks; @@ -37,7 +35,7 @@ namespace NadekoBot.Modules.Administration public override void Install(ModuleManager manager) { - + manager.CreateCommands("", cgb => { @@ -315,6 +313,42 @@ namespace NadekoBot.Modules.Administration } }); + cgb.CreateCommand(Prefix + "sb").Alias(Prefix + "softban") + .Parameter("user", ParameterType.Required) + .Parameter("msg", ParameterType.Optional) + .Description("Bans and then unbans a user by id or name with an optional message.\n**Usage**: .sb \"@some Guy\" Your behaviour is toxic.") + .Do(async e => + { + var msg = e.GetArg("msg"); + var user = e.GetArg("user"); + if (e.User.ServerPermissions.BanMembers) + { + var usr = e.Server.FindUsers(user).FirstOrDefault(); + if (usr == null) + { + await e.Channel.SendMessage("User not found.").ConfigureAwait(false); + return; + } + if (!string.IsNullOrWhiteSpace(msg)) + { + await usr.SendMessage($"**You have been SOFT-BANNED from `{e.Server.Name}` server.**\n" + + $"Reason: {msg}").ConfigureAwait(false); + await Task.Delay(2000).ConfigureAwait(false); // temp solution; give time for a message to be send, fu volt + } + try + { + await e.Server.Ban(usr, 7).ConfigureAwait(false); + await e.Server.Unban(usr).ConfigureAwait(false); + + await e.Channel.SendMessage("Soft-Banned user " + usr.Name + " Id: " + usr.Id).ConfigureAwait(false); + } + catch + { + await e.Channel.SendMessage("Error. Most likely I don't have sufficient permissions.").ConfigureAwait(false); + } + } + }); + cgb.CreateCommand(Prefix + "k").Alias(Prefix + "kick") .Parameter("user") .Parameter("msg", ParameterType.Unparsed) @@ -685,18 +719,6 @@ namespace NadekoBot.Modules.Administration Environment.Exit(0); }); - //cgb.CreateCommand(Prefix + "newnick") - // .Alias(Prefix + "setnick") - // .Description("Give the bot a new nickname. You need manage server permissions.") - // .Parameter("new_nick", ParameterType.Unparsed) - // .AddCheck(SimpleCheckers.ManageServer()) - // .Do(async e => - // { - // if (e.GetArg("new_nick") == null) return; - - // await client.CurrentUser.Edit(NadekoBot.Creds.Password, e.GetArg("new_nick")).ConfigureAwait(false); - // }); - cgb.CreateCommand(Prefix + "newname") .Alias(Prefix + "setname") .Description("Give the bot a new name. **Owner Only!**") @@ -880,21 +902,6 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - cgb.CreateCommand(Prefix + "parsetosql") - .Description("Loads exported parsedata from /data/parsedata/ into sqlite database.") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - await Task.Run(() => - { - SaveParseToDb("data/parsedata/Announcements.json"); - SaveParseToDb("data/parsedata/CommandsRan.json"); - SaveParseToDb("data/parsedata/Requests.json"); - SaveParseToDb("data/parsedata/Stats.json"); - SaveParseToDb("data/parsedata/TypingArticles.json"); - }).ConfigureAwait(false); - }); - cgb.CreateCommand(Prefix + "unstuck") .Description("Clears the message queue. **Owner Only!**") .AddCheck(SimpleCheckers.OwnerOnly()) @@ -917,7 +924,6 @@ namespace NadekoBot.Modules.Administration }).ConfigureAwait(false); }); - //THIS IS INTENTED TO BE USED ONLY BY THE ORIGINAL BOT OWNER cgb.CreateCommand(Prefix + "adddon") .Alias(Prefix + "donadd") .Description("Add a donator to the database.") @@ -1019,19 +1025,5 @@ namespace NadekoBot.Modules.Administration }); } - - public void SaveParseToDb(string where) where T : IDataModel - { - try - { - var data = File.ReadAllText(where); - var arr = JObject.Parse(data)["results"] as JArray; - if (arr == null) - return; - var objects = arr.Select(x => x.ToObject()); - DbHandler.Instance.InsertMany(objects); - } - catch { } - } } } diff --git a/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs b/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs index 1a8ebb52..abcf35e5 100644 --- a/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs +++ b/NadekoBot/Modules/Administration/Commands/MessageRepeater.cs @@ -85,10 +85,12 @@ namespace NadekoBot.Modules.Administration.Commands // if both null, disable if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) { - await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false); + Repeater rep; - if (repeaters.TryRemove(e.Server, out rep)) - rep.MessageTimer.Stop(); + if (!repeaters.TryRemove(e.Server, out rep)) + return; + rep.MessageTimer.Stop(); + await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false); return; } int minutes; diff --git a/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs b/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs index d300e29a..22e0d695 100644 --- a/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs +++ b/NadekoBot/Modules/Administration/Commands/RatelimitCommand.cs @@ -42,15 +42,9 @@ namespace NadekoBot.Modules.Administration.Commands { cgb.CreateCommand(Module.Prefix + "slowmode") .Description("Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds.") - .Parameter("minutes", ParameterType.Optional) .AddCheck(SimpleCheckers.ManageMessages()) .Do(async e => { - //var minutesStr = e.GetArg("minutes"); - //if (string.IsNullOrWhiteSpace(minutesStr)) { - // RatelimitingChannels.Remove(e.Channel.Id); - // return; - //} ConcurrentDictionary throwaway; if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway)) { diff --git a/NadekoBot/Modules/Music/MusicModule.cs b/NadekoBot/Modules/Music/MusicModule.cs index cecf4555..4fcf3a36 100644 --- a/NadekoBot/Modules/Music/MusicModule.cs +++ b/NadekoBot/Modules/Music/MusicModule.cs @@ -23,22 +23,6 @@ namespace NadekoBot.Modules.Music public MusicModule() { - // ready for 1.0 - //NadekoBot.Client.UserUpdated += (s, e) => - //{ - // try - // { - // if (e.Before.VoiceChannel != e.After.VoiceChannel && - // e.Before.VoiceChannel.Members.Count() == 0) - // { - // MusicPlayer musicPlayer; - // if (!MusicPlayers.TryRemove(e.Server, out musicPlayer)) return; - // musicPlayer.Destroy(); - // } - // } - // catch { } - //}; - } public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Music; @@ -129,6 +113,7 @@ namespace NadekoBot.Modules.Music cgb.CreateCommand("lq") .Alias("ls").Alias("lp") .Description("Lists up to 15 currently queued songs.\n**Usage**: `!m lq`") + .Parameter("page", ParameterType.Optional) .Do(async e => { MusicPlayer musicPlayer; @@ -137,6 +122,13 @@ namespace NadekoBot.Modules.Music await e.Channel.SendMessage("🎵 No active music player.").ConfigureAwait(false); return; } + + int page; + if (!int.TryParse(e.GetArg("page"), out page) || page <= 0) + { + page = 1; + } + var currentSong = musicPlayer.CurrentSong; if (currentSong == null) return; @@ -145,13 +137,15 @@ namespace NadekoBot.Modules.Music toSend += "🔂"; else if (musicPlayer.RepeatPlaylist) toSend += "🔁"; - toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued.` "; + toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` "; if (musicPlayer.Playlist.Count >= MusicPlayer.MaximumPlaylistSize) toSend += "**Song queue is full!**\n"; else toSend += "\n"; - var number = 1; - await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); + const int itemsPerPage = 15; + int startAt = itemsPerPage * (page - 1); + var number = 1 + startAt; + await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Skip(startAt).Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); }); cgb.CreateCommand("np") diff --git a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs index eb0e466c..44f311dc 100644 --- a/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs +++ b/NadekoBot/Modules/Translator/Helpers/GoogleTranslator.cs @@ -110,7 +110,8 @@ namespace NadekoBot.Modules.Translator.Helpers } } } - else { + else + { // Translation of phrase text = text.Substring(0, index); text = text.Replace("],[", ","); @@ -180,134 +181,135 @@ namespace NadekoBot.Modules.Translator.Helpers { if (GoogleTranslator._languageModeMap == null) { - GoogleTranslator._languageModeMap = new Dictionary(); - GoogleTranslator._languageModeMap.Add("afrikaans", "af"); - GoogleTranslator._languageModeMap.Add("albanian", "sq"); - GoogleTranslator._languageModeMap.Add("arabic", "ar"); - GoogleTranslator._languageModeMap.Add("armenian", "hy"); - GoogleTranslator._languageModeMap.Add("azerbaijani", "az"); - GoogleTranslator._languageModeMap.Add("basque", "eu"); - GoogleTranslator._languageModeMap.Add("belarusian", "be"); - GoogleTranslator._languageModeMap.Add("bengali", "bn"); - GoogleTranslator._languageModeMap.Add("bulgarian", "bg"); - GoogleTranslator._languageModeMap.Add("catalan", "ca"); - GoogleTranslator._languageModeMap.Add("chinese", "zh-CN"); - GoogleTranslator._languageModeMap.Add("croatian", "hr"); - GoogleTranslator._languageModeMap.Add("czech", "cs"); - GoogleTranslator._languageModeMap.Add("danish", "da"); - GoogleTranslator._languageModeMap.Add("dutch", "nl"); - GoogleTranslator._languageModeMap.Add("english", "en"); - GoogleTranslator._languageModeMap.Add("esperanto", "eo"); - GoogleTranslator._languageModeMap.Add("estonian", "et"); - GoogleTranslator._languageModeMap.Add("filipino", "tl"); - GoogleTranslator._languageModeMap.Add("finnish", "fi"); - GoogleTranslator._languageModeMap.Add("french", "fr"); - GoogleTranslator._languageModeMap.Add("galician", "gl"); - GoogleTranslator._languageModeMap.Add("german", "de"); - GoogleTranslator._languageModeMap.Add("georgian", "ka"); - GoogleTranslator._languageModeMap.Add("greek", "el"); - GoogleTranslator._languageModeMap.Add("haitian Creole", "ht"); - GoogleTranslator._languageModeMap.Add("hebrew", "iw"); - GoogleTranslator._languageModeMap.Add("hindi", "hi"); - GoogleTranslator._languageModeMap.Add("hungarian", "hu"); - GoogleTranslator._languageModeMap.Add("icelandic", "is"); - GoogleTranslator._languageModeMap.Add("indonesian", "id"); - GoogleTranslator._languageModeMap.Add("irish", "ga"); - GoogleTranslator._languageModeMap.Add("italian", "it"); - GoogleTranslator._languageModeMap.Add("japanese", "ja"); - GoogleTranslator._languageModeMap.Add("korean", "ko"); - GoogleTranslator._languageModeMap.Add("lao", "lo"); - GoogleTranslator._languageModeMap.Add("latin", "la"); - GoogleTranslator._languageModeMap.Add("latvian", "lv"); - GoogleTranslator._languageModeMap.Add("lithuanian", "lt"); - GoogleTranslator._languageModeMap.Add("macedonian", "mk"); - GoogleTranslator._languageModeMap.Add("malay", "ms"); - GoogleTranslator._languageModeMap.Add("maltese", "mt"); - GoogleTranslator._languageModeMap.Add("norwegian", "no"); - GoogleTranslator._languageModeMap.Add("persian", "fa"); - GoogleTranslator._languageModeMap.Add("polish", "pl"); - GoogleTranslator._languageModeMap.Add("portuguese", "pt"); - GoogleTranslator._languageModeMap.Add("romanian", "ro"); - GoogleTranslator._languageModeMap.Add("russian", "ru"); - GoogleTranslator._languageModeMap.Add("serbian", "sr"); - GoogleTranslator._languageModeMap.Add("slovak", "sk"); - GoogleTranslator._languageModeMap.Add("slovenian", "sl"); - GoogleTranslator._languageModeMap.Add("spanish", "es"); - GoogleTranslator._languageModeMap.Add("swahili", "sw"); - GoogleTranslator._languageModeMap.Add("swedish", "sv"); - GoogleTranslator._languageModeMap.Add("tamil", "ta"); - GoogleTranslator._languageModeMap.Add("telugu", "te"); - GoogleTranslator._languageModeMap.Add("thai", "th"); - GoogleTranslator._languageModeMap.Add("turkish", "tr"); - GoogleTranslator._languageModeMap.Add("ukrainian", "uk"); - GoogleTranslator._languageModeMap.Add("urdu", "ur"); - GoogleTranslator._languageModeMap.Add("vietnamese", "vi"); - GoogleTranslator._languageModeMap.Add("welsh", "cy"); - GoogleTranslator._languageModeMap.Add("yiddish", "yi"); + GoogleTranslator._languageModeMap = new Dictionary() { + { "afrikaans", "af"}, + { "albanian", "sq"}, + { "arabic", "ar"}, + { "armenian", "hy"}, + { "azerbaijani", "az"}, + { "basque", "eu"}, + { "belarusian", "be"}, + { "bengali", "bn"}, + { "bulgarian", "bg"}, + { "catalan", "ca"}, + { "chinese", "zh-CN"}, + { "croatian", "hr"}, + { "czech", "cs"}, + { "danish", "da"}, + { "dutch", "nl"}, + { "english", "en"}, + { "esperanto", "eo"}, + { "estonian", "et"}, + { "filipino", "tl"}, + { "finnish", "fi"}, + { "french", "fr"}, + { "galician", "gl"}, + { "german", "de"}, + { "georgian", "ka"}, + { "greek", "el"}, + { "haitian Creole", "ht"}, + { "hebrew", "iw"}, + { "hindi", "hi"}, + { "hungarian", "hu"}, + { "icelandic", "is"}, + { "indonesian", "id"}, + { "irish", "ga"}, + { "italian", "it"}, + { "japanese", "ja"}, + { "korean", "ko"}, + { "lao", "lo"}, + { "latin", "la"}, + { "latvian", "lv"}, + { "lithuanian", "lt"}, + { "macedonian", "mk"}, + { "malay", "ms"}, + { "maltese", "mt"}, + { "norwegian", "no"}, + { "persian", "fa"}, + { "polish", "pl"}, + { "portuguese", "pt"}, + { "romanian", "ro"}, + { "russian", "ru"}, + { "serbian", "sr"}, + { "slovak", "sk"}, + { "slovenian", "sl"}, + { "spanish", "es"}, + { "swahili", "sw"}, + { "swedish", "sv"}, + { "tamil", "ta"}, + { "telugu", "te"}, + { "thai", "th"}, + { "turkish", "tr"}, + { "ukrainian", "uk"}, + { "urdu", "ur"}, + { "vietnamese", "vi"}, + { "welsh", "cy"}, + { "yiddish", "yi"}, - GoogleTranslator._languageModeMap.Add("af", "af"); - GoogleTranslator._languageModeMap.Add("sq", "sq"); - GoogleTranslator._languageModeMap.Add("ar", "ar"); - GoogleTranslator._languageModeMap.Add("hy", "hy"); - GoogleTranslator._languageModeMap.Add("az", "az"); - GoogleTranslator._languageModeMap.Add("eu", "eu"); - GoogleTranslator._languageModeMap.Add("be", "be"); - GoogleTranslator._languageModeMap.Add("bn", "bn"); - GoogleTranslator._languageModeMap.Add("bg", "bg"); - GoogleTranslator._languageModeMap.Add("ca", "ca"); - GoogleTranslator._languageModeMap.Add("zh-CN", "zh-CN"); - GoogleTranslator._languageModeMap.Add("hr", "hr"); - GoogleTranslator._languageModeMap.Add("cs", "cs"); - GoogleTranslator._languageModeMap.Add("da", "da"); - GoogleTranslator._languageModeMap.Add("nl", "nl"); - GoogleTranslator._languageModeMap.Add("en", "en"); - GoogleTranslator._languageModeMap.Add("eo", "eo"); - GoogleTranslator._languageModeMap.Add("et", "et"); - GoogleTranslator._languageModeMap.Add("tl", "tl"); - GoogleTranslator._languageModeMap.Add("fi", "fi"); - GoogleTranslator._languageModeMap.Add("fr", "fr"); - GoogleTranslator._languageModeMap.Add("gl", "gl"); - GoogleTranslator._languageModeMap.Add("de", "de"); - GoogleTranslator._languageModeMap.Add("ka", "ka"); - GoogleTranslator._languageModeMap.Add("el", "el"); - GoogleTranslator._languageModeMap.Add("ht", "ht"); - GoogleTranslator._languageModeMap.Add("iw", "iw"); - GoogleTranslator._languageModeMap.Add("hi", "hi"); - GoogleTranslator._languageModeMap.Add("hu", "hu"); - GoogleTranslator._languageModeMap.Add("is", "is"); - GoogleTranslator._languageModeMap.Add("id", "id"); - GoogleTranslator._languageModeMap.Add("ga", "ga"); - GoogleTranslator._languageModeMap.Add("it", "it"); - GoogleTranslator._languageModeMap.Add("ja", "ja"); - GoogleTranslator._languageModeMap.Add("ko", "ko"); - GoogleTranslator._languageModeMap.Add("lo", "lo"); - GoogleTranslator._languageModeMap.Add("la", "la"); - GoogleTranslator._languageModeMap.Add("lv", "lv"); - GoogleTranslator._languageModeMap.Add("lt", "lt"); - GoogleTranslator._languageModeMap.Add("mk", "mk"); - GoogleTranslator._languageModeMap.Add("ms", "ms"); - GoogleTranslator._languageModeMap.Add("mt", "mt"); - GoogleTranslator._languageModeMap.Add("no", "no"); - GoogleTranslator._languageModeMap.Add("fa", "fa"); - GoogleTranslator._languageModeMap.Add("pl", "pl"); - GoogleTranslator._languageModeMap.Add("pt", "pt"); - GoogleTranslator._languageModeMap.Add("ro", "ro"); - GoogleTranslator._languageModeMap.Add("ru", "ru"); - GoogleTranslator._languageModeMap.Add("sr", "sr"); - GoogleTranslator._languageModeMap.Add("sk", "sk"); - GoogleTranslator._languageModeMap.Add("sl", "sl"); - GoogleTranslator._languageModeMap.Add("es", "es"); - GoogleTranslator._languageModeMap.Add("sw", "sw"); - GoogleTranslator._languageModeMap.Add("sv", "sv"); - GoogleTranslator._languageModeMap.Add("ta", "ta"); - GoogleTranslator._languageModeMap.Add("te", "te"); - GoogleTranslator._languageModeMap.Add("th", "th"); - GoogleTranslator._languageModeMap.Add("tr", "tr"); - GoogleTranslator._languageModeMap.Add("uk", "uk"); - GoogleTranslator._languageModeMap.Add("ur", "ur"); - GoogleTranslator._languageModeMap.Add("vi", "vi"); - GoogleTranslator._languageModeMap.Add("cy", "cy"); - GoogleTranslator._languageModeMap.Add("yi", "yi"); + { "af", "af"}, + { "sq", "sq"}, + { "ar", "ar"}, + { "hy", "hy"}, + { "az", "az"}, + { "eu", "eu"}, + { "be", "be"}, + { "bn", "bn"}, + { "bg", "bg"}, + { "ca", "ca"}, + { "zh-CN", "zh-CN"}, + { "hr", "hr"}, + { "cs", "cs"}, + { "da", "da"}, + { "nl", "nl"}, + { "en", "en"}, + { "eo", "eo"}, + { "et", "et"}, + { "tl", "tl"}, + { "fi", "fi"}, + { "fr", "fr"}, + { "gl", "gl"}, + { "de", "de"}, + { "ka", "ka"}, + { "el", "el"}, + { "ht", "ht"}, + { "iw", "iw"}, + { "hi", "hi"}, + { "hu", "hu"}, + { "is", "is"}, + { "id", "id"}, + { "ga", "ga"}, + { "it", "it"}, + { "ja", "ja"}, + { "ko", "ko"}, + { "lo", "lo"}, + { "la", "la"}, + { "lv", "lv"}, + { "lt", "lt"}, + { "mk", "mk"}, + { "ms", "ms"}, + { "mt", "mt"}, + { "no", "no"}, + { "fa", "fa"}, + { "pl", "pl"}, + { "pt", "pt"}, + { "ro", "ro"}, + { "ru", "ru"}, + { "sr", "sr"}, + { "sk", "sk"}, + { "sl", "sl"}, + { "es", "es"}, + { "sw", "sw"}, + { "sv", "sv"}, + { "ta", "ta"}, + { "te", "te"}, + { "th", "th"}, + { "tr", "tr"}, + { "uk", "uk"}, + { "ur", "ur"}, + { "vi", "vi"}, + { "cy", "cy"}, + { "yi", "yi"}, + }; } }