SuperMachoBot/SuperMachoBot/Program.cs

361 lines
19 KiB
C#
Raw Normal View History

2022-09-10 19:56:21 +00:00
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;
2022-09-10 19:56:21 +00:00
using DSharpPlus.SlashCommands;
using Newtonsoft.Json;
using SuperMachoBot.Commands;
using System.Data.SqlTypes;
using System.Linq.Expressions;
2022-09-10 19:56:21 +00:00
namespace SuperMachoBot
{
class Program
{
public static string rootPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
public static bool moneyCooldown = true;
public static List<Config> configItems = new List<Config>();
public static DiscordClient discord;
public static string databasePath = "";
2022-09-10 19:56:21 +00:00
static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
}
internal static async Task MainAsync()
{
using (StreamReader r = new StreamReader(@$"{rootPath}\config\config.json"))
{
string json = r.ReadToEnd();
configItems = JsonConvert.DeserializeObject<List<Config>>(json);
}
discord = new DiscordClient(new DiscordConfiguration()
2022-09-10 19:56:21 +00:00
{
Token = configItems[0].Token,
2023-02-16 18:20:08 +00:00
TokenType = TokenType.Bot,
Intents = DiscordIntents.Guilds | DiscordIntents.GuildMembers | DiscordIntents.GuildMessages | DiscordIntents.GuildMessageReactions | DiscordIntents.DirectMessages | DiscordIntents.MessageContents
2022-09-10 19:56:21 +00:00
});
var slash = discord.UseSlashCommands();
discord.MessageCreated += async (s, e) =>
{
2023-02-16 18:20:08 +00:00
};
databasePath = configItems[0].EconomyDatabasePath;
discord.MessageReactionAdded += async (s, e) =>
2023-02-16 18:20:08 +00:00
{
try //I don't think this is good practice. Fuck it.
2023-02-16 18:20:08 +00:00
{
List<GuildConfig> config = JsonConvert.DeserializeObject<List<GuildConfig>>(File.ReadAllText(@$"{Program.databasePath}/{e.Guild.Id}/Config.json"));
var bruh = config[0].coalEmoteId;
if (e.Emoji.Id == config[0].gemEmoteId) //Gem
2023-02-16 18:20:08 +00:00
{
var message = await e.Channel.GetMessageAsync(e.Message.Id);
foreach (var reaction in message.Reactions)
2023-02-16 18:20:08 +00:00
{
if (reaction.Emoji.Id == config[0].gemEmoteId)
{
if (reaction.Count > config[0].gemAmount - 1 && !CheckPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
{
string thumbnailURL = GetRelevantEmbedURL(message);
string desc = "";
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/Pinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
if (message.Content != "")
{
desc = $@"""{message.Content}""";
}
2023-02-16 18:20:08 +00:00
var bruhgimus = new DiscordEmbedBuilder
{
Title = $"GEM ALERT!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://media.discordapp.net/attachments/977270567881298024/1076252389637627904/850_-_SoyBooru.gif" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = message.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{message.Author.Username}#{message.Author.Discriminator}" },
Color = DiscordColor.PhthaloBlue
}.AddField("Gem:", $"[link]({message.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, bruhgimus);
}
}
}
2023-02-16 18:20:08 +00:00
}
if (e.Emoji.Id == config[0].gemEmoteId) //GEMERALD!!
2023-02-16 18:20:08 +00:00
{
var message = await e.Channel.GetMessageAsync(e.Message.Id);
foreach (var reaction in message.Reactions)
2023-02-16 18:20:08 +00:00
{
if (reaction.Emoji.Id == config[0].gemEmoteId)
{
if (reaction.Count > config[0].turboAmount - 1 && !CheckUltraPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
{
string thumbnailURL = GetRelevantEmbedURL(message);
string desc = "";
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/UltraPinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
if (message.Content != "")
{
desc = $@"""{message.Content}""";
}
2023-02-16 18:20:08 +00:00
var bruhgimus = new DiscordEmbedBuilder
{
Title = $"GEMERALD ALERT! GEMERALD ALERT! {config[0].turboAmount}+ GEMS!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1093186592782422057/Gemerald.png" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = message.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{message.Author.Username}#{message.Author.Discriminator}" },
Color = new DiscordColor("#66ff33")
}.AddField("Gemerald:", $"[link]({message.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, bruhgimus);
}
}
}
}
if (e.Emoji.Id == config[0].coalEmoteId) //Coal
{
var message = await e.Channel.GetMessageAsync(e.Message.Id);
foreach (var reaction in message.Reactions)
2023-02-16 18:20:08 +00:00
{
if (reaction.Emoji.Id == config[0].coalEmoteId)
{
if (reaction.Count > config[0].gemAmount - 1 && !CheckPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
{
string thumbnailURL = GetRelevantEmbedURL(message);
string desc = "";
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/Pinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
if (message.Content != "")
{
desc = $@"""{message.Content}""";
}
var embed = new DiscordEmbedBuilder
{
Title = $"COAL!!!! STINKY PISSCOAL ALERT!!!!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1076252390157733958/862_-_SoyBooru.gif" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = message.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{message.Author.Username}#{message.Author.Discriminator}" },
Color = DiscordColor.Black
}.AddField("Coal:", $"[link]({message.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
}
}
}
}
if (e.Emoji.Id == config[0].coalEmoteId) //BRIMSTONE!!
{
var message = await e.Channel.GetMessageAsync(e.Message.Id);
foreach (var reaction in message.Reactions)
{
if (reaction.Emoji.Id == config[0].coalEmoteId)
{
if (reaction.Count > config[0].turboAmount - 1 && !CheckUltraPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
{
string thumbnailURL = GetRelevantEmbedURL(message);
string desc = "";
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/UltraPinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
if (message.Content != "")
{
desc = $@"""{message.Content}""";
}
var embed = new DiscordEmbedBuilder
{
Title = $"BRIMSTONE!!!! HELLISH TORTURECOAL ALERT!!!! {config[0].turboAmount}+ COALS!!!!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
2023-04-12 05:20:32 +00:00
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1095576471235465266/Brimstone.png" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = message.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{message.Author.Username}#{message.Author.Discriminator}" },
2023-04-12 05:20:32 +00:00
Color = DiscordColor.DarkRed
}.AddField("Brimstone:", $"[link]({message.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
}
}
}
}
bool debug = true;
if (e.Emoji.Id == 959642740277252136) //Delete
{
var bruha = await e.Channel.GetMessageAsync(e.Message.Id);
if (e.User.Id == 304033317513199617 && bruha.Author.Id == 305520963238494219) //Only let me delete messages from the bot, so it's not a le epic backdoor.
{
await bruha.DeleteAsync();
}
}
if (e.Emoji.Id == 820033186008399903) //Debug
{
var message = await e.Channel.GetMessageAsync(e.Message.Id);
if (e.User.Id == 304033317513199617)
{
foreach (var reaction in message.Reactions)
{
if (reaction.Emoji.Id == 820033186008399903)
{
if (reaction.Count > 0)
{
string thumbnailURL = "";
string desc = "";
if (message.Embeds.Count > 0)
{
thumbnailURL = message.Embeds[0].Thumbnail.Url.ToString();
var video = message.Embeds[0].Video;
if (video != null)
{
thumbnailURL = video.Url.ToString();
}
}
if (message.Attachments.Count > 0)
{
thumbnailURL = message.Attachments[0].Url;
}
if (message.Content != "")
{
desc = $@"""{message.Content}""";
}
var embed = new DiscordEmbedBuilder
{
Title = $"....Debug alert?",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1078813136649474128/pinson.gif" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = message.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{message.Author.Username}#{message.Author.Discriminator}" },
Color = DiscordColor.Black
}.AddField("Debug:", $"[link]({message.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
//File.AppendAllText(pinnedPath, bruh.Id.ToString() + "\n");
}
}
}
}
2023-02-16 18:20:08 +00:00
}
2022-09-10 19:56:21 +00:00
}
catch (Exception ex)
{
}
2022-09-10 19:56:21 +00:00
};
var commands = discord.UseCommandsNext(new CommandsNextConfiguration()
{
StringPrefixes = new[] { "tf" }
});
commands.RegisterCommands<GeneralCommands>();
slash.RegisterCommands<SlashCommands>();
slash.RegisterCommands<EconomyCommands>();
2023-02-16 18:20:08 +00:00
EconomyCommands.jsonPath = configItems[0].EconomyDatabasePath;
2022-09-10 19:56:21 +00:00
2023-02-16 18:31:41 +00:00
Console.WriteLine(EconomyCommands.jsonPath);
2022-09-10 19:56:21 +00:00
await discord.ConnectAsync();
await Task.Delay(-1);
}
static void cooldown()
{
moneyCooldown = true;
Thread.Sleep(10000);
moneyCooldown = false;
}
2023-02-16 18:20:08 +00:00
static bool CheckPinID(ulong messageid, ulong? guildid)
2023-02-16 18:20:08 +00:00
{
if (!Directory.Exists($"{databasePath}/{guildid}/"))
{
Directory.CreateDirectory(@$"{databasePath}/{guildid}/");
}
if (!File.Exists($"{databasePath}/{guildid}/Pinned.txt"))
2023-02-16 18:20:08 +00:00
{
File.Create(@$"{databasePath}/{guildid}/Pinned.txt").Close();
}
foreach (var line in File.ReadAllLines($"{databasePath}/{guildid}/Pinned.txt"))
{
if (line.Split(',')[0] == messageid.ToString())
2023-02-16 18:20:08 +00:00
{
return true;
}
}
return false;
}
static bool CheckUltraPinID(ulong messageid, ulong? guildid)
{
if (!Directory.Exists($"{databasePath}/{guildid}/"))
{
Directory.CreateDirectory(@$"{databasePath}/{guildid}/");
}
if (!File.Exists($"{databasePath}/{guildid}/UltraPinned.txt"))
{
File.Create(@$"{databasePath}/{guildid}/UltraPinned.txt").Close();
}
foreach (var line in File.ReadAllLines($"{databasePath}/{guildid}/UltraPinned.txt"))
{
if (line.Split(',')[0] == messageid.ToString())
{
return true;
}
}
return false;
}
static string GetRelevantEmbedURL(DiscordMessage message)
{
string thumbnailURL = "";
if (message.Embeds.Count > 0)
{
//thumbnailURL = message.Embeds[0].Image.Url.ToString();
var video = message.Embeds[0].Video;
var image = message.Embeds[0].Image;
//thumbnailURL = message.Embeds[0].Video != null ? message.Embeds[0].Video.Url.ToString() : message.Embeds[0].Image.Url.ToString();
if (video != null)
{
var urlString = video.Url.ToString(); //Hate Tenor Hate Tenor Hate Tenor Hate Tenor Hate Tenor Hate Tenor RAGE!!!!
bool isTenorUrl = urlString.StartsWith("https://media.tenor.com");
if (isTenorUrl)
{
/*RANT: I HATE TENOR
* IF YOU WANT TO ACTUALLY GET THE MP4 FILE, YOU HAVE TO CHANGE THE WEIRD FILETYPE IDENTIFIER LETTERS IN THE URL FROM 'AAAPo' to 'AAAAd'.
* WHY WOULD YOU DO THIS TO ME YOU MOTHERFUCKERS? THIS SHIT LITERALLY BREAKS EMBED ON DISCORD MOBILE TOO!
* Oh also Discord is a bit stupid and I have to change the end of the url from '.mp4' to '.gif' for it to autoplay correctly. Lol!
*/
thumbnailURL = urlString.Replace("AAAPo", "AAAAd");
thumbnailURL = thumbnailURL.Substring(0, thumbnailURL.Length - 3) + "gif";
}
else
{
thumbnailURL = video.Url.ToString();
}
}
else
{
thumbnailURL = image.Url.ToString();
}
}
else if (message.Attachments.Count > 0)
{
thumbnailURL = message.Attachments[0].Url;
}
return thumbnailURL;
}
2022-09-10 19:56:21 +00:00
}
public class Config
{
public string Token;
public ulong OwnerID;
public string EconomyDatabasePath;
2022-09-10 19:56:21 +00:00
}
public class GuildConfig
{
public ulong gemboardChannelId;
public long gemAmount;
public long turboAmount;
public ulong gemEmoteId;
public ulong coalEmoteId;
}
2022-09-10 19:56:21 +00:00
}