From e62849f9997f402a00c360c09eb4816a1ecde698 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 11 Dec 2015 15:58:25 +0100 Subject: [PATCH] Added randserver command Moved avatar to conversations from searches. --- NadekoBot/Modules/Conversations.cs | 47 ++++++++++++++++++++++++++++-- NadekoBot/Modules/Searches.cs | 13 --------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index ab7f47a6..21eaaa18 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -535,16 +535,59 @@ namespace NadekoBot.Modules i++; } catch (Exception ex) { - Console.WriteLine(ex.ToString()); j++; continue; } } File.WriteAllText("dump.txt", invites); await e.Send($"Got invites for {i} servers and failed to get invites for {j} servers"); - }); + Stopwatch randServerSW = new Stopwatch(); + randServerSW.Start(); + + cgb.CreateCommand("randserver") + .Description("Generates an invite to a random server and prints some stats.") + .Do(async e => + { + if (randServerSW.ElapsedMilliseconds / 1000 < 1800) + { + await e.Send("You have to wait " + (1800 - randServerSW.ElapsedMilliseconds / 1000) + " more seconds to use this function."); + return; + } + randServerSW.Reset(); + while (true) { + var server = client.AllServers.OrderBy(x => rng.Next()).FirstOrDefault(); + if (server == null) + continue; + try + { + var inv = await client.CreateInvite(server, 100, 5); + await e.Send("**Server:** " + server.Name + + "\n**Owner:** " + server.Owner.Name + + "\n**Channels:** " + server.Channels.Count() + + "\n**Total Members:** " + server.Members.Count() + + "\n**Online Members:** " + server.Members.Where(u => u.Status == UserStatus.Online).Count() + + "\n**Invite:** " + inv.Url); + break; + } + catch (Exception) { continue; } + } + }); + + cgb.CreateCommand("av").Alias("avatar") + .Parameter("mention", ParameterType.Required) + .Description("Shows a mentioned person's avatar. **Usage**: ~av @X") + .Do(async e => + { + var usr = client.FindUsers(e.Channel, e.GetArg("mention")).FirstOrDefault(); + if (usr == null) { + await e.Send("Invalid user specified."); + return; + } + string av = usr.AvatarUrl; + await e.Send(Searches.ShortenUrl(av)); + }); //TODO add eval /* diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 08ae033b..ba70fbc6 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -28,19 +28,6 @@ namespace NadekoBot.Modules manager.CreateCommands("",cgb => { - cgb.CreateCommand("~av") - .Parameter("mention", Discord.Commands.ParameterType.Required) - .Description("Shows a mentioned person's avatar. **Usage**: ~av @X") - .Do(async e => - { - if (e.Message.MentionedUsers.Count() == 0) { - await e.Send( "You need to mention a person"); - return; - } - string av = e.Message.MentionedUsers.First().AvatarUrl; - await e.Send( ShortenUrl("http://www.discordapp.com/api/" + av)); - - }); cgb.CreateCommand("~yt") .Parameter("query",Discord.Commands.ParameterType.Unparsed) .Description("Queries youtubes and embeds the first result")