From 28563c1f0bf5b787d3803f36eaf1e249d5da974b Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 11:38:06 +0100 Subject: [PATCH 01/12] fixed !!ms on local songs --- src/NadekoBot/Modules/Music/Classes/Song.cs | 4 ++-- src/NadekoBot/Modules/Music/Music.cs | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index 04e49a70..31c92d10 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Modules.Music.Classes public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime; - public string PrettyName => $"**[{SongInfo.Title.TrimTo(65)}]({songUrl})**"; + public string PrettyName => $"**[{SongInfo.Title.TrimTo(65)}]({SongUrl})**"; public string PrettyInfo => $"{MusicPlayer.PrettyVolume} | {PrettyTotalTime} | {PrettyProvider} | {QueuerName}"; @@ -104,7 +104,7 @@ namespace NadekoBot.Modules.Music.Classes } } - private string songUrl { + public string SongUrl { get { switch (SongInfo.ProviderType) { diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 256a1c43..231bcc65 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -512,12 +512,13 @@ namespace NadekoBot.Modules.Music [RequireContext(ContextType.Guild)] public async Task MoveSong([Remainder] string fromto) { + if (string.IsNullOrWhiteSpace(fromto)) + return; MusicPlayer musicPlayer; if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer)) - { return; - } + fromto = fromto?.Trim(); var fromtoArr = fromto.Split('>'); @@ -541,7 +542,7 @@ namespace NadekoBot.Modules.Music var embed = new EmbedBuilder() .WithTitle($"{s.SongInfo.Title.TrimTo(70)}") - .WithUrl($"{s.SongInfo.Query}") + .WithUrl(s.SongUrl) .WithAuthor(eab => eab.WithName("Song Moved").WithIconUrl("https://cdn.discordapp.com/attachments/155726317222887425/258605269972549642/music1.png")) .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) From cf686a20c3afec14dee48162c19f74476ac02121 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 12:05:05 +0100 Subject: [PATCH 02/12] owner channel bugs fixed, you can now see files sent to the bot --- .../Administration/Commands/SelfCommands.cs | 29 +++++++++++--- src/NadekoBot/Services/CommandHandler.cs | 39 +++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs index 0dfb3d0a..89d23094 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfCommands.cs @@ -72,23 +72,42 @@ namespace NadekoBot.Modules.Administration { if (_forwardDMs && ownerChannels.Any()) { - var title = - GetTextStatic("dm_from", NadekoBot.Localization.DefaultCultureInfo, - typeof(Administration).Name.ToLowerInvariant()) + $" [{msg.Author}]({msg.Author.Id})"; + var title = GetTextStatic("dm_from", + NadekoBot.Localization.DefaultCultureInfo, + typeof(Administration).Name.ToLowerInvariant()) + + $" [{msg.Author}]({msg.Author.Id})"; + + var attachamentsTxt = GetTextStatic("attachments", + NadekoBot.Localization.DefaultCultureInfo, + typeof(Administration).Name.ToLowerInvariant()); + + var toSend = msg.Content; + + if (msg.Attachments.Count > 0) + { + toSend += $"\n\n{Format.Code(attachamentsTxt)}:\n" + + string.Join("\n", msg.Attachments.Select(a => a.ProxyUrl)); + } + if (_forwardDMsToAllOwners) { await Task.WhenAll(ownerChannels.Where(ch => ch.Recipient.Id != msg.Author.Id) - .Select(ch => ch.SendConfirmAsync(title, msg.Content))).ConfigureAwait(false); + .Select(ch => ch.SendConfirmAsync(title, toSend))).ConfigureAwait(false); } else { var firstOwnerChannel = ownerChannels.First(); if (firstOwnerChannel.Recipient.Id != msg.Author.Id) - try { await firstOwnerChannel.SendConfirmAsync(title, msg.Content).ConfigureAwait(false); } + { + try + { + await firstOwnerChannel.SendConfirmAsync(title, toSend).ConfigureAwait(false); + } catch { // ignored } + } } } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index a944a21e..2b827191 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -40,7 +40,7 @@ namespace NadekoBot.Services private readonly CommandService _commandService; private readonly Logger _log; - private List ownerChannels { get; set; } + private List ownerChannels { get; set; } = new List(); public event Func CommandExecuted = delegate { return Task.CompletedTask; }; @@ -61,21 +61,36 @@ namespace NadekoBot.Services UsersOnShortCooldown.Clear(); }, null, GlobalCommandsCooldown, GlobalCommandsCooldown); } - public async Task StartHandling() + public Task StartHandling() { - ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users) - .Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id)) - .Distinct(new IGuildUserComparer()) - .Select(async u => { try { return await u.CreateDMChannelAsync(); } catch { return null; } }))) - .Where(ch => ch != null) - .ToList(); + var _ = Task.Run(async () => + { + await Task.Delay(5000).ConfigureAwait(false); + ownerChannels = (await Task.WhenAll(_client.GetGuilds().SelectMany(g => g.Users) + .Where(u => NadekoBot.Credentials.OwnerIds.Contains(u.Id)) + .Distinct(new IGuildUserComparer()) + .Select(async u => + { + try + { + return await u.CreateDMChannelAsync(); + } + catch + { + return null; + } + }))) + .Where(ch => ch != null) + .ToList(); - if (!ownerChannels.Any()) - _log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file."); - else - _log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels."); + if (!ownerChannels.Any()) + _log.Warn("No owner channels created! Make sure you've specified correct OwnerId in the credentials.json file."); + else + _log.Info($"Created {ownerChannels.Count} out of {NadekoBot.Credentials.OwnerIds.Count} owner message channels."); + }); _client.MessageReceived += MessageReceivedHandler; + return Task.CompletedTask; } private async Task TryRunCleverbot(SocketUserMessage usrMsg, IGuild guild) From b588da43e59e2aa043877c3f5fb039eacdb30892 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 13:11:24 +0100 Subject: [PATCH 03/12] !!ap bug fixed --- .../Modules/Music/Classes/SongHandler.cs | 13 +++++--- src/NadekoBot/Modules/Music/Music.cs | 33 ++++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs index f296d2cb..e374279f 100644 --- a/src/NadekoBot/Modules/Music/Classes/SongHandler.cs +++ b/src/NadekoBot/Modules/Music/Classes/SongHandler.cs @@ -6,12 +6,14 @@ using System.Net.Http; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using NLog; using VideoLibrary; namespace NadekoBot.Modules.Music.Classes { public static class SongHandler { + private static readonly Logger _log = LogManager.GetCurrentClassLogger(); public static async Task ResolveSong(string query, MusicType musicType = MusicType.Normal) { if (string.IsNullOrWhiteSpace(query)) @@ -106,7 +108,8 @@ namespace NadekoBot.Modules.Music.Classes } catch (Exception ex) { - Console.WriteLine($"Failed resolving the link.{ex.Message}"); + _log.Warn($"Failed resolving the link.{ex.Message}"); + _log.Warn(ex); return null; } } @@ -137,7 +140,7 @@ namespace NadekoBot.Modules.Music.Classes } catch { - Console.WriteLine($"Failed reading .pls:\n{file}"); + _log.Warn($"Failed reading .pls:\n{file}"); return null; } } @@ -156,7 +159,7 @@ namespace NadekoBot.Modules.Music.Classes } catch { - Console.WriteLine($"Failed reading .m3u:\n{file}"); + _log.Warn($"Failed reading .m3u:\n{file}"); return null; } @@ -172,7 +175,7 @@ namespace NadekoBot.Modules.Music.Classes } catch { - Console.WriteLine($"Failed reading .asx:\n{file}"); + _log.Warn($"Failed reading .asx:\n{file}"); return null; } } @@ -192,7 +195,7 @@ namespace NadekoBot.Modules.Music.Classes } catch { - Console.WriteLine($"Failed reading .xspf:\n{file}"); + _log.Warn($"Failed reading .xspf:\n{file}"); return null; } } diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 231bcc65..4fbc8701 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -14,7 +14,6 @@ using System.Net.Http; using Newtonsoft.Json.Linq; using System.Collections.Generic; using NadekoBot.Services.Database.Models; -using System.Text.RegularExpressions; using System.Threading; namespace NadekoBot.Modules.Music @@ -78,7 +77,10 @@ namespace NadekoBot.Modules.Music } } - catch { } + catch + { + // ignored + } return Task.CompletedTask; } @@ -215,9 +217,8 @@ namespace NadekoBot.Modules.Music .Skip(startAt) .Take(itemsPerPage) .Select(v => $"`{++number}.` {v.PrettyFullName}")); - - if (currentSong != null) - desc = $"`🔊` {currentSong.PrettyFullName}\n\n" + desc; + + desc = $"`🔊` {currentSong.PrettyFullName}\n\n" + desc; if (musicPlayer.RepeatSong) desc = "🔂 Repeating Current Song\n\n" + desc; @@ -862,8 +863,7 @@ namespace NadekoBot.Modules.Music textCh, voiceCh, relatedVideos[new NadekoRandom().Next(0, relatedVideos.Count)], - true, - musicType).ConfigureAwait(false); + true).ConfigureAwait(false); } } catch { } @@ -871,7 +871,11 @@ namespace NadekoBot.Modules.Music mp.OnStarted += async (player, song) => { - try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } + try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } + catch + { + // ignored + } var sender = player as MusicPlayer; if (sender == null) return; @@ -915,7 +919,10 @@ namespace NadekoBot.Modules.Music await mp.OutputTextChannel.EmbedAsync(embed).ConfigureAwait(false); } - catch { } + catch + { + // ignored + } }; return mp; }); @@ -946,10 +953,12 @@ namespace NadekoBot.Modules.Music .WithThumbnailUrl(resolvedSong.Thumbnail) .WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider))) .ConfigureAwait(false); - if (queuedMessage != null) - queuedMessage.DeleteAfter(10); + queuedMessage?.DeleteAfter(10); } - catch { } // if queued message sending fails, don't attempt to delete it + catch + { + // ignored + } // if queued message sending fails, don't attempt to delete it } } } From 40989604e94e5f56e091f3cc42ad40916716f710 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 13:57:01 +0100 Subject: [PATCH 04/12] fixed current time on repeating songs --- src/NadekoBot/Modules/Music/Classes/Song.cs | 95 +++++++++------------ 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/Song.cs b/src/NadekoBot/Modules/Music/Classes/Song.cs index 31c92d10..8a69ec6f 100644 --- a/src/NadekoBot/Modules/Music/Classes/Song.cs +++ b/src/NadekoBot/Modules/Music/Classes/Song.cs @@ -5,12 +5,9 @@ using System; using System.Diagnostics; using System.Diagnostics.Contracts; using System.IO; -using System.Linq; -using System.Net.Http; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using VideoLibrary; using System.Net; namespace NadekoBot.Modules.Music.Classes @@ -32,13 +29,13 @@ namespace NadekoBot.Modules.Music.Classes public string QueuerName { get; set; } public TimeSpan TotalTime { get; set; } = TimeSpan.Zero; - public TimeSpan CurrentTime => TimeSpan.FromSeconds(bytesSent / frameBytes / (1000 / milliseconds)); + public TimeSpan CurrentTime => TimeSpan.FromSeconds(bytesSent / (float)_frameBytes / (1000 / (float)_milliseconds)); - const int milliseconds = 20; - const int samplesPerFrame = (48000 / 1000) * milliseconds; - const int frameBytes = 3840; //16-bit, 2 channels + private const int _milliseconds = 20; + private const int _samplesPerFrame = (48000 / 1000) * _milliseconds; + private const int _frameBytes = 3840; //16-bit, 2 channels - private ulong bytesSent { get; set; } = 0; + private ulong bytesSent { get; set; } //pwetty @@ -65,22 +62,19 @@ namespace NadekoBot.Modules.Music.Classes } } - private string PrettyTotalTime { - get { + public string PrettyTotalTime { + get + { if (TotalTime == TimeSpan.Zero) return "(?)"; - else if (TotalTime == TimeSpan.MaxValue) + if (TotalTime == TimeSpan.MaxValue) return "∞"; - else - { - var time = TotalTime.ToString(@"mm\:ss"); - var hrs = (int)TotalTime.TotalHours; + var time = TotalTime.ToString(@"mm\:ss"); + var hrs = (int)TotalTime.TotalHours; - if (hrs > 0) - return hrs + ":" + time; - else - return time; - } + if (hrs > 0) + return hrs + ":" + time; + return time; } } @@ -89,13 +83,13 @@ namespace NadekoBot.Modules.Music.Classes switch (SongInfo.ProviderType) { case MusicType.Radio: - return $"https://cdn.discordapp.com/attachments/155726317222887425/261850925063340032/1482522097_radio.png"; //test links + return "https://cdn.discordapp.com/attachments/155726317222887425/261850925063340032/1482522097_radio.png"; //test links case MusicType.Normal: //todo have videoid in songinfo from the start var videoId = Regex.Match(SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+"); return $"https://img.youtube.com/vi/{ videoId }/0.jpg"; case MusicType.Local: - return $"https://cdn.discordapp.com/attachments/155726317222887425/261850914783100928/1482522077_music.png"; //test links + return "https://cdn.discordapp.com/attachments/155726317222887425/261850914783100928/1482522077_music.png"; //test links case MusicType.Soundcloud: return SongInfo.AlbumArt; default: @@ -122,36 +116,32 @@ namespace NadekoBot.Modules.Music.Classes } } - private int skipTo = 0; - public int SkipTo { - get { return skipTo; } - set { - skipTo = value; - bytesSent = (ulong)skipTo * 3840 * 50; - } - } + public int SkipTo { get; set; } private readonly Logger _log; public Song(SongInfo songInfo) { - this.SongInfo = songInfo; - this._log = LogManager.GetCurrentClassLogger(); + SongInfo = songInfo; + _log = LogManager.GetCurrentClassLogger(); } public Song Clone() { - var s = new Song(SongInfo); - s.MusicPlayer = MusicPlayer; - s.QueuerName = QueuerName; + var s = new Song(SongInfo) + { + MusicPlayer = MusicPlayer, + QueuerName = QueuerName + }; return s; } public async Task Play(IAudioClient voiceClient, CancellationToken cancelToken) { + bytesSent = (ulong) SkipTo * 3840 * 50; var filename = Path.Combine(Music.MusicDataPath, DateTime.Now.UnixTimestamp().ToString()); - SongBuffer inStream = new SongBuffer(MusicPlayer, filename, SongInfo, skipTo, frameBytes * 100); + var inStream = new SongBuffer(MusicPlayer, filename, SongInfo, SkipTo, _frameBytes * 100); var bufferTask = inStream.BufferSong(cancelToken).ConfigureAwait(false); try @@ -200,22 +190,22 @@ namespace NadekoBot.Modules.Music.Classes var outStream = voiceClient.CreatePCMStream(960); - int nextTime = Environment.TickCount + milliseconds; + int nextTime = Environment.TickCount + _milliseconds; - byte[] buffer = new byte[frameBytes]; + byte[] buffer = new byte[_frameBytes]; while (!cancelToken.IsCancellationRequested && //song canceled for whatever reason !(MusicPlayer.MaxPlaytimeSeconds != 0 && CurrentTime.TotalSeconds >= MusicPlayer.MaxPlaytimeSeconds)) // or exceedded max playtime { //Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------"); var read = await inStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); //await inStream.CopyToAsync(voiceClient.OutputStream); - if (read < frameBytes) + if (read < _frameBytes) _log.Debug("read {0}", read); unchecked { bytesSent += (ulong)read; } - if (read < frameBytes) + if (read < _frameBytes) { if (read == 0) { @@ -231,12 +221,12 @@ namespace NadekoBot.Modules.Music.Classes _log.Warn("Slow connection has disrupted music, waiting a bit for buffer"); await Task.Delay(1000, cancelToken).ConfigureAwait(false); - nextTime = Environment.TickCount + milliseconds; + nextTime = Environment.TickCount + _milliseconds; } else { await Task.Delay(100, cancelToken).ConfigureAwait(false); - nextTime = Environment.TickCount + milliseconds; + nextTime = Environment.TickCount + _milliseconds; } } else @@ -245,16 +235,16 @@ namespace NadekoBot.Modules.Music.Classes else attempt = 0; - while (this.MusicPlayer.Paused) + while (MusicPlayer.Paused) { await Task.Delay(200, cancelToken).ConfigureAwait(false); - nextTime = Environment.TickCount + milliseconds; + nextTime = Environment.TickCount + _milliseconds; } buffer = AdjustVolume(buffer, MusicPlayer.Volume); - if (read != frameBytes) continue; - nextTime = unchecked(nextTime + milliseconds); + if (read != _frameBytes) continue; + nextTime = unchecked(nextTime + _milliseconds); int delayMillis = unchecked(nextTime - Environment.TickCount); if (delayMillis > 0) await Task.Delay(delayMillis, cancelToken).ConfigureAwait(false); @@ -264,8 +254,7 @@ namespace NadekoBot.Modules.Music.Classes finally { await bufferTask; - if (inStream != null) - inStream.Dispose(); + inStream.Dispose(); } } @@ -279,7 +268,7 @@ namespace NadekoBot.Modules.Music.Classes } //aidiakapi ftw - public unsafe static byte[] AdjustVolume(byte[] audioSamples, float volume) + public static unsafe byte[] AdjustVolume(byte[] audioSamples, float volume) { Contract.Requires(audioSamples != null); Contract.Requires(audioSamples.Length % 2 == 0); @@ -289,15 +278,15 @@ namespace NadekoBot.Modules.Music.Classes if (Math.Abs(volume - 1f) < 0.0001f) return audioSamples; // 16-bit precision for the multiplication - int volumeFixed = (int)Math.Round(volume * 65536d); + var volumeFixed = (int)Math.Round(volume * 65536d); - int count = audioSamples.Length / 2; + var count = audioSamples.Length / 2; fixed (byte* srcBytes = audioSamples) { - short* src = (short*)srcBytes; + var src = (short*)srcBytes; - for (int i = count; i != 0; i--, src++) + for (var i = count; i != 0; i--, src++) *src = (short)(((*src) * volumeFixed) >> 16); } From 33bc565571c8f4521a329e9f4228c4c6b274d9f1 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 14:26:32 +0100 Subject: [PATCH 05/12] fixed rare randomcat bug --- src/NadekoBot/Modules/Searches/Searches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index b250e57f..75d82871 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Searches using (var http = new HttpClient()) { var res = JObject.Parse(await http.GetStringAsync("http://www.random.cat/meow").ConfigureAwait(false)); - await Context.Channel.SendMessageAsync(res["file"].ToString()).ConfigureAwait(false); + await Context.Channel.SendMessageAsync(Uri.EscapeUriString(res["file"].ToString())).ConfigureAwait(false); } } From 9f69532d7b72f7132a7d99b0e83caf07dd16fb9f Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 14:43:32 +0100 Subject: [PATCH 06/12] ~g fix --- src/NadekoBot/Modules/Music/Classes/MusicControls.cs | 8 ++++---- src/NadekoBot/Modules/Searches/Searches.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs index 92ca19ae..bf07a508 100644 --- a/src/NadekoBot/Modules/Music/Classes/MusicControls.cs +++ b/src/NadekoBot/Modules/Music/Classes/MusicControls.cs @@ -77,10 +77,10 @@ namespace NadekoBot.Modules.Music.Classes public IVoiceChannel PlaybackVoiceChannel { get; private set; } public ITextChannel OutputTextChannel { get; set; } - private bool destroyed { get; set; } = false; - public bool RepeatSong { get; private set; } = false; - public bool RepeatPlaylist { get; private set; } = false; - public bool Autoplay { get; set; } = false; + private bool destroyed { get; set; } + public bool RepeatSong { get; private set; } + public bool RepeatPlaylist { get; private set; } + public bool Autoplay { get; set; } public uint MaxQueueSize { get; set; } = 0; private ConcurrentQueue actionQueue { get; } = new ConcurrentQueue(); diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 75d82871..670980ea 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -273,7 +273,7 @@ namespace NadekoBot.Modules.Searches var results = elems.Select(elem => { - var aTag = (elem.Children.FirstOrDefault().Children.FirstOrDefault() as IHtmlAnchorElement); //

-> + var aTag = (elem.Children.FirstOrDefault()?.Children.FirstOrDefault() as IHtmlAnchorElement); //

-> var href = aTag?.Href; var name = aTag?.TextContent; if (href == null || name == null) @@ -292,7 +292,7 @@ namespace NadekoBot.Modules.Searches .WithAuthor(eab => eab.WithName("Search For: " + terms.TrimTo(50)) .WithUrl(fullQueryLink) .WithIconUrl("http://i.imgur.com/G46fm8J.png")) - .WithTitle(Context.User.Mention) + .WithTitle(Context.User.ToString()) .WithFooter(efb => efb.WithText(totalResults)); var desc = await Task.WhenAll(results.Select(async res => From eeb9ff93703a03b261a63eb144c260b7462ead65 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 14:53:13 +0100 Subject: [PATCH 07/12] $$$ is smarter, $startevent flowerreaction X - x is number of flowers to award --- .../Modules/Gambling/Commands/CurrencyEvents.cs | 17 ++++++++++------- src/NadekoBot/Modules/Gambling/Gambling.cs | 6 ++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs index 814fb747..d3f04c53 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Gambling switch (e) { case CurrencyEvent.FlowerReaction: - await FlowerReactionEvent(Context).ConfigureAwait(false); + await FlowerReactionEvent(Context, arg).ConfigureAwait(false); break; case CurrencyEvent.SneakyGameStatus: await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false); @@ -115,23 +115,26 @@ namespace NadekoBot.Modules.Gambling return Task.Delay(0); } - public async Task FlowerReactionEvent(CommandContext context) + public async Task FlowerReactionEvent(CommandContext context, int amount) { + if (amount <= 0) + amount = 100; + var title = GetText("flowerreaction_title"); - var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(100.ToString()) + CurrencySign); + var desc = GetText("flowerreaction_desc", "🌸", Format.Bold(amount.ToString()) + CurrencySign); var footer = GetText("flowerreaction_footer", 24); var msg = await context.Channel.SendConfirmAsync(title, desc, footer: footer) .ConfigureAwait(false); - await new FlowerReactionEvent().Start(msg, context); + await new FlowerReactionEvent().Start(msg, context, amount); } } } public abstract class CurrencyEvent { - public abstract Task Start(IUserMessage msg, CommandContext channel); + public abstract Task Start(IUserMessage msg, CommandContext channel, int amount); } public class FlowerReactionEvent : CurrencyEvent @@ -172,7 +175,7 @@ namespace NadekoBot.Modules.Gambling return Task.CompletedTask; } - public override async Task Start(IUserMessage umsg, CommandContext context) + public override async Task Start(IUserMessage umsg, CommandContext context, int amount) { msg = umsg; NadekoBot.Client.MessageDeleted += MessageDeletedEventHandler; @@ -193,7 +196,7 @@ namespace NadekoBot.Modules.Gambling { if (r.Emoji.Name == "🌸" && r.User.IsSpecified && ((DateTime.UtcNow - r.User.Value.CreatedAt).TotalDays > 5) && _flowerReactionAwardedUsers.Add(r.User.Value.Id)) { - await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", 100, false) + await CurrencyHandler.AddCurrencyAsync(r.User.Value, "Flower Reaction Event", amount, false) .ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 6650bee5..acceab4e 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -49,8 +49,10 @@ namespace NadekoBot.Modules.Gambling [Priority(0)] public async Task Cash([Remainder] IUser user = null) { - user = user ?? Context.User; - await ReplyConfirmLocalized("has", Format.Bold(user.ToString()), $"{GetCurrency(user.Id)} {CurrencySign}").ConfigureAwait(false); + if(user == null) + await ConfirmLocalized("has", Format.Bold(Context.User.ToString()), $"{GetCurrency(Context.User.Id)} {CurrencySign}").ConfigureAwait(false); + else + await ReplyConfirmLocalized("has", Format.Bold(user.ToString()), $"{GetCurrency(user.Id)} {CurrencySign}").ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] From d5987f33317598db77304803d6c58d2b2f1bb3b0 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 15:06:44 +0100 Subject: [PATCH 08/12] ../... now support embeds too --- .../Modules/Utility/Commands/QuoteCommands.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs index 8add0707..193acf42 100644 --- a/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/QuoteCommands.cs @@ -8,13 +8,14 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using NadekoBot.DataStructures; namespace NadekoBot.Modules.Utility { public partial class Utility { [Group] - public class QuoteCommands : ModuleBase + public class QuoteCommands : NadekoSubmodule { [NadekoCommand, Usage, Description, Aliases] [RequireContext(ContextType.Guild)] @@ -56,6 +57,17 @@ namespace NadekoBot.Modules.Utility if (quote == null) return; + CREmbed crembed; + if (CREmbed.TryParse(quote.Text, out crembed)) + { + try { await Context.Channel.EmbedAsync(crembed.ToEmbed(), crembed.PlainText ?? "").ConfigureAwait(false); } + catch (Exception ex) + { + _log.Warn("Sending CREmbed failed"); + _log.Warn(ex); + } + return; + } await Context.Channel.SendMessageAsync("📣 " + quote.Text.SanitizeMentions()); } From ffdfd0e84e05f77a5a9cabac2ef5fac91896ec15 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 17 Feb 2017 15:20:28 +0100 Subject: [PATCH 09/12] word and invite filtering work on edited messages too, now --- src/NadekoBot/Services/CommandHandler.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 2b827191..c563586c 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -90,6 +90,27 @@ namespace NadekoBot.Services }); _client.MessageReceived += MessageReceivedHandler; + _client.MessageUpdated += (oldmsg, newMsg) => + { + var ignore = Task.Run(async () => + { + try + { + var usrMsg = newMsg as SocketUserMessage; + var guild = (usrMsg?.Channel as ITextChannel)?.Guild; + + if (guild != null && !await InviteFiltered(guild, usrMsg).ConfigureAwait(false)) + await WordFiltered(guild, usrMsg).ConfigureAwait(false); + + } + catch (Exception ex) + { + _log.Warn(ex); + } + return Task.CompletedTask; + }); + return Task.CompletedTask; + }; return Task.CompletedTask; } From 407df07b52281fc5585a463af41375307e5a23be Mon Sep 17 00:00:00 2001 From: samvaio Date: Fri, 17 Feb 2017 21:38:34 +0530 Subject: [PATCH 10/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62289d80..955a8e80 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![img](https://ci.appveyor.com/api/projects/status/gmu6b3ltc80hr3k9?svg=true) [![Discord](https://discordapp.com/api/guilds/117523346618318850/widget.png)](https://discord.gg/nadekobot) [![Documentation Status](https://readthedocs.org/projects/nadekobot/badge/?version=latest)](http://nadekobot.readthedocs.io/en/latest/?badge=latest) -![nadeko0](https://cdn.discordapp.com/attachments/266240393639755778/281920716809699328/part1.png) +[![nadeko0](https://cdn.discordapp.com/attachments/266240393639755778/281920716809699328/part1.png)](http://nadekobot.xyz) [![nadeko1](https://cdn.discordapp.com/attachments/266240393639755778/281920134967328768/part2.png)](https://discordapp.com/oauth2/authorize?client_id=170254782546575360&scope=bot&permissions=66186303) [![nadeko2](https://cdn.discordapp.com/attachments/266240393639755778/281920161311883264/part3.png)](http://nadekobot.readthedocs.io/en/latest/Commands%20List/) From 9ca376c4fd52f6f35b4be40732b8defdeadfa439 Mon Sep 17 00:00:00 2001 From: Manuel de la Fuente Date: Fri, 17 Feb 2017 14:58:40 -0600 Subject: [PATCH 11/12] Fixed a typo and put the bottom links in a table to look better --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 955a8e80..1a4b64db 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ [![nadeko1](https://cdn.discordapp.com/attachments/266240393639755778/281920134967328768/part2.png)](https://discordapp.com/oauth2/authorize?client_id=170254782546575360&scope=bot&permissions=66186303) [![nadeko2](https://cdn.discordapp.com/attachments/266240393639755778/281920161311883264/part3.png)](http://nadekobot.readthedocs.io/en/latest/Commands%20List/) -##For Update, Help and Guidlines - -`Follow me on twitter for updates. | Join my Discord server if you need help. | Read the Docs for hosting guides.` - -[![twitter](https://cdn.discordapp.com/attachments/155726317222887425/252192520094613504/twiter_banner.JPG)](https://twitter.com/TheNadekoBot) [![discord](https://cdn.discordapp.com/attachments/266240393639755778/281920766490968064/discord.png)](https://discord.gg/nadekobot) [![Wiki](https://cdn.discordapp.com/attachments/266240393639755778/281920793330581506/datcord.png)](http://nadekobot.readthedocs.io/en/latest/) - +##For Update, Help and Guidelines +| [![twitter](https://cdn.discordapp.com/attachments/155726317222887425/252192520094613504/twiter_banner.JPG)](https://twitter.com/TheNadekoBot) | [![discord](https://cdn.discordapp.com/attachments/266240393639755778/281920766490968064/discord.png)](https://discord.gg/nadekobot) | [![Wiki](https://cdn.discordapp.com/attachments/266240393639755778/281920793330581506/datcord.png)](http://nadekobot.readthedocs.io/en/latest/) +|- +| Follow me on Twitter for updates. | Join my Discord server if you need help. | Read the Docs for hosting guides. \ No newline at end of file From cd2642b92113e29aff9f57c650d227d051308a15 Mon Sep 17 00:00:00 2001 From: Manuel de la Fuente Date: Fri, 17 Feb 2017 15:04:03 -0600 Subject: [PATCH 12/12] My bad? (the markdown preview didn't show any error though) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a4b64db..cb00cdc9 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,5 @@ ##For Update, Help and Guidelines | [![twitter](https://cdn.discordapp.com/attachments/155726317222887425/252192520094613504/twiter_banner.JPG)](https://twitter.com/TheNadekoBot) | [![discord](https://cdn.discordapp.com/attachments/266240393639755778/281920766490968064/discord.png)](https://discord.gg/nadekobot) | [![Wiki](https://cdn.discordapp.com/attachments/266240393639755778/281920793330581506/datcord.png)](http://nadekobot.readthedocs.io/en/latest/) -|- -| Follow me on Twitter for updates. | Join my Discord server if you need help. | Read the Docs for hosting guides. \ No newline at end of file +| --- | --- | --- | +| Follow me on Twitter for updates. | Join my Discord server if you need help. | Read the Docs for hosting guides. | \ No newline at end of file