This commit is contained in:
HIDEN64 2023-05-25 00:41:26 -05:00
parent 0b1c981268
commit 9e6e9801fc
14 changed files with 257 additions and 182 deletions

2
.gitignore vendored
View File

@ -349,7 +349,7 @@ healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# WinBot stuff
# HBot stuff
WorkingDirectory/
# VSCode

View File

@ -29,7 +29,7 @@ using ImageMagick;
namespace HBot {
class Bot {
public const string VERSION = "1.8.0";
public const string VERSION = "1.8.1";
public static void Main(string[] args) => new Bot().RunBot().GetAwaiter().GetResult();
@ -130,7 +130,7 @@ namespace HBot {
// If git pull is successful, tell the user to rebuild
if (process.ExitCode == 0) {
Log.Information("Update successful. Please rebuild and restart the bot.");
Log.Warning("Update successful. Please rebuild and restart the bot.");
}
else {

View File

@ -14,14 +14,14 @@ namespace HBot.Commands.Fun {
[Description("Hack into the mainframes... just kidding; Hack into Toxidation's network.")]
[Usage("[length]")]
[Category(Category.Fun)]
public async Task Hackerman(CommandContext Context, int length = 6)
{
public async Task Hackerman(CommandContext Context, int length = 6) {
Random r = new Random();
if(length < 6)
throw new Exception("Length must be greater than or equal to 6");
else if(length > 100)
if(length < 6) {
throw new Exception("Length must be greater than or equal to 6");
}
else if(length > 100) {
throw new Exception("Length must be less than 100");
}
// Generate pure nonsense
string jargon = actions[r.Next(0, actions.Length)];
for(int i = 0; i < length; i++) {
@ -49,7 +49,7 @@ namespace HBot.Commands.Fun {
static string[] actions = new string[] {
"I've hacked into your ", "I'm breaking into the ", "I've hacked the ", "I've gained effective root access to your ",
"I'm gaining root access to ", "I've hacked into the ", "I broke into the "
"I'm gaining root access to ", "I've hacked into the ", "I broke into the ", "I have inflitrated the "
};
}
}

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -10,10 +10,8 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class MagikCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class MagikCommand : BaseCommandModule {
// This is just a hacky way to avoid having to change ImageArgs scale to a float
// while still allowing the -scaleup option to exist with decimal increments
static float scale = 1.0f;
@ -22,20 +20,30 @@ namespace HBot.Commands.Images
[Description("Really mess up an image")]
[Usage("[image] [-scale=(1-5) -layers=(1-3) -gif -size=25]")]
[Category(Category.Images)]
public async Task Magik(CommandContext Context, [RemainingText]string input)
{
public async Task Magik(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
if(args.layers > 3)
if(args.layers > 3) {
args.layers = 3;
else if(args.scale > 5)
}
else if(args.scale > 5) {
args.scale = 5;
}
scale = args.scale;
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-magikDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -43,21 +51,25 @@ namespace HBot.Commands.Images
MagickImage img = null;
MagickImageCollection gif = null;
bool scaleup = false;
if(!string.IsNullOrWhiteSpace(args.textArg))
if(!string.IsNullOrWhiteSpace(args.textArg)) {
scaleup = args.textArg.ToLower() == "-scaleup";
}
if(args.extension.ToLower() != "gif") {
img = new MagickImage(tempImgFile);
if(string.IsNullOrWhiteSpace(args.textArg))
if(string.IsNullOrWhiteSpace(args.textArg)) {
DoMagik(img, args);
}
else if(args.textArg.ToLower() == "-gif" || scaleup) { // We're turning the image into a gif
gif = new MagickImageCollection();
// Default to 25 frames
if(args.size == 1)
if(args.size == 1) {
args.size = 25;
else if(args.size > 64)
}
else if(args.size > 64) {
throw new System.Exception("New gif size must not exceed 64 frames!");
}
// Create args.size frames with slightly different magik applied to each
for(int i = 0; i < args.size; i++) {
@ -69,10 +81,12 @@ namespace HBot.Commands.Images
DoMagik(frame, args);
// Resize the frame to the size of the first magik'd frame
if(i != 0)
if(i != 0) {
frame.Resize(gif[0].Width, gif[0].Height);
if(scaleup)
}
if(scaleup) {
scale+=0.05f;
}
gif.Add(frame);
}
}
@ -82,22 +96,26 @@ namespace HBot.Commands.Images
foreach(var frame in gif) {
DoMagik((MagickImage)frame, args);
frame.Resize(gif[0].Width, gif[0].Height);
if(scaleup)
if(scaleup) {
scale+=0.05f;
}
}
}
TempManager.RemoveTempFile(seed+"-magikDL."+args.extension);
// Change the extension to gif if we turned an image into a gif
if(!string.IsNullOrWhiteSpace(args.textArg) && (args.textArg.ToLower() == "-gif" || scaleup))
if(!string.IsNullOrWhiteSpace(args.textArg) && (args.textArg.ToLower() == "-gif" || scaleup)) {
args.extension = "gif";
}
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream, MagickFormat.Gif);
}
imgStream.Position = 0;
// Send the image
@ -106,8 +124,7 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
public static void DoMagik(MagickImage img, ImageArgs args)
{
public static void DoMagik(MagickImage img, ImageArgs args) {
img.Scale(img.Width/2, img.Height/2);
args.extension = img.Format.ToString().ToLower();
for(int i = 0; i < args.layers; i++) {

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -11,16 +11,13 @@ using static HBot.Util.ResourceManager;
using ImageMagick;
namespace HBot.Commands.Images
{
public class OverlayCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class OverlayCommand : BaseCommandModule {
[Command("overlay")]
[Description("Add an overlay to an image")]
[Usage("[image] [overlay (mehdi, northkorea, usa, ussr, lgbt, norton)]")]
[Category(Category.Images)]
public async Task Overlay(CommandContext Context, [RemainingText]string input)
{
public async Task Overlay(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
@ -28,7 +25,16 @@ namespace HBot.Commands.Images
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-overlayDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -51,10 +57,12 @@ namespace HBot.Commands.Images
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
@ -63,15 +71,15 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
void DoOverlay(MagickImage image, ImageArgs args)
{
void DoOverlay(MagickImage image, ImageArgs args) {
// Validate the image argument
if(string.IsNullOrWhiteSpace(args.textArg))
if(string.IsNullOrWhiteSpace(args.textArg)) {
throw new System.Exception("No overlay provided!");
}
args.textArg = args.textArg.Replace("/", "").Replace("\\", "").Replace(".", "");
if(!ResourceExists(args.textArg + ".png", ResourceType.Resource))
if(!ResourceExists(args.textArg + ".png", ResourceType.Resource)) {
throw new System.Exception($"Image '{args.textArg}' does not exist!");
}
// Load the image
MagickImage overlayImage = new MagickImage(GetResourcePath(args.textArg + ".png", ResourceType.Resource));
overlayImage.Resize(new MagickGeometry($"{image.Width}x{image.Height}!"));

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Linq;
using System.Threading.Tasks;
@ -11,38 +11,45 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class ScrambleCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class ScrambleCommand : BaseCommandModule {
[Command("scramble")]
[Description("H")]
[Usage("[gif]")]
[Category(Category.Images)]
public async Task Scramble(CommandContext Context, [RemainingText]string input)
{
public async Task Scramble(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
args.scale+=2;
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-randomDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
string tempImgFile = TempManager.GetTempFile(seed+"-scrambleDL."+args.extension, true);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
// R a n d o m i z e
MagickImageCollection gif = null;
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
return;
}
else {
gif = new MagickImageCollection(tempImgFile);
var tmp = gif.OrderBy(x => new System.Random().Next()).ToArray();
gif = new MagickImageCollection(tmp);
}
TempManager.RemoveTempFile(seed+"-randomDL."+args.extension);
TempManager.RemoveTempFile(seed+"-scrambleDL."+args.extension);
// Save the image
MemoryStream imgStream = new MemoryStream();

View File

@ -1,4 +1,5 @@
using System.Net;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -9,27 +10,34 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class SpinCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class SpinCommand : BaseCommandModule {
[Command("spin")]
[Description("Spin an image")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task Spin(CommandContext Context, [RemainingText]string input)
{
public async Task Spin(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
if(args.layers > 3)
if(args.layers > 3) {
args.layers = 3;
else if(args.scale > 5)
}
else if(args.scale > 5) {
args.scale = 5;
}
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-spinDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -50,8 +58,7 @@ namespace HBot.Commands.Images
TempManager.RemoveTempFile(seed+"-spin.gif");
}
MagickImageCollection DoSpin(MagickImage img, ImageArgs args)
{
MagickImageCollection DoSpin(MagickImage img, ImageArgs args) {
// Setup
MagickImageCollection gifOut = new MagickImageCollection();
MagickImage mask = new MagickImage(ResourceManager.GetResourcePath("circleMask.png", ResourceType.Resource));

View File

@ -1,6 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -11,23 +11,29 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class TVCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class TVCommand : BaseCommandModule {
[Command("tv")]
[Description("Watch TV or something idk")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task TV(CommandContext Context, [RemainingText]string input)
{
public async Task TV(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-tvDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -49,10 +55,12 @@ namespace HBot.Commands.Images
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
@ -61,8 +69,7 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
MagickImage DoTV(MagickImage img, ImageArgs args, bool isGif = false)
{
MagickImage DoTV(MagickImage img, ImageArgs args, bool isGif = false) {
// Composite args
float rotation = 0.15f;
int srcX = 260;
@ -72,9 +79,9 @@ namespace HBot.Commands.Images
string imageFile = "tv.png";
// Setup
if(string.IsNullOrWhiteSpace(args.textArg))
if(string.IsNullOrWhiteSpace(args.textArg)) {
args.textArg = images[new Random().Next(0, images.Length)];
}
if(args.textArg.ToLower() == "celebrate") {
compX = 196;
compY = 64;
@ -108,16 +115,18 @@ namespace HBot.Commands.Images
img.Rotate(rotation);
tv.Alpha(AlphaOption.Remove);
tv.Composite(img, compX, compY, CompositeOperator.SrcIn);
if(args.textArg.ToLower() == "remote" || args.textArg.ToLower() == "angry")
if(args.textArg.ToLower() == "remote" || args.textArg.ToLower() == "angry") {
tv.Composite(tvClean, 0, 0, CompositeOperator.SrcOver, "-background none");
}
if(isGif) {
img.Resize(new MagickGeometry($"{tv.Width}x{tv.Height}!"));
img.Rotate(rotation*-1);
img.CopyPixels(tv);
return null;
}
else
else {
return tv;
}
}
static string[] images = { "celebrate", "remote", "normal", "angry" };

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -10,58 +10,65 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class WTHCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class WTHCommand : BaseCommandModule {
[Command("wth")]
[Description("what h")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task WTH(CommandContext Context, [RemainingText]string input)
{
public async Task WTH(CommandContext Context, [RemainingText] string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-wthDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
MagickImage img = null;
MagickImageCollection gif = null;
if(args.extension.ToLower() != "gif") {
if (args.extension.ToLower() != "gif") {
img = new MagickImage(tempImgFile);
img = DoWTH(img, args);
}
else {
gif = new MagickImageCollection(tempImgFile);
foreach(var frame in gif) {
foreach (var frame in gif) {
DoWTH((MagickImage)frame, args, true);
frame.Resize(400, 300);
}
}
TempManager.RemoveTempFile(seed+"-wthDL."+args.extension);
TempManager.RemoveTempFile(seed + "-wthDL." + args.extension);
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if (args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
await msg.ModifyAsync("Uploading...\nThis may take a while depending on the image size");
await Context.Channel.SendFileAsync(imgStream, "wth."+args.extension);
await Context.Channel.SendFileAsync(imgStream, "wth." + args.extension);
await msg.DeleteAsync();
}
MagickImage DoWTH(MagickImage img, ImageArgs args, bool isGif = false)
{
MagickImage DoWTH(MagickImage img, ImageArgs args, bool isGif = false) {
// Composite args
float rotation = 0.15f;
int srcX = 250;
@ -80,14 +87,15 @@ namespace HBot.Commands.Images
img.Rotate(rotation);
wth.Alpha(AlphaOption.Remove);
wth.Composite(img, compX, compY, CompositeOperator.SrcIn);
if(isGif) {
if (isGif) {
img.Resize(new MagickGeometry($"{wth.Width}x{wth.Height}!"));
img.Rotate(rotation*-1);
img.Rotate(rotation * -1);
img.CopyPixels(wth);
return null;
}
else
else {
return wth;
}
}
}
}
}

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -10,16 +10,13 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class WaawCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class WaawCommand : BaseCommandModule {
[Command("waaw")]
[Description("W a a w")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task Waaw(CommandContext Context, [RemainingText]string input)
{
public async Task Waaw(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
@ -27,7 +24,16 @@ namespace HBot.Commands.Images
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-waawDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -45,15 +51,17 @@ namespace HBot.Commands.Images
}
}
TempManager.RemoveTempFile(seed+"-waawDL."+args.extension);
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
args.extension = img.Format.ToString().ToLower();
}
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
@ -62,15 +70,14 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
public static void DoWaaw(MagickImage image)
{
public static void DoWaaw(MagickImage image) {
MagickImage left;
left = (MagickImage)image.Clone();
int width = image.Width/2;
if(width <= 0)
if(width <= 0) {
width = 1;
}
left.Crop(width, image.Height, Gravity.East);
left.Rotate(180);
left.Flip();

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -10,23 +10,29 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class WallCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class WallCommand : BaseCommandModule {
[Command("wall")]
[Description("Build a great big beautiful wall ~~and make Mexico pay for it~~")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task Wall(CommandContext Context, [RemainingText]string input)
{
public async Task Wall(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-wallDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -48,10 +54,12 @@ namespace HBot.Commands.Images
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
@ -60,8 +68,7 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
public static void DoWall(MagickImage img, ImageArgs args)
{
public static void DoWall(MagickImage img, ImageArgs args) {
img.Resize(new MagickGeometry("128"));
img.VirtualPixelMethod = VirtualPixelMethod.Tile;
img.MatteColor = MagickColors.None;

View File

@ -1,5 +1,5 @@
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
@ -10,16 +10,13 @@ using HBot.Commands.Attributes;
using ImageMagick;
namespace HBot.Commands.Images
{
public class WoowCommand : BaseCommandModule
{
namespace HBot.Commands.Images {
public class WoowCommand : BaseCommandModule {
[Command("woow")]
[Description("W o o w")]
[Usage("[image]")]
[Category(Category.Images)]
public async Task Woow(CommandContext Context, [RemainingText]string input)
{
public async Task Woow(CommandContext Context, [RemainingText]string input) {
// Handle arguments
ImageArgs args = ImageCommandParser.ParseArgs(Context, input);
int seed = new System.Random().Next(1000, 99999);
@ -27,7 +24,16 @@ namespace HBot.Commands.Images
// Download the image
string tempImgFile = TempManager.GetTempFile(seed+"-woowDL."+args.extension, true);
new WebClient().DownloadFile(args.url, tempImgFile);
using (var httpClient = new HttpClient()) {
using (var response = await httpClient.GetAsync(args.url, HttpCompletionOption.ResponseHeadersRead)) {
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync()) {
using (var fileStream = new FileStream(tempImgFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
await stream.CopyToAsync(fileStream);
}
}
}
}
var msg = await Context.ReplyAsync("Processing...\nThis may take a while depending on the image size");
@ -50,10 +56,12 @@ namespace HBot.Commands.Images
// Save the image
MemoryStream imgStream = new MemoryStream();
if(args.extension.ToLower() != "gif")
if(args.extension.ToLower() != "gif") {
img.Write(imgStream);
else
}
else {
gif.Write(imgStream);
}
imgStream.Position = 0;
// Send the image
@ -62,15 +70,14 @@ namespace HBot.Commands.Images
await msg.DeleteAsync();
}
public static void DoWoow(MagickImage image)
{
public static void DoWoow(MagickImage image) {
MagickImage bottom;
bottom = (MagickImage)image.Clone();
int height = image.Height/2;
if(height <= 0)
if(height <= 0) {
height = 1;
}
bottom.Crop(image.Width, height, Gravity.North);
bottom.Flip();

View File

@ -6,68 +6,66 @@ using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using HBot.Commands.Attributes;
namespace HBot.Commands.Owner {
public class EvalCommand: BaseCommandModule {
public class EvalCommand : BaseCommandModule {
[Command("eval")]
[Aliases("ev")]
[Description("It's an eval command.")]
[Usage("[C# Code]")]
[Category(Category.Owner)]
[Description("Execute C# code")]
[RequireOwner]
public async Task Eval(CommandContext ctx, [RemainingText] string code) {
// Set up the script options
var options = ScriptOptions.Default
.WithImports("System", "System.Linq", "System.Collections.Generic", "DSharpPlus", "DSharpPlus.CommandsNext", "DSharpPlus.Entities", "DSharpPlus.EventArgs")
.WithReferences(GetReferencedAssemblies());
.AddReferences(GetReferencedAssemblies())
.AddImports("System", "System.Linq", "System.Collections.Generic", "DSharpPlus", "DSharpPlus.CommandsNext", "DSharpPlus.Entities");
// Evaluate the code
try {
var result = await CSharpScript.EvaluateAsync(code, options, globals: new EvalGlobals(ctx));
var globals = new EvalGlobals(ctx);
var result = await CSharpScript.EvaluateAsync(code, options, globals);
if (result != null) {
// Send the result as a message
var resultString = result.ToString();
var embed = new DiscordEmbedBuilder()
.WithTitle("Eval Result")
.WithTitle("Result")
.WithColor(DiscordColor.Gold)
.WithDescription($"```\n{result}\n```")
.WithDescription($"```\n{resultString}\n```")
.Build();
await ctx.RespondAsync(embed: embed);
}
} catch (Exception ex) {
// Send the error message as a message
}
catch (Exception ex) {
var embed = new DiscordEmbedBuilder()
.WithTitle("Eval Error")
.WithTitle("Error")
.WithColor(DiscordColor.Red)
.WithDescription($"```\n{ex.Message}\n```")
.WithDescription($"An error occurred: {ex.Message}")
.Build();
await ctx.RespondAsync(embed: embed);
}
}
private static IEnumerable < MetadataReference > GetReferencedAssemblies() {
var assemblies = new List < Assembly > {
private static IEnumerable<MetadataReference> GetReferencedAssemblies() {
var assemblies = new List<Assembly> {
Assembly.GetEntryAssembly(),
typeof (object).Assembly,
typeof (Enumerable).Assembly,
typeof (DiscordClient).Assembly,
typeof (CommandContext).Assembly,
typeof (CommandEventArgs).Assembly
typeof(object).Assembly,
typeof(Enumerable).Assembly,
typeof(DiscordClient).Assembly,
typeof(CommandContext).Assembly,
typeof(CommandEventArgs).Assembly
};
return assemblies.Select(x => MetadataReference.CreateFromFile(x.Location));
}
}
public class EvalGlobals {
public CommandContext Context {
get;
}
public CommandContext Context { get; }
public DiscordGuild Guild => Context.Guild;
public DiscordChannel Channel => Context.Channel;
public DiscordUser User => Context.User;
@ -77,4 +75,4 @@ namespace HBot.Commands.Owner {
Context = ctx;
}
}
}
}

View File

@ -9,7 +9,7 @@ using Serilog;
namespace HBot.Misc {
public static class UpdateChecker {
private static readonly HttpClient httpClient = new HttpClient();
private const string API_URL = "https://hiden.pw/api/hbot/check-update";
private const string API_URL = "http://localhost/api/hbot/check-update";
public static async Task<(bool updateAvailable, string latestVersion, string releaseDate)> CheckForUpdate(string currentVersion) {
try {
@ -17,7 +17,7 @@ namespace HBot.Misc {
var response = await httpClient.GetAsync(url);
if(!response.IsSuccessStatusCode) {
Log.Error($"Failed to check for update. Response code: {(int)response.StatusCode} ({response.StatusCode})");
Log.Error($"Failed to check for updates. Response code: {(int)response.StatusCode} ({response.StatusCode})");
Environment.Exit(1);
return (false, "", "");
}
@ -26,7 +26,7 @@ namespace HBot.Misc {
var updateInfo = JsonConvert.DeserializeObject<UpdateInfo>(content);
if(updateInfo == null) {
Log.Error("Invalid update info. The API may be having issues");
Log.Error("Invalid server-side version info. The API may be having issues");
Log.Error("Report this issue on GitHub, or contact HIDEN at https://hiden.pw/about/socials.");
Environment.Exit(1);
return (false, "", "");