From 2cf37987281658170cee59263fe971848df46c40 Mon Sep 17 00:00:00 2001 From: skyjoshua Date: Fri, 10 Apr 2026 03:35:42 +0100 Subject: [PATCH] added a few roleplay commands and edited the user-agent text --- SkyBot/Commands/RP/Angry.cs | 2 +- SkyBot/Commands/RP/Baka.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Bite.cs | 2 +- SkyBot/Commands/RP/Blowkiss.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Blush.cs | 2 +- SkyBot/Commands/RP/Bonk.cs | 2 +- SkyBot/Commands/RP/Carry.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Clap.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Cry.cs | 2 +- SkyBot/Commands/RP/Cuddle.cs | 2 +- SkyBot/Commands/RP/Dance.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Facepalm.cs | 2 +- SkyBot/Commands/RP/Happy.cs | 2 +- SkyBot/Commands/RP/Holdhand.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Hug.cs | 2 +- SkyBot/Commands/RP/Kiss.cs | 2 +- SkyBot/Commands/RP/Laugh.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Lurk.cs | 2 +- SkyBot/Commands/RP/Nom.cs | 2 +- SkyBot/Commands/RP/Nya.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Pat.cs | 2 +- SkyBot/Commands/RP/Poke.cs | 2 +- SkyBot/Commands/RP/Pout.cs | 2 +- SkyBot/Commands/RP/Punch.cs | 2 +- SkyBot/Commands/RP/Run.cs | 2 +- SkyBot/Commands/RP/Shocked.cs | 2 +- SkyBot/Commands/RP/Sleep.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Smug.cs | 2 +- SkyBot/Commands/RP/Spin.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Tableflip.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Teehee.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Tickle.cs | 2 +- SkyBot/Commands/RP/Wave.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Wink.cs | 118 ++++++++++++++++++++++++++++++++ SkyBot/Commands/RP/Yawn.cs | 2 +- 35 files changed, 1673 insertions(+), 21 deletions(-) create mode 100644 SkyBot/Commands/RP/Baka.cs create mode 100644 SkyBot/Commands/RP/Blowkiss.cs create mode 100644 SkyBot/Commands/RP/Carry.cs create mode 100644 SkyBot/Commands/RP/Clap.cs create mode 100644 SkyBot/Commands/RP/Dance.cs create mode 100644 SkyBot/Commands/RP/Holdhand.cs create mode 100644 SkyBot/Commands/RP/Laugh.cs create mode 100644 SkyBot/Commands/RP/Nya.cs create mode 100644 SkyBot/Commands/RP/Sleep.cs create mode 100644 SkyBot/Commands/RP/Spin.cs create mode 100644 SkyBot/Commands/RP/Tableflip.cs create mode 100644 SkyBot/Commands/RP/Teehee.cs create mode 100644 SkyBot/Commands/RP/Wave.cs create mode 100644 SkyBot/Commands/RP/Wink.cs diff --git a/SkyBot/Commands/RP/Angry.cs b/SkyBot/Commands/RP/Angry.cs index 9272187..84cd019 100644 --- a/SkyBot/Commands/RP/Angry.cs +++ b/SkyBot/Commands/RP/Angry.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Baka.cs b/SkyBot/Commands/RP/Baka.cs new file mode 100644 index 0000000..6ff0df0 --- /dev/null +++ b/SkyBot/Commands/RP/Baka.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Baka : ICommand + { + public string Name => "baka"; + public string[] Aliases => ["idiot"]; + public string Description => "Call someone a baka with a random gif."; + public string Section => "RP"; + public string Usage => "baka [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/baka"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a baka gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the baka gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "baka.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the baka gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the baka gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} calls {target} a baka!" + : $"{sender} says baka!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "baka.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Bite.cs b/SkyBot/Commands/RP/Bite.cs index a7affd7..dbc9d11 100644 --- a/SkyBot/Commands/RP/Bite.cs +++ b/SkyBot/Commands/RP/Bite.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Blowkiss.cs b/SkyBot/Commands/RP/Blowkiss.cs new file mode 100644 index 0000000..f493026 --- /dev/null +++ b/SkyBot/Commands/RP/Blowkiss.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Blowkiss : ICommand + { + public string Name => "blowkiss"; + public string[] Aliases => []; + public string Description => "Blow a kiss with a random gif."; + public string Section => "RP"; + public string Usage => "blowkiss [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/blowkiss"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a blowkiss gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the blowkiss gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "blowkiss.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the blowkiss gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the blowkiss gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} blows a kiss to {target}!" + : $"{sender} blows a kiss!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "blowkiss.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Blush.cs b/SkyBot/Commands/RP/Blush.cs index 412de44..f7fa414 100644 --- a/SkyBot/Commands/RP/Blush.cs +++ b/SkyBot/Commands/RP/Blush.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Bonk.cs b/SkyBot/Commands/RP/Bonk.cs index e4f50e1..2c4f5f1 100644 --- a/SkyBot/Commands/RP/Bonk.cs +++ b/SkyBot/Commands/RP/Bonk.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Carry.cs b/SkyBot/Commands/RP/Carry.cs new file mode 100644 index 0000000..c8242f7 --- /dev/null +++ b/SkyBot/Commands/RP/Carry.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Carry : ICommand + { + public string Name => "carry"; + public string[] Aliases => []; + public string Description => "Carry someone with a random gif."; + public string Section => "RP"; + public string Usage => "carry [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/carry"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a carry gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the carry gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "carry.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the carry gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the carry gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} carries {target}!" + : $"{sender} wants to carry someone!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "carry.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Clap.cs b/SkyBot/Commands/RP/Clap.cs new file mode 100644 index 0000000..8c4cbc8 --- /dev/null +++ b/SkyBot/Commands/RP/Clap.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Clap : ICommand + { + public string Name => "clap"; + public string[] Aliases => []; + public string Description => "Clap with a random gif."; + public string Section => "RP"; + public string Usage => "clap [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/clap"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a clap gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the clap gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "clap.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the clap gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the clap gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} claps for {target}!" + : $"{sender} is clapping!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "clap.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Cry.cs b/SkyBot/Commands/RP/Cry.cs index b4efccd..acd5d28 100644 --- a/SkyBot/Commands/RP/Cry.cs +++ b/SkyBot/Commands/RP/Cry.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Cuddle.cs b/SkyBot/Commands/RP/Cuddle.cs index 23d39e4..469f5c5 100644 --- a/SkyBot/Commands/RP/Cuddle.cs +++ b/SkyBot/Commands/RP/Cuddle.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Dance.cs b/SkyBot/Commands/RP/Dance.cs new file mode 100644 index 0000000..c23468c --- /dev/null +++ b/SkyBot/Commands/RP/Dance.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Dance : ICommand + { + public string Name => "dance"; + public string[] Aliases => []; + public string Description => "Dance with a random gif."; + public string Section => "RP"; + public string Usage => "dance [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/dance"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a dance gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the dance gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "dance.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the dance gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the dance gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} dances with {target}!" + : $"{sender} is dancing!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "dance.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Facepalm.cs b/SkyBot/Commands/RP/Facepalm.cs index 693e4d3..bd7b93f 100644 --- a/SkyBot/Commands/RP/Facepalm.cs +++ b/SkyBot/Commands/RP/Facepalm.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Happy.cs b/SkyBot/Commands/RP/Happy.cs index 8b66c23..2aa7c8f 100644 --- a/SkyBot/Commands/RP/Happy.cs +++ b/SkyBot/Commands/RP/Happy.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Holdhand.cs b/SkyBot/Commands/RP/Holdhand.cs new file mode 100644 index 0000000..40c5052 --- /dev/null +++ b/SkyBot/Commands/RP/Holdhand.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Holdhand : ICommand + { + public string Name => "holdhand"; + public string[] Aliases => []; + public string Description => "Hold hands with a random gif."; + public string Section => "RP"; + public string Usage => "holdhand [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/handhold"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a handhold gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the handhold gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "handhold.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the handhold gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the handhold gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} holds hands with {target}!" + : $"{sender} wants to hold hands!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "handhold.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Hug.cs b/SkyBot/Commands/RP/Hug.cs index bdd826d..a015b94 100644 --- a/SkyBot/Commands/RP/Hug.cs +++ b/SkyBot/Commands/RP/Hug.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Kiss.cs b/SkyBot/Commands/RP/Kiss.cs index 2c83c2d..8056d2a 100644 --- a/SkyBot/Commands/RP/Kiss.cs +++ b/SkyBot/Commands/RP/Kiss.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Laugh.cs b/SkyBot/Commands/RP/Laugh.cs new file mode 100644 index 0000000..f4e877e --- /dev/null +++ b/SkyBot/Commands/RP/Laugh.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Laugh : ICommand + { + public string Name => "laugh"; + public string[] Aliases => []; + public string Description => "Laugh with a random gif."; + public string Section => "RP"; + public string Usage => "laugh [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/laugh"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a laugh gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the laugh gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "laugh.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the laugh gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the laugh gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} laughs at {target}!" + : $"{sender} is laughing!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "laugh.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Lurk.cs b/SkyBot/Commands/RP/Lurk.cs index b5be608..410e148 100644 --- a/SkyBot/Commands/RP/Lurk.cs +++ b/SkyBot/Commands/RP/Lurk.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Nom.cs b/SkyBot/Commands/RP/Nom.cs index 87be9bd..fadb750 100644 --- a/SkyBot/Commands/RP/Nom.cs +++ b/SkyBot/Commands/RP/Nom.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Nya.cs b/SkyBot/Commands/RP/Nya.cs new file mode 100644 index 0000000..5743eb9 --- /dev/null +++ b/SkyBot/Commands/RP/Nya.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Nya : ICommand + { + public string Name => "nya"; + public string[] Aliases => []; + public string Description => "Nya with a random gif."; + public string Section => "RP"; + public string Usage => "nya [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/nya"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a nya gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the nya gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "nya.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the nya gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the nya gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} nyas at {target}!" + : $"{sender} nyas!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "nya.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Pat.cs b/SkyBot/Commands/RP/Pat.cs index 296aa7b..2668b17 100644 --- a/SkyBot/Commands/RP/Pat.cs +++ b/SkyBot/Commands/RP/Pat.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Poke.cs b/SkyBot/Commands/RP/Poke.cs index 571c975..8aefa5b 100644 --- a/SkyBot/Commands/RP/Poke.cs +++ b/SkyBot/Commands/RP/Poke.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Pout.cs b/SkyBot/Commands/RP/Pout.cs index c8a7c94..39b46ee 100644 --- a/SkyBot/Commands/RP/Pout.cs +++ b/SkyBot/Commands/RP/Pout.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Punch.cs b/SkyBot/Commands/RP/Punch.cs index 3448d02..23412b2 100644 --- a/SkyBot/Commands/RP/Punch.cs +++ b/SkyBot/Commands/RP/Punch.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Run.cs b/SkyBot/Commands/RP/Run.cs index aab30c2..5a2968f 100644 --- a/SkyBot/Commands/RP/Run.cs +++ b/SkyBot/Commands/RP/Run.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Shocked.cs b/SkyBot/Commands/RP/Shocked.cs index 421266a..1a1af34 100644 --- a/SkyBot/Commands/RP/Shocked.cs +++ b/SkyBot/Commands/RP/Shocked.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Sleep.cs b/SkyBot/Commands/RP/Sleep.cs new file mode 100644 index 0000000..d2ec872 --- /dev/null +++ b/SkyBot/Commands/RP/Sleep.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Sleep : ICommand + { + public string Name => "sleep"; + public string[] Aliases => ["eep"]; + public string Description => "Sleep with a random gif."; + public string Section => "RP"; + public string Usage => "sleep [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/sleep"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a sleep gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the sleep gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "sleep.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the sleep gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the sleep gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} falls asleep on {target}!" + : $"{sender} is sleeping! zzz..."; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "sleep.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Smug.cs b/SkyBot/Commands/RP/Smug.cs index bc4c255..db95df1 100644 --- a/SkyBot/Commands/RP/Smug.cs +++ b/SkyBot/Commands/RP/Smug.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Spin.cs b/SkyBot/Commands/RP/Spin.cs new file mode 100644 index 0000000..e4fc856 --- /dev/null +++ b/SkyBot/Commands/RP/Spin.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Spin : ICommand + { + public string Name => "spin"; + public string[] Aliases => []; + public string Description => "Spin with a random gif."; + public string Section => "RP"; + public string Usage => "spin [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/spin"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a spin gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the spin gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "spin.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the spin gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the spin gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} spins {target} around!" + : $"{sender} is spinning!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "spin.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Tableflip.cs b/SkyBot/Commands/RP/Tableflip.cs new file mode 100644 index 0000000..0e78415 --- /dev/null +++ b/SkyBot/Commands/RP/Tableflip.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Tableflip : ICommand + { + public string Name => "tableflip"; + public string[] Aliases => []; + public string Description => "Flip a table with a random gif."; + public string Section => "RP"; + public string Usage => "tableflip [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/tableflip"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a tableflip gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the tableflip gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "tableflip.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the tableflip gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the tableflip gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} flips the table at {target}! (╯°□°)╯︵ ┻━┻" + : $"{sender} flips the table! (╯°□°)╯︵ ┻━┻"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "tableflip.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Teehee.cs b/SkyBot/Commands/RP/Teehee.cs new file mode 100644 index 0000000..abaf004 --- /dev/null +++ b/SkyBot/Commands/RP/Teehee.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Teehee : ICommand + { + public string Name => "teehee"; + public string[] Aliases => ["hehe"]; + public string Description => "Teehee with a random gif."; + public string Section => "RP"; + public string Usage => "teehee [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/teehee"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a teehee gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the teehee gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "teehee.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the teehee gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the teehee gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} teehees at {target}!" + : $"{sender} teehees~"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "teehee.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Tickle.cs b/SkyBot/Commands/RP/Tickle.cs index 0d10cb1..274a318 100644 --- a/SkyBot/Commands/RP/Tickle.cs +++ b/SkyBot/Commands/RP/Tickle.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx) diff --git a/SkyBot/Commands/RP/Wave.cs b/SkyBot/Commands/RP/Wave.cs new file mode 100644 index 0000000..3c63de5 --- /dev/null +++ b/SkyBot/Commands/RP/Wave.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Wave : ICommand + { + public string Name => "wave"; + public string[] Aliases => []; + public string Description => "Wave with a random gif."; + public string Section => "RP"; + public string Usage => "wave [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/wave"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a wave gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the wave gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "wave.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the wave gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the wave gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} waves at {target}!" + : $"{sender} waves!"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "wave.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Wink.cs b/SkyBot/Commands/RP/Wink.cs new file mode 100644 index 0000000..35ef80c --- /dev/null +++ b/SkyBot/Commands/RP/Wink.cs @@ -0,0 +1,118 @@ +using System.Collections.Concurrent; +using System.Text.Json; +using SkyBot.Helpers; +using SkyBot.Models; +using Valour.Sdk.Models; +using Valour.Shared.Models; + +namespace SkyBot.Commands +{ + public class Wink : ICommand + { + public string Name => "wink"; + public string[] Aliases => []; + public string Description => "Wink with a random gif."; + public string Section => "RP"; + public string Usage => "wink [@user]"; + + private static readonly HttpClient _http = new() + { + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } + }; + + public async Task Execute(CommandContext ctx) + { + ConcurrentDictionary channelCache = ctx.ChannelCache; + long channelId = ctx.ChannelId; + + if (!channelCache.TryGetValue(channelId, out var channel)) return; + + await channel.SendIsTyping(); + + string json; + try + { + json = await _http.GetStringAsync("https://nekos.best/api/v2/wink"); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not fetch a wink gif. Try again later."); + return; + } + + using var doc = JsonDocument.Parse(json); + var results = doc.RootElement.GetProperty("results"); + string gifUrl = results[0].GetProperty("url").GetString()!; + + byte[] gifBytes; + try + { + gifBytes = await _http.GetByteArrayAsync(gifUrl); + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not download the wink gif. Try again later."); + return; + } + + int width = 0, height = 0; + if (gifBytes.Length >= 10) + { + width = gifBytes[6] | (gifBytes[7] << 8); + height = gifBytes[8] | (gifBytes[9] << 8); + } + + string cdnUrl; + try + { + using var form = new MultipartFormDataContent(); + using var fileContent = new ByteArrayContent(gifBytes); + fileContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); + form.Add(fileContent, "file", "wink.gif"); + + var uploadResult = await ctx.Planet.Node.PostMultipartDataWithResponse("upload/image", form); + if (!uploadResult.Success) + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the wink gif. Try again later."); + return; + } + cdnUrl = uploadResult.Data!; + } + catch + { + await MessageHelper.ReplyAsync(ctx, channel, "Could not upload the wink gif. Try again later."); + return; + } + + string? target = null; + if (ctx.Message.ReplyToId is not null) + { + var replied = await ctx.Message.FetchReplyMessageAsync(); + if (replied is not null) + { + var author = await replied.FetchAuthorAsync(); + if (author is not null) + target = author.Name; + } + } + if (target is null && ctx.Args.Length > 0) + target = string.Join(" ", ctx.Args); + + string sender = ctx.Member.Nickname ?? ctx.Member.User?.Name ?? "Unknown"; + string text = target is not null + ? $"{sender} winks at {target}! ;)" + : $"{sender} winks! ;)"; + + var attachment = new MessageAttachment(MessageAttachmentType.Image) + { + Location = cdnUrl, + MimeType = "image/gif", + FileName = "wink.gif", + Width = width, + Height = height + }; + + await MessageHelper.ReplyAsync(ctx, channel, text, [attachment]); + } + } +} diff --git a/SkyBot/Commands/RP/Yawn.cs b/SkyBot/Commands/RP/Yawn.cs index edea527..b92be67 100644 --- a/SkyBot/Commands/RP/Yawn.cs +++ b/SkyBot/Commands/RP/Yawn.cs @@ -17,7 +17,7 @@ namespace SkyBot.Commands private static readonly HttpClient _http = new() { - DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0" } } + DefaultRequestHeaders = { { "User-Agent", "SkyBot/1.0 (https://skyjoshua.xyz, https://valour.gg)" } } }; public async Task Execute(CommandContext ctx)