This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Command("purge")] | |
[Alias("clean")] | |
[Summary("Downloads and removes X messages from the current channel.")] | |
[RequireUserPermission(ChannelPermission.ManageMessages)] | |
[RequireBotPermission(ChannelPermission.ManageMessages)] | |
public async Task PurgeAsync(int amount) | |
{ | |
// Check if the amount provided by the user is positive. | |
if (amount <= 0) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define a static array of paths that we'll choose the image from | |
// we make it static so it isn't reinstantiated unnecessarily each time we run a command from this module | |
private static string[] _imagePaths = new[] { "images/hackerman.jpg", "images/computerman.jpg", "images/polarbear.png" }; | |
[Command("image")] | |
[Alias("picture")] | |
[Summary("Sends a random image.")] | |
public async Task ImageAsync() | |
{ | |
// using a new instance of the Random class we randomize a path with an index from 0 to x - 1, where x is the amount of paths in the array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Command("ping")] | |
[Alias("latency")] | |
[Summary("Shows the websocket connection's latency and time it takes for me send a message.")] | |
public async Task PingAsync() | |
{ | |
// start a new stopwatch to measure the time it takes for us to send a message | |
var sw = Stopwatch.StartNew(); | |
// send the message and store it for later modification | |
var msg = await ReplyAsync($"**Websocket latency**: {Context.Client.Latency}ms\n" + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enumerable.Range(1, 100).Select(x => x % 15 == 0 ? "FizzBuzz" : x % 3 == 0 ? "Fizz" : x % 5 == 0 ? "Buzz" : x.ToString()).ToList().ForEach(Console.WriteLine); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Humanize(this Type type, bool includeNamespace = false) | |
{ | |
// simply return its name | |
if (!type.IsGenericType) | |
return includeNamespace ? $"{type.Namespace}.{type.Name}" : type.Name; | |
// what are you doing | |
if (type.IsNested && type.DeclaringType.IsGenericType) | |
throw new NotImplementedException(); |