BALLS OVER

This commit is contained in:
Dylan Martini 2024-04-23 16:37:54 -05:00
parent 3500829e10
commit 52da9e6345
16 changed files with 97 additions and 152 deletions

View File

@ -10,12 +10,12 @@
<ItemGroup>
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.6" />
<PackageReference Include="DSharpPlus" Version="4.4.3" />
<PackageReference Include="DSharpPlus" Version="4.4.6" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.3" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.4.3" />
<PackageReference Include="Magick.NET-Q16-x64" Version="13.5.0" />
<PackageReference Include="Magick.NET-Q16-x64" Version="13.6.0" />
<PackageReference Include="MarkovSharp" Version="4.0.32" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.9.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Miki.UrbanDictionary" Version="6.0.0" />
<PackageReference Include="Newtonsoft.json" Version="13.0.3" />

View File

@ -1,24 +1,13 @@
# HBot
General purpose Discord bot, made with DSharpPlus v4.4.3. Originally based on NetRunner + WinBot.
General purpose Discord bot, made with DSharpPlus. Originally based on NetRunner + WinBot.
## Usage instructions
### Requirements:
- .NET 8.0
- Roboto, Impact, and xband fonts
#### Officially supported OSes:
- Windows 10 Anniversary Update or newer
- macOS 10.15 or newer
- Debian 11 or newer
- Ubuntu 20.04 or newer
- Fedora 37 or newer
- Any other Linux distribution that supports .NET 8.0
You will not recieve technical assistance if you are using an unsupported OS, or if you're using a workaround to run this on an unsupported OS.
### Building and running:
1. Clone the repository: ``https://git.hiden.pw/scythe/HBot.git`` and move into the project directory: ``cd HBot``
1. Clone the repository: ``https://git.hiden.cc/scythe/HBot.git`` and move into the project directory: ``cd HBot``
2. Build the source code: ``dotnet build -c Release``
3. Change into the build directory: ``cd bin/Release/net7.0/``
4. Run the bot: ``./HBot`` or just ``HBot`` for Windows. This will generate a blank configuration file for you.

View File

@ -29,7 +29,7 @@ using ImageMagick;
namespace HBot {
class Bot {
public const string VERSION = "Dev";
public const string VERSION = "1.11";
public static void Main(string[] args) => new Bot().RunBot().GetAwaiter().GetResult();
@ -100,57 +100,6 @@ namespace HBot {
// Set misc stuff
// Check for updates, start misc systems
Log.Information("Checking for updates...");
var (updateAvailable, latestVersion, releaseDate) = await UpdateChecker.CheckForUpdate(VERSION);
if (updateAvailable) {
Log.Warning($"An update is available (latest version: {latestVersion}, release date: {releaseDate}). Please update as soon as possible.");
DateTime releaseDateTime = DateTime.Parse(releaseDate);
// Check if 14 days have passed since release date
if (DateTime.Now >= releaseDateTime.AddDays(14)) {
Log.Warning("Updating to the latest version is required to continue using HBot. Running git pull...");
// Attempt to run git pull
var process = new Process {
StartInfo = new ProcessStartInfo {
FileName = MiscUtil.GetGitExec(),
Arguments = "pull",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
// If git pull is successful, tell the user to rebuild
if (process.ExitCode == 0) {
Log.Warning("Update successful. Please rebuild and restart the bot.");
}
else {
Log.Fatal("git pull failed. Please update the bot manually.");
}
Environment.Exit(1);
}
// Check if 7 days have passed since release date
else if (DateTime.Now >= releaseDateTime.AddDays(7)) {
Log.Warning("User confirmation required to start without updating.");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
else {
Log.Information("No updates available. You're good to go!");
}
UserData.Init();
Leveling.Init();
TempManager.Init();
@ -180,7 +129,7 @@ namespace HBot {
client.GuildMemberAdded += async (DiscordClient client, GuildMemberAddEventArgs e) => {
if (e.Guild == Global.targetGuild) {
if (!Global.mutedUsers.Contains(e.Member.Id)) {
await Global.welcomeChannel.SendMessageAsync($"Welcome, {e.Member.Mention} to HIDNet! Make sure you read the rules before chatting. You can find them here: https://dev.hiden.pw/discord/rules. Once you're done with that, send an introduction in the introductions channel.");
await Global.welcomeChannel.SendMessageAsync($"Welcome, {e.Member.Mention} to HIDNet! Make sure you read the rules before chatting. You can find them here: https://hiden.cc/discord/rules. Once you're done with that, send an introduction in the introductions channel.");
} else {
await Global.welcomeChannel.SendMessageAsync($"Welcome, {e.Member.Mention} to HIDNet! Unfortunately, it seems as if you have failed to read the rules. Have fun in the box! This is what you get for trying to be a ding-dong :P.");
await e.Member.GrantRoleAsync(Global.mutedRole);
@ -237,11 +186,11 @@ namespace HBot {
// Verify and download resources
Log.Information("Verifying resources...");
using HttpClient httpClient = new HttpClient();
string resourcesJson = await httpClient.GetStringAsync("https://storage.hiden.pw/hbot-dist/res/resources.json");
string resourcesJson = await httpClient.GetStringAsync("https://storage.hiden.cc/hbot-dist/res/resources.json");
string[] resources = JsonConvert.DeserializeObject<string[]>(resourcesJson);
foreach (string resource in resources) {
if (!ResourceExists(resource, ResourceType.Resource)) {
var response = await httpClient.GetAsync($"https://storage.hiden.pw/hbot-dist/res/{resource}");
var response = await httpClient.GetAsync($"https://storage.hiden.cc/hbot-dist/res/{resource}");
var stream = await response.Content.ReadAsStreamAsync();
using (var fileStream = new FileStream(GetResourcePath(resource, ResourceType.Resource), FileMode.Create)) {
await stream.CopyToAsync(fileStream);

View File

@ -16,7 +16,7 @@ namespace HBot.Commands.Fun {
string json = "";
using (HttpClient http = new HttpClient()) {
try {
json = await http.GetStringAsync("https://dev.hiden.pw/api/random-cat");
json = await http.GetStringAsync("https://hiden.cc/api/random-cat");
}
catch (Exception ex) {
throw new Exception($"Error fetching cat image: {ex.Message}");

View File

@ -50,7 +50,7 @@ namespace HBot.Commands.Main {
// Create and send an embed
DiscordEmbedBuilder eb = new DiscordEmbedBuilder();
eb.WithTitle("Random Spam E-mail");
eb.WithThumbnail("https://dev.hiden.pw/static/icon/socials/email.png");
eb.WithThumbnail("https://hiden.cc/static/icon/socials/email.png");
eb.AddField($"Subject: {spamSubject}", $"{spamContent}");
eb.WithFooter($"ID: {spamID}");
eb.WithColor(DiscordColor.Gold);

View File

@ -14,7 +14,7 @@ namespace HBot.Commands.Fun {
[Attributes.Category(Category.Fun)]
[Aliases("speech")]
public async Task SpeechBubble(CommandContext ctx) {
string funnyUrl = "https://speech.hiden.pw";
string funnyUrl = "https://speech.hiden.cc";
using (var response = await httpClient.GetAsync(funnyUrl)) {
if (response.IsSuccessStatusCode) {

View File

@ -79,7 +79,7 @@ namespace HBot.Commands.Images {
// Setup
if (string.IsNullOrWhiteSpace(args.textArg))
args.textArg = images[new Random().Next(0, images.Length)];
// go go gadget yanderedev
if (args.textArg.ToLower() == "1") {
compX = 925/2;
compY = 225/2;
@ -112,6 +112,62 @@ namespace HBot.Commands.Images {
rotation = 0.4f;
imageFile = "billboard4.png";
}
else if (args.textArg.ToLower() == "8bit") {
compX = 170;
compY = 620;
srcX = 710;
srcY = 430;
rotation = 0;
imageFile = "8bit.png";
}
else if (args.textArg.ToLower() == "8bit2") {
compX = 253;
compY = 688;
srcX = 554;
srcY = 318;
rotation = 0;
imageFile = "8bit2.png";
}
else if (args.textArg.ToLower() == "8bit3") {
compX = 607;
compY = 198;
srcX = 520;
srcY = 360;
rotation = 0;
imageFile = "8bit3.png";
}
else if (args.textArg.ToLower() == "8bit4") {
compX = 662;
compY = 244;
srcX = 408;
srcY = 268;
rotation = 0;
imageFile = "8bit4.png";
}
else if (args.textArg.ToLower() == "dprk") {
compX = 633;
compY = 220;
srcX = 190;
srcY = 237;
rotation = 0.2f;
imageFile = "dprk.png";
}
else if (args.textArg.ToLower() == "kim") {
compX = 475;
compY = 393;
srcX = 250;
srcY = 150;
rotation = 2.5f;
imageFile = "kim.png";
}
else if (args.textArg.ToLower() == "kimsad") {
compX = 475;
compY = 393;
srcX = 250;
srcY = 150;
rotation = 2.5f;
imageFile = "kimsad.png";
}
MagickImage tv = new MagickImage(ResourceManager.GetResourcePath(imageFile, ResourceType.Resource));
MagickImage tvClean = new MagickImage(ResourceManager.GetResourcePath(imageFile, ResourceType.Resource));
@ -121,10 +177,10 @@ namespace HBot.Commands.Images {
img.Rotate(rotation);
tv.Alpha(AlphaOption.Remove);
tv.Composite(img, compX, compY, CompositeOperator.SrcIn);
if(args.textArg.ToLower() == "1" || args.textArg.ToLower() == "joe") {
if (args.textArg.ToLower() == "1" || args.textArg.ToLower() == "joe" || args.textArg.ToLower().Contains("8bit") || args.textArg.ToLower().Contains("dprk") || args.textArg.ToLower().Contains ("kim")) {
tv.Composite(tvClean, 0, 0, CompositeOperator.SrcOver, "-background none");
}
if(isGif) {
if (isGif) {
img.Resize(new MagickGeometry($"{tv.Width}x{tv.Height}!"));
img.Rotate(rotation*-1);
img.CopyPixels(tv);
@ -134,6 +190,6 @@ namespace HBot.Commands.Images {
return tv;
}
static string[] images = { "1", "2", "3", "joe" };
static string[] images = { "1", "2", "3", "joe", "8bit", "8bit2", "8bit3", "8bit4", "dprk", "kim", "kimsad" };
}
}

View File

@ -79,10 +79,10 @@ 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") {
if (args.textArg.ToLower() == "celebrate") {
compX = 196;
compY = 64;
srcX = 149;
@ -90,7 +90,7 @@ namespace HBot.Commands.Images {
rotation = 0;
imageFile = "tv2.png";
}
else if(args.textArg.ToLower() == "remote") {
else if (args.textArg.ToLower() == "remote") {
compX = 95;
compY = 35;
srcX = 459;
@ -98,7 +98,7 @@ namespace HBot.Commands.Images {
rotation = 0;
imageFile = "tv3.png";
}
else if(args.textArg.ToLower() == "angry") {
else if (args.textArg.ToLower() == "angry") {
compX = 75;
compY = 145;
srcX = 280;
@ -106,6 +106,14 @@ namespace HBot.Commands.Images {
rotation = 0;
imageFile = "tv4.png";
}
else if (args.textArg.ToLower() == "8bit") {
compX = 278;
compY = 207;
srcX = 234;
srcY = 171;
rotation = 0.2f;
imageFile = "8bit-tv.png";
}
MagickImage tv = new MagickImage(ResourceManager.GetResourcePath(imageFile, ResourceType.Resource));
MagickImage tvClean = new MagickImage(ResourceManager.GetResourcePath(imageFile, ResourceType.Resource));
@ -118,7 +126,7 @@ namespace HBot.Commands.Images {
if(args.textArg.ToLower() == "remote" || args.textArg.ToLower() == "angry") {
tv.Composite(tvClean, 0, 0, CompositeOperator.SrcOver, "-background none");
}
if(isGif) {
if (isGif) {
img.Resize(new MagickGeometry($"{tv.Width}x{tv.Height}!"));
img.Rotate(rotation*-1);
img.CopyPixels(tv);
@ -129,6 +137,6 @@ namespace HBot.Commands.Images {
}
}
static string[] images = { "celebrate", "remote", "normal", "angry" };
static string[] images = { "celebrate", "remote", "normal", "angry", "8bit" };
}
}

View File

@ -22,7 +22,7 @@ namespace HBot.Commands.Main {
eb.AddField("Version", Bot.VERSION, true);
eb.AddField("Library", $"DSharpPlus v{Bot.client.VersionString}", true);
eb.AddField("Host OS", Environment.OSVersion.VersionString, true);
eb.WithUrl("https://git.hiden.pw/scythe/HBot");
eb.WithUrl("https://git.hiden.cc/HIDEN/HBot");
eb.WithThumbnail(Bot.client.CurrentUser.AvatarUrl);
eb.WithColor(DiscordColor.Gold);

View File

@ -9,7 +9,7 @@ using HBot.Commands.Attributes;
namespace HBot.Commands.Main {
public class OCRCommand : BaseCommandModule {
private const string OCR_API_URL = "https://dev.hiden.pw/api/ocr";
private const string OCR_API_URL = "https://hiden.cc/api/ocr";
[Command("ocr")]
[Description("Gets the text from an image")]

View File

@ -23,20 +23,18 @@ namespace HBot.Commands.Main {
// Need to specify a role, dumbass
if (string.IsNullOrWhiteSpace(roleName)) {
throw new Exception("Role must be one of: Announcements, Blog Posts, Updates, Polls (case insensitive)");
throw new Exception("Role must be one of: Announcements, CrossTalk Updates (case insensitive)");
}
// Check if the role exists
if (role == null) {
throw new Exception($"The {roleName} role does not exist, must be one of: Announcements, Blog Posts, Updates, Polls (case insensitive)");
throw new Exception($"The {roleName} role does not exist, must be one of: Announcements, CrossTalk Updates (case insensitive)");
}
// Check if the role is one of the allowed roles
if (!string.Equals(roleName, "Announcements", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(roleName, "Blog Posts", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(roleName, "Updates", StringComparison.OrdinalIgnoreCase) &&
!string.Equals(roleName, "Polls", StringComparison.OrdinalIgnoreCase)) {
await ctx.RespondAsync("You can only add the Announcements, Blog Posts, Updates, or Polls role to yourself.");
!string.Equals(roleName, "CrossTalk Updates", StringComparison.OrdinalIgnoreCase)) {
await ctx.RespondAsync("You can only add Announcements or CrossTalk Updates role to yourself.");
return;
}

View File

@ -71,7 +71,7 @@ namespace HBot.Commands.Main {
dynamic responseData = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
string translatedText = Convert.ToString(responseData.translatedText);
if (translatedText.Length >= 1024) {
string baseUrl = "https://paste.hiden.pw/";
string baseUrl = "https://paste.hiden.cc/";
var hasteBinClient = new HasteBinClient(baseUrl);
HasteBinResult HBresult = hasteBinClient.Post(translatedText).Result;
translatedText = $"{baseUrl}{HBresult.Key}";

View File

@ -13,6 +13,7 @@ using Newtonsoft.Json;
namespace HBot.Commands.Main {
public class WeatherCommand : BaseCommandModule {
[Command("weather")]
[Aliases("wx")]
[Description("Get the weather for a specific location")]
[Usage("[location]")]
[Attributes.Category(Category.Main)]

View File

@ -46,7 +46,7 @@ namespace HBot.Misc {
public static async Task FetchItems() {
try {
// Setup
var feed = await FeedReader.ReadAsync("https://dev.hiden.pw/blog/rss.xml");
var feed = await FeedReader.ReadAsync("https://hiden.cc/blog/rss.xml");
DiscordChannel additions = await Bot.client.GetChannelAsync(Bot.config.ids.rssChannel);
DiscordGuild guild = additions.Guild;

View File

@ -1,56 +0,0 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Serilog;
namespace HBot.Misc {
public static class UpdateChecker {
private static readonly HttpClient httpClient = new HttpClient();
private const string API_URL = "https://dev.hiden.pw/api/hbot-update";
public static async Task<(bool updateAvailable, string latestVersion, string releaseDate)> CheckForUpdate(string currentVersion) {
try {
var url = $"{API_URL}?version={currentVersion}";
var response = await httpClient.GetAsync(url);
if(!response.IsSuccessStatusCode) {
Log.Error($"Failed to check for updates. Response code: {(int)response.StatusCode} ({response.StatusCode})");
Environment.Exit(1);
return (false, "", "");
}
var content = await response.Content.ReadAsStringAsync();
var updateInfo = JsonConvert.DeserializeObject<UpdateInfo>(content);
if(updateInfo == null) {
Log.Error("Invalid server-side version info. The API may be having issues");
Log.Error("Report this issue on the Git repo, or contact HIDEN at https://dev.hiden.pw/about/socials.");
Environment.Exit(1);
return (false, "", "");
}
return (updateInfo.updateAvailable, updateInfo.latestVersion, updateInfo.releaseDate);
}
catch(Exception ex) {
Log.Error(ex, "An error occurred while checking for updates; the API may be unavailable at this time. Please try again later.");
Log.Error("If the error persists, please report it on the Git repo, or contact HIDEN at https://dev.hiden.pw/about/socials.");
Environment.Exit(1);
return (false, "", "");
}
}
private class UpdateInfo {
[JsonProperty("update_available")]
public bool updateAvailable { get; set; }
[JsonProperty("latest_version")]
public string latestVersion { get; set; }
[JsonProperty("release_date")]
public string releaseDate { get; set; }
}
}
}

View File

@ -20,7 +20,7 @@ namespace HBot.Util {
if (result.Length < 1024)
return result;
else {
string baseUrl = "https://paste.hiden.pw/";
string baseUrl = "https://paste.hiden.cc/";
var hasteBinClient = new HasteBinClient(baseUrl);
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
return $"{baseUrl}{HBresult.Key}";
@ -45,7 +45,7 @@ namespace HBot.Util {
if (result.Length < 1024)
return result;
else {
string baseUrl = "https://paste.hiden.pw/";
string baseUrl = "https://paste.hiden.cc/";
var hasteBinClient = new HasteBinClient(baseUrl);
HasteBinResult HBresult = hasteBinClient.Post(result).Result;
return $"{baseUrl}{HBresult.Key}";