From eb94f61badb9a3b32283a7ee9d68cb676a9080e9 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 07:51:15 +0200 Subject: [PATCH 1/6] Fixed .b and .sb --- src/NadekoBot/Modules/Administration/Administration.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 28a68c1b..80abffda 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -306,11 +306,6 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync("You can't use this command on users with a role higher or equal to yours in the role hierarchy."); return; } - if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Max().Position >= ((IGuildUser)umsg.Author).Roles.Max().Position) - { - await channel.SendMessageAsync("You can't use this command on users with a role higher or equal to yours in the role hierarchy."); - return; - } try { await (await user.CreateDMChannelAsync()).SendMessageAsync($"**You have been BANNED from `{channel.Guild.Name}` server.**\n" + @@ -340,7 +335,7 @@ namespace NadekoBot.Modules.Administration { msg = "No reason provided."; } - if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Max().Position >= ((IGuildUser)umsg.Author).Roles.Max().Position) + if (umsg.Author.Id != user.Guild.OwnerId && user.Roles.Select(r => r.Position).Max() >= ((IGuildUser)umsg.Author).Roles.Select(r => r.Position).Max()) { await channel.SendMessageAsync("You can't use this command on users with a role higher or equal to yours in the role hierarchy."); return; From f82b3633f17d71c0ccebff3e42d2d5bef81ae047 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 09:12:41 +0200 Subject: [PATCH 2/6] Restart removed --- .../Modules/Administration/Administration.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 80abffda..17a74f35 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -121,22 +121,6 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync($"{imsg.Author.Mention} :ok: `Permissions for this server are reset`"); } - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - [OwnerOnly] - public async Task Restart(IUserMessage umsg) - { - var channel = (ITextChannel)umsg.Channel; - - await channel.SendMessageAsync("`Restarting in 2 seconds...`").ConfigureAwait(false); - await Task.Delay(2000).ConfigureAwait(false); - System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo - { - Arguments = "dotnet " + System.Reflection.Assembly.GetEntryAssembly().Location - }); - Environment.Exit(0); - } - [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] [RequirePermission(GuildPermission.Administrator)] From 916612311b77aada972f0e2f879272d7eeae3421 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 13:06:37 +0200 Subject: [PATCH 3/6] Fixed carbonitex data sending, fixed v+t haveing duplicate channels --- .../Commands/VoicePlusTextCommands.cs | 8 +++--- src/NadekoBot/Services/Impl/BotCredentials.cs | 3 +++ src/NadekoBot/Services/Impl/StatsService.cs | 27 +++++++++++++++++++ src/NadekoBot/credentials_example.json | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index d74b7a9f..2779ea6f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -70,7 +70,7 @@ namespace NadekoBot.Modules.Administration var beforeVch = before.VoiceChannel; if (beforeVch != null) { - var textChannel = guild.GetTextChannels().Where(t => t.Name == GetChannelName(beforeVch.Name)).FirstOrDefault(); + var textChannel = guild.GetTextChannels().Where(t => t.Name == GetChannelName(beforeVch.Name).ToLowerInvariant()).FirstOrDefault(); if (textChannel != null) await textChannel.AddPermissionOverwriteAsync(user, new OverwritePermissions(readMessages: PermValue.Deny, @@ -80,11 +80,11 @@ namespace NadekoBot.Modules.Administration if (afterVch != null && guild.AFKChannelId != afterVch.Id) { var textChannel = guild.GetTextChannels() - .Where(t => t.Name == GetChannelName(afterVch.Name)) + .Where(t => t.Name == GetChannelName(afterVch.Name).ToLowerInvariant()) .FirstOrDefault(); if (textChannel == null) { - textChannel = (await guild.CreateTextChannelAsync(GetChannelName(afterVch.Name)).ConfigureAwait(false)); + textChannel = (await guild.CreateTextChannelAsync(GetChannelName(afterVch.Name).ToLowerInvariant()).ConfigureAwait(false)); await textChannel.AddPermissionOverwriteAsync(guild.EveryoneRole, new OverwritePermissions(readMessages: PermValue.Deny, sendMessages: PermValue.Deny)).ConfigureAwait(false); @@ -163,7 +163,7 @@ namespace NadekoBot.Modules.Administration } var allTxtChannels = guild.GetTextChannels().Where(c => c.Name.EndsWith("-voice")); - var validTxtChannelNames = guild.GetVoiceChannels().Select(c => GetChannelName(c.Name)); + var validTxtChannelNames = guild.GetVoiceChannels().Select(c => GetChannelName(c.Name).ToLowerInvariant()); var invalidTxtChannels = allTxtChannels.Where(c => !validTxtChannelNames.Contains(c.Name)); diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index a37e4a05..d52e8ad7 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -29,6 +29,7 @@ namespace NadekoBot.Services.Impl public DB Db { get; } public int TotalShards { get; } + public string CarbonKey { get; } public BotCredentials() { @@ -48,6 +49,7 @@ namespace NadekoBot.Services.Impl BotId = cm.BotId ?? cm.ClientId; ClientId = cm.ClientId; SoundCloudClientId = cm.SoundCloudClientId; + CarbonKey = cm.CarbonKey; if (cm.Db == null) Db = new DB("sqlite", ""); else @@ -72,6 +74,7 @@ namespace NadekoBot.Services.Impl public string MashapeKey { get; set; } = ""; public string OsuApiKey { get; set; } = ""; public string SoundCloudClientId { get; set; } = ""; + public string CarbonKey { get; set; } = ""; public DB Db { get; set; } public int TotalShards { get; set; } = 1; } diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 6a5c12c6..ea80f41d 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net.Http; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace NadekoBot.Services.Impl @@ -21,6 +23,8 @@ namespace NadekoBot.Services.Impl public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2).ToString(); + Timer carbonitexTimer { get; } + public StatsService(ShardedDiscordClient client, CommandHandler cmdHandler) { @@ -32,6 +36,29 @@ namespace NadekoBot.Services.Impl cmdHandler.CommandExecuted += (_, e) => commandsRan++; this.client.Disconnected += _ => Reset(); + + this.carbonitexTimer = new Timer(async (state) => + { + if (string.IsNullOrWhiteSpace(NadekoBot.Credentials.CarbonKey)) + return; + try + { + using (var http = new HttpClient()) + { + using (var content = new FormUrlEncodedContent( + new Dictionary { + { "servercount", this.client.GetGuilds().Count.ToString() }, + { "key", NadekoBot.Credentials.CarbonKey }})) + { + content.Headers.Clear(); + content.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); + + var res = await http.PostAsync("https://www.carbonitex.net/discord/data/botdata.php", content).ConfigureAwait(false); + } + }; + } + catch { } + }, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); } public async Task Print() { diff --git a/src/NadekoBot/credentials_example.json b/src/NadekoBot/credentials_example.json index 31a9414f..34925301 100644 --- a/src/NadekoBot/credentials_example.json +++ b/src/NadekoBot/credentials_example.json @@ -10,6 +10,7 @@ "MashapeKey": "", "OsuApiKey": "", "SoundCloudClientId": "", + "CarbonKey": "", "Db": null, "TotalShards": 1 } \ No newline at end of file From e0c7ffa13a207883c8451abfc5f8b48b82040fdd Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 13:10:05 +0200 Subject: [PATCH 4/6] Clarification --- .../Commands/VoicePlusTextCommands.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index 2779ea6f..f132396d 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -117,9 +117,19 @@ namespace NadekoBot.Modules.Administration var botUser = guild.GetCurrentUser(); if (!botUser.GuildPermissions.ManageRoles || !botUser.GuildPermissions.ManageChannels) { - await channel.SendMessageAsync(":anger: `I require manage roles and manage channels permissions to enable this feature.`"); + await channel.SendMessageAsync(":anger: `I require atleast manage roles and manage channels permissions to enable this feature (preffered Administration permission).`"); return; } + + if (!botUser.GuildPermissions.Administrator) + { + try + { + await channel.SendMessageAsync(":warning: `You are enabling this feature and I do not have ADMINISTRATOR permissions, " + + "this may cause some issues, and you will have to clean up text channels yourself afterwards.`"); + } + catch { ]} + } try { bool isEnabled; @@ -156,9 +166,9 @@ namespace NadekoBot.Modules.Administration { var channel = (ITextChannel)msg.Channel; var guild = channel.Guild; - if (!guild.GetCurrentUser().GuildPermissions.ManageChannels) + if (!guild.GetCurrentUser().GuildPermissions.Administrator) { - await channel.SendMessageAsync("`I have insufficient permission to do that.`").ConfigureAwait(false); + await channel.SendMessageAsync("`I need Administrator permission to do that.`").ConfigureAwait(false); return; } From a17ddf199142adc7c39afeec813568ff7ea6b1c4 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 13:10:55 +0200 Subject: [PATCH 5/6] typo --- .../Modules/Administration/Commands/VoicePlusTextCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs index f132396d..d9451afc 100644 --- a/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/VoicePlusTextCommands.cs @@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration await channel.SendMessageAsync(":warning: `You are enabling this feature and I do not have ADMINISTRATOR permissions, " + "this may cause some issues, and you will have to clean up text channels yourself afterwards.`"); } - catch { ]} + catch { } } try { From a4642c59fe43c7e828540dc26050295ab402762b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 25 Oct 2016 13:29:09 +0200 Subject: [PATCH 6/6] !!sh should be fixed --- src/NadekoBot/Modules/Music/Classes/MusicControls.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index a918fc11..53a2c736 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -188,7 +188,9 @@ namespace NadekoBot.Modules.Music.Classes { actionQueue.Enqueue(() => { - playlist.Shuffle(); + var oldPlaylist = playlist.ToArray(); + playlist.Clear(); + playlist.AddRange(oldPlaylist.Shuffle()); }); }