cleanup + .softban added

This commit is contained in:
Master Kwoth 2016-06-15 16:12:34 +02:00
parent 7e0c8a9fee
commit dada0b64c5
5 changed files with 185 additions and 201 deletions

View File

@ -6,9 +6,7 @@ using NadekoBot.DataModels;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Commands; using NadekoBot.Modules.Administration.Commands;
using NadekoBot.Modules.Permissions.Classes; using NadekoBot.Modules.Permissions.Classes;
using Newtonsoft.Json.Linq;
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -37,7 +35,7 @@ namespace NadekoBot.Modules.Administration
public override void Install(ModuleManager manager) public override void Install(ModuleManager manager)
{ {
manager.CreateCommands("", cgb => 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") cgb.CreateCommand(Prefix + "k").Alias(Prefix + "kick")
.Parameter("user") .Parameter("user")
.Parameter("msg", ParameterType.Unparsed) .Parameter("msg", ParameterType.Unparsed)
@ -685,18 +719,6 @@ namespace NadekoBot.Modules.Administration
Environment.Exit(0); 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") cgb.CreateCommand(Prefix + "newname")
.Alias(Prefix + "setname") .Alias(Prefix + "setname")
.Description("Give the bot a new name. **Owner Only!**") .Description("Give the bot a new name. **Owner Only!**")
@ -880,21 +902,6 @@ namespace NadekoBot.Modules.Administration
}).ConfigureAwait(false); }).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<Announcement>("data/parsedata/Announcements.json");
SaveParseToDb<DataModels.Command>("data/parsedata/CommandsRan.json");
SaveParseToDb<Request>("data/parsedata/Requests.json");
SaveParseToDb<Stats>("data/parsedata/Stats.json");
SaveParseToDb<TypingArticle>("data/parsedata/TypingArticles.json");
}).ConfigureAwait(false);
});
cgb.CreateCommand(Prefix + "unstuck") cgb.CreateCommand(Prefix + "unstuck")
.Description("Clears the message queue. **Owner Only!**") .Description("Clears the message queue. **Owner Only!**")
.AddCheck(SimpleCheckers.OwnerOnly()) .AddCheck(SimpleCheckers.OwnerOnly())
@ -917,7 +924,6 @@ namespace NadekoBot.Modules.Administration
}).ConfigureAwait(false); }).ConfigureAwait(false);
}); });
//THIS IS INTENTED TO BE USED ONLY BY THE ORIGINAL BOT OWNER
cgb.CreateCommand(Prefix + "adddon") cgb.CreateCommand(Prefix + "adddon")
.Alias(Prefix + "donadd") .Alias(Prefix + "donadd")
.Description("Add a donator to the database.") .Description("Add a donator to the database.")
@ -1019,19 +1025,5 @@ namespace NadekoBot.Modules.Administration
}); });
} }
public void SaveParseToDb<T>(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<T>());
DbHandler.Instance.InsertMany(objects);
}
catch { }
}
} }
} }

View File

@ -85,10 +85,12 @@ namespace NadekoBot.Modules.Administration.Commands
// if both null, disable // if both null, disable
if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr)) if (string.IsNullOrWhiteSpace(msg) && string.IsNullOrWhiteSpace(minutesStr))
{ {
await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false);
Repeater rep; Repeater rep;
if (repeaters.TryRemove(e.Server, out rep)) if (!repeaters.TryRemove(e.Server, out rep))
rep.MessageTimer.Stop(); return;
rep.MessageTimer.Stop();
await e.Channel.SendMessage("Repeating disabled").ConfigureAwait(false);
return; return;
} }
int minutes; int minutes;

View File

@ -42,15 +42,9 @@ namespace NadekoBot.Modules.Administration.Commands
{ {
cgb.CreateCommand(Module.Prefix + "slowmode") cgb.CreateCommand(Module.Prefix + "slowmode")
.Description("Toggles slow mode. When ON, users will be able to send only 1 message every 5 seconds.") .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()) .AddCheck(SimpleCheckers.ManageMessages())
.Do(async e => .Do(async e =>
{ {
//var minutesStr = e.GetArg("minutes");
//if (string.IsNullOrWhiteSpace(minutesStr)) {
// RatelimitingChannels.Remove(e.Channel.Id);
// return;
//}
ConcurrentDictionary<ulong, DateTime> throwaway; ConcurrentDictionary<ulong, DateTime> throwaway;
if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway)) if (RatelimitingChannels.TryRemove(e.Channel.Id, out throwaway))
{ {

View File

@ -23,22 +23,6 @@ namespace NadekoBot.Modules.Music
public MusicModule() 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; public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Music;
@ -129,6 +113,7 @@ namespace NadekoBot.Modules.Music
cgb.CreateCommand("lq") cgb.CreateCommand("lq")
.Alias("ls").Alias("lp") .Alias("ls").Alias("lp")
.Description("Lists up to 15 currently queued songs.\n**Usage**: `!m lq`") .Description("Lists up to 15 currently queued songs.\n**Usage**: `!m lq`")
.Parameter("page", ParameterType.Optional)
.Do(async e => .Do(async e =>
{ {
MusicPlayer musicPlayer; MusicPlayer musicPlayer;
@ -137,6 +122,13 @@ namespace NadekoBot.Modules.Music
await e.Channel.SendMessage("🎵 No active music player.").ConfigureAwait(false); await e.Channel.SendMessage("🎵 No active music player.").ConfigureAwait(false);
return; return;
} }
int page;
if (!int.TryParse(e.GetArg("page"), out page) || page <= 0)
{
page = 1;
}
var currentSong = musicPlayer.CurrentSong; var currentSong = musicPlayer.CurrentSong;
if (currentSong == null) if (currentSong == null)
return; return;
@ -145,13 +137,15 @@ namespace NadekoBot.Modules.Music
toSend += "🔂"; toSend += "🔂";
else if (musicPlayer.RepeatPlaylist) else if (musicPlayer.RepeatPlaylist)
toSend += "🔁"; toSend += "🔁";
toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued.` "; toSend += $" **{musicPlayer.Playlist.Count}** `tracks currently queued. Showing page {page}` ";
if (musicPlayer.Playlist.Count >= MusicPlayer.MaximumPlaylistSize) if (musicPlayer.Playlist.Count >= MusicPlayer.MaximumPlaylistSize)
toSend += "**Song queue is full!**\n"; toSend += "**Song queue is full!**\n";
else else
toSend += "\n"; toSend += "\n";
var number = 1; const int itemsPerPage = 15;
await e.Channel.SendMessage(toSend + string.Join("\n", musicPlayer.Playlist.Take(15).Select(v => $"`{number++}.` {v.PrettyName}"))).ConfigureAwait(false); 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") cgb.CreateCommand("np")

View File

@ -110,7 +110,8 @@ namespace NadekoBot.Modules.Translator.Helpers
} }
} }
} }
else { else
{
// Translation of phrase // Translation of phrase
text = text.Substring(0, index); text = text.Substring(0, index);
text = text.Replace("],[", ","); text = text.Replace("],[", ",");
@ -180,134 +181,135 @@ namespace NadekoBot.Modules.Translator.Helpers
{ {
if (GoogleTranslator._languageModeMap == null) if (GoogleTranslator._languageModeMap == null)
{ {
GoogleTranslator._languageModeMap = new Dictionary<string, string>(); GoogleTranslator._languageModeMap = new Dictionary<string, string>() {
GoogleTranslator._languageModeMap.Add("afrikaans", "af"); { "afrikaans", "af"},
GoogleTranslator._languageModeMap.Add("albanian", "sq"); { "albanian", "sq"},
GoogleTranslator._languageModeMap.Add("arabic", "ar"); { "arabic", "ar"},
GoogleTranslator._languageModeMap.Add("armenian", "hy"); { "armenian", "hy"},
GoogleTranslator._languageModeMap.Add("azerbaijani", "az"); { "azerbaijani", "az"},
GoogleTranslator._languageModeMap.Add("basque", "eu"); { "basque", "eu"},
GoogleTranslator._languageModeMap.Add("belarusian", "be"); { "belarusian", "be"},
GoogleTranslator._languageModeMap.Add("bengali", "bn"); { "bengali", "bn"},
GoogleTranslator._languageModeMap.Add("bulgarian", "bg"); { "bulgarian", "bg"},
GoogleTranslator._languageModeMap.Add("catalan", "ca"); { "catalan", "ca"},
GoogleTranslator._languageModeMap.Add("chinese", "zh-CN"); { "chinese", "zh-CN"},
GoogleTranslator._languageModeMap.Add("croatian", "hr"); { "croatian", "hr"},
GoogleTranslator._languageModeMap.Add("czech", "cs"); { "czech", "cs"},
GoogleTranslator._languageModeMap.Add("danish", "da"); { "danish", "da"},
GoogleTranslator._languageModeMap.Add("dutch", "nl"); { "dutch", "nl"},
GoogleTranslator._languageModeMap.Add("english", "en"); { "english", "en"},
GoogleTranslator._languageModeMap.Add("esperanto", "eo"); { "esperanto", "eo"},
GoogleTranslator._languageModeMap.Add("estonian", "et"); { "estonian", "et"},
GoogleTranslator._languageModeMap.Add("filipino", "tl"); { "filipino", "tl"},
GoogleTranslator._languageModeMap.Add("finnish", "fi"); { "finnish", "fi"},
GoogleTranslator._languageModeMap.Add("french", "fr"); { "french", "fr"},
GoogleTranslator._languageModeMap.Add("galician", "gl"); { "galician", "gl"},
GoogleTranslator._languageModeMap.Add("german", "de"); { "german", "de"},
GoogleTranslator._languageModeMap.Add("georgian", "ka"); { "georgian", "ka"},
GoogleTranslator._languageModeMap.Add("greek", "el"); { "greek", "el"},
GoogleTranslator._languageModeMap.Add("haitian Creole", "ht"); { "haitian Creole", "ht"},
GoogleTranslator._languageModeMap.Add("hebrew", "iw"); { "hebrew", "iw"},
GoogleTranslator._languageModeMap.Add("hindi", "hi"); { "hindi", "hi"},
GoogleTranslator._languageModeMap.Add("hungarian", "hu"); { "hungarian", "hu"},
GoogleTranslator._languageModeMap.Add("icelandic", "is"); { "icelandic", "is"},
GoogleTranslator._languageModeMap.Add("indonesian", "id"); { "indonesian", "id"},
GoogleTranslator._languageModeMap.Add("irish", "ga"); { "irish", "ga"},
GoogleTranslator._languageModeMap.Add("italian", "it"); { "italian", "it"},
GoogleTranslator._languageModeMap.Add("japanese", "ja"); { "japanese", "ja"},
GoogleTranslator._languageModeMap.Add("korean", "ko"); { "korean", "ko"},
GoogleTranslator._languageModeMap.Add("lao", "lo"); { "lao", "lo"},
GoogleTranslator._languageModeMap.Add("latin", "la"); { "latin", "la"},
GoogleTranslator._languageModeMap.Add("latvian", "lv"); { "latvian", "lv"},
GoogleTranslator._languageModeMap.Add("lithuanian", "lt"); { "lithuanian", "lt"},
GoogleTranslator._languageModeMap.Add("macedonian", "mk"); { "macedonian", "mk"},
GoogleTranslator._languageModeMap.Add("malay", "ms"); { "malay", "ms"},
GoogleTranslator._languageModeMap.Add("maltese", "mt"); { "maltese", "mt"},
GoogleTranslator._languageModeMap.Add("norwegian", "no"); { "norwegian", "no"},
GoogleTranslator._languageModeMap.Add("persian", "fa"); { "persian", "fa"},
GoogleTranslator._languageModeMap.Add("polish", "pl"); { "polish", "pl"},
GoogleTranslator._languageModeMap.Add("portuguese", "pt"); { "portuguese", "pt"},
GoogleTranslator._languageModeMap.Add("romanian", "ro"); { "romanian", "ro"},
GoogleTranslator._languageModeMap.Add("russian", "ru"); { "russian", "ru"},
GoogleTranslator._languageModeMap.Add("serbian", "sr"); { "serbian", "sr"},
GoogleTranslator._languageModeMap.Add("slovak", "sk"); { "slovak", "sk"},
GoogleTranslator._languageModeMap.Add("slovenian", "sl"); { "slovenian", "sl"},
GoogleTranslator._languageModeMap.Add("spanish", "es"); { "spanish", "es"},
GoogleTranslator._languageModeMap.Add("swahili", "sw"); { "swahili", "sw"},
GoogleTranslator._languageModeMap.Add("swedish", "sv"); { "swedish", "sv"},
GoogleTranslator._languageModeMap.Add("tamil", "ta"); { "tamil", "ta"},
GoogleTranslator._languageModeMap.Add("telugu", "te"); { "telugu", "te"},
GoogleTranslator._languageModeMap.Add("thai", "th"); { "thai", "th"},
GoogleTranslator._languageModeMap.Add("turkish", "tr"); { "turkish", "tr"},
GoogleTranslator._languageModeMap.Add("ukrainian", "uk"); { "ukrainian", "uk"},
GoogleTranslator._languageModeMap.Add("urdu", "ur"); { "urdu", "ur"},
GoogleTranslator._languageModeMap.Add("vietnamese", "vi"); { "vietnamese", "vi"},
GoogleTranslator._languageModeMap.Add("welsh", "cy"); { "welsh", "cy"},
GoogleTranslator._languageModeMap.Add("yiddish", "yi"); { "yiddish", "yi"},
GoogleTranslator._languageModeMap.Add("af", "af"); { "af", "af"},
GoogleTranslator._languageModeMap.Add("sq", "sq"); { "sq", "sq"},
GoogleTranslator._languageModeMap.Add("ar", "ar"); { "ar", "ar"},
GoogleTranslator._languageModeMap.Add("hy", "hy"); { "hy", "hy"},
GoogleTranslator._languageModeMap.Add("az", "az"); { "az", "az"},
GoogleTranslator._languageModeMap.Add("eu", "eu"); { "eu", "eu"},
GoogleTranslator._languageModeMap.Add("be", "be"); { "be", "be"},
GoogleTranslator._languageModeMap.Add("bn", "bn"); { "bn", "bn"},
GoogleTranslator._languageModeMap.Add("bg", "bg"); { "bg", "bg"},
GoogleTranslator._languageModeMap.Add("ca", "ca"); { "ca", "ca"},
GoogleTranslator._languageModeMap.Add("zh-CN", "zh-CN"); { "zh-CN", "zh-CN"},
GoogleTranslator._languageModeMap.Add("hr", "hr"); { "hr", "hr"},
GoogleTranslator._languageModeMap.Add("cs", "cs"); { "cs", "cs"},
GoogleTranslator._languageModeMap.Add("da", "da"); { "da", "da"},
GoogleTranslator._languageModeMap.Add("nl", "nl"); { "nl", "nl"},
GoogleTranslator._languageModeMap.Add("en", "en"); { "en", "en"},
GoogleTranslator._languageModeMap.Add("eo", "eo"); { "eo", "eo"},
GoogleTranslator._languageModeMap.Add("et", "et"); { "et", "et"},
GoogleTranslator._languageModeMap.Add("tl", "tl"); { "tl", "tl"},
GoogleTranslator._languageModeMap.Add("fi", "fi"); { "fi", "fi"},
GoogleTranslator._languageModeMap.Add("fr", "fr"); { "fr", "fr"},
GoogleTranslator._languageModeMap.Add("gl", "gl"); { "gl", "gl"},
GoogleTranslator._languageModeMap.Add("de", "de"); { "de", "de"},
GoogleTranslator._languageModeMap.Add("ka", "ka"); { "ka", "ka"},
GoogleTranslator._languageModeMap.Add("el", "el"); { "el", "el"},
GoogleTranslator._languageModeMap.Add("ht", "ht"); { "ht", "ht"},
GoogleTranslator._languageModeMap.Add("iw", "iw"); { "iw", "iw"},
GoogleTranslator._languageModeMap.Add("hi", "hi"); { "hi", "hi"},
GoogleTranslator._languageModeMap.Add("hu", "hu"); { "hu", "hu"},
GoogleTranslator._languageModeMap.Add("is", "is"); { "is", "is"},
GoogleTranslator._languageModeMap.Add("id", "id"); { "id", "id"},
GoogleTranslator._languageModeMap.Add("ga", "ga"); { "ga", "ga"},
GoogleTranslator._languageModeMap.Add("it", "it"); { "it", "it"},
GoogleTranslator._languageModeMap.Add("ja", "ja"); { "ja", "ja"},
GoogleTranslator._languageModeMap.Add("ko", "ko"); { "ko", "ko"},
GoogleTranslator._languageModeMap.Add("lo", "lo"); { "lo", "lo"},
GoogleTranslator._languageModeMap.Add("la", "la"); { "la", "la"},
GoogleTranslator._languageModeMap.Add("lv", "lv"); { "lv", "lv"},
GoogleTranslator._languageModeMap.Add("lt", "lt"); { "lt", "lt"},
GoogleTranslator._languageModeMap.Add("mk", "mk"); { "mk", "mk"},
GoogleTranslator._languageModeMap.Add("ms", "ms"); { "ms", "ms"},
GoogleTranslator._languageModeMap.Add("mt", "mt"); { "mt", "mt"},
GoogleTranslator._languageModeMap.Add("no", "no"); { "no", "no"},
GoogleTranslator._languageModeMap.Add("fa", "fa"); { "fa", "fa"},
GoogleTranslator._languageModeMap.Add("pl", "pl"); { "pl", "pl"},
GoogleTranslator._languageModeMap.Add("pt", "pt"); { "pt", "pt"},
GoogleTranslator._languageModeMap.Add("ro", "ro"); { "ro", "ro"},
GoogleTranslator._languageModeMap.Add("ru", "ru"); { "ru", "ru"},
GoogleTranslator._languageModeMap.Add("sr", "sr"); { "sr", "sr"},
GoogleTranslator._languageModeMap.Add("sk", "sk"); { "sk", "sk"},
GoogleTranslator._languageModeMap.Add("sl", "sl"); { "sl", "sl"},
GoogleTranslator._languageModeMap.Add("es", "es"); { "es", "es"},
GoogleTranslator._languageModeMap.Add("sw", "sw"); { "sw", "sw"},
GoogleTranslator._languageModeMap.Add("sv", "sv"); { "sv", "sv"},
GoogleTranslator._languageModeMap.Add("ta", "ta"); { "ta", "ta"},
GoogleTranslator._languageModeMap.Add("te", "te"); { "te", "te"},
GoogleTranslator._languageModeMap.Add("th", "th"); { "th", "th"},
GoogleTranslator._languageModeMap.Add("tr", "tr"); { "tr", "tr"},
GoogleTranslator._languageModeMap.Add("uk", "uk"); { "uk", "uk"},
GoogleTranslator._languageModeMap.Add("ur", "ur"); { "ur", "ur"},
GoogleTranslator._languageModeMap.Add("vi", "vi"); { "vi", "vi"},
GoogleTranslator._languageModeMap.Add("cy", "cy"); { "cy", "cy"},
GoogleTranslator._languageModeMap.Add("yi", "yi"); { "yi", "yi"},
};
} }
} }