Beispiel #1
0
        public async Task PingCommand([Summary("Use -a here in order to view the latency of all shards.")] string param = null)
        {
            try
            {
                var s = Stopwatch.StartNew();
                var m = await ReplyAsync("getting ping");

                s.Stop();
                var lat = s.ElapsedTicks;
                s.Restart();
                using (var h = new HttpClient())
                    await h.GetAsync("https://status.discordapp.com/", new CancellationTokenSource(timeout).Token);
                s.Stop();



                string description;

                if (param == "-a" || param == "--all")
                {
                    List <string> latencies = new List <string>();

                    foreach (DiscordSocketClient shard in _client.Shards)
                    {
                        if (shard.ShardId == _client.GetShardIdFor(Context.Guild))
                        {
                            latencies.Add($"shard {shard.ShardId + 1}/{_client.Shards.Count} (current shard): **{shard.Latency} ms**");
                        }
                        else
                        {
                            latencies.Add($"shard {shard.ShardId + 1}/{_client.Shards.Count}: **{shard.Latency} ms**");
                        }
                    }

                    description = $"Latencies for all shards: \n{string.Join("\n", latencies)}\nMessage latency: **{lat / 10000d} ms**\nAPI latency: **{s.ElapsedTicks / 10000d} ms**";
                }
                else
                {
                    description = $"Latency for shard {_client.GetShardIdFor(Context.Guild) + 1}/{_client.Shards.Count}: **{_client.GetShardFor(Context.Guild).Latency} ms**\nMessage latency: **{lat / 10000d} ms**\nAPI latency: **{s.ElapsedTicks/10000d} ms**";
                }
                EmbedBuilder embed = new EmbedBuilder()
                                     .WithColor(Color.Orange)
                                     .WithCurrentTimestamp()
                                     .WithDescription(description);

                await m.ModifyAsync(x =>
                {
                    x.Content = "";
                    x.Embed   = embed.Build();
                });
            }
            catch (Exception e)
            {
                await ReplyAsync(embed : (await _misc.GenerateErrorMessage(e)).Build());
            }
        }
Beispiel #2
0
        public async Task CompCmd([Summary("The user whose avatar will be compressed.")] SocketGuildUser user = null, [Summary("The percentage quality desired.")] long quality = 50)
        {
            try
            {
                if (quality < 0 || quality > 100)
                {
                    quality = 50;
                }

                string url;
                if (user == null)
                {
                    url = Context.User.GetAvatarUrl(ImageFormat.Auto, 512);
                }
                else
                {
                    url = user.GetAvatarUrl(ImageFormat.Auto, 512);
                }
                var bmp = await _img.GetBitmapFromUrlAsync(url);

                var path = _img.Compress(bmp, "Jpeg", quality);
                await Context.Channel.SendFileAsync(path);

                File.Delete(path);
            }
            catch (ArgumentException)
            {
                await ReplyAsync("Make sure that the URL is a direct link to an image.");
            }
            catch (Exception e)
            {
                await ReplyAsync(embed : (await _misc.GenerateErrorMessage(e)).Build());
            }
        }
Beispiel #3
0
 public async Task StatsCmd()
 {
     try
     {
         await ReplyAsync(embed : _ms.GetStats().Build());
     }
     catch (Exception e)
     {
         await ReplyAsync(embed : (await _misc.GenerateErrorMessage(e)).Build());
     }
 }
Beispiel #4
0
 public async Task MuteCmd([Summary("The user to mute.")] SocketGuildUser user, [Summary("The timespan to mute the user for.")] TimeSpan timespan, [Summary("The reason to mute the user; may be blank."), Remainder] string reason = null)
 {
     try
     {
         if (await _ms.TryMuteUserAsync(Context.Guild, Context.User as SocketGuildUser, user, timespan, reason))
         {
             await ReplyAsync("Successfully muted user.");
         }
         else
         {
             await ReplyAsync("Failed to mute user. (are they already muted?)");
         }
     }
     catch (Exception e)
     {
         await ReplyAsync(embed : (await _misc.GenerateErrorMessage(e)).Build());
     }
 }
Beispiel #5
0
 public async Task EvalCmd([Summary("The code to evaluate."), Remainder] string code)
 {
     try
     {
         await ReplyAsync(embed : (await _misc.EvaluateAsync(Context, code)).Build());
     }
     catch (System.Net.WebException e) when(e.Message == "The remote server returned an error: (400) Bad Request.")
     {
         await ReplyAsync("Bisoga returned an HTTP 400 error (bad request). Are you doing something shady? :thinking:");
     }
     catch (System.Net.WebException e) when(e.Message == "The remote server returned an error: (413) Payload Too Large.")
     {
         await ReplyAsync("Bisoga returned an HTTP 413 error (payload too large). Are you doing something shady? :thinking:");
     }
     catch (Exception e)
     {
         await ReplyAsync(embed : (await _misc.GenerateErrorMessage(e)).Build());
     }
 }