mirror of
https://github.com/Brazmann/SuperMachoBot.git
synced 2024-12-22 21:26:41 +00:00
Database/Gemboard Rewrite + Additions
-Rewrote backend to support seperate databases/configs for guilds. -Added configuration file for gemboard to determine emote ids, amounts, etc. -Added command for owner of guild to run to configure gemboard. -Added new 'Turbo' pins, which create an additional special pin for messages which get a high amount of gem/coal reactions, with the amount required determined by config file. -Added method to retrieve the relevant embed from a supplied Discord message. -Solved the issue of retrieving proper links to tenor gif embeds, allowing pinned messages to embed the tenor gif posted. The solution was really stupid, too. Thanks Tenor. -Rewrote pins to now also store the id of the user whom the pinned message was authored by. -Added variant of CheckPinID for turbo pins. -Made all economy commands reference once instance of Random() instead of creating their own instance every time. -Condensed code in the Wheel command by using two arrays, instead of a switch statement. -Removed old commented-out code from EconomyCommands and SlashCommands. -Removed pointless usings in SlashCommands.
This commit is contained in:
parent
193deba267
commit
fc00374f7d
|
@ -7,7 +7,7 @@ namespace SuperMachoBot.Commands
|
|||
public class EconomyCommands : ApplicationCommandModule
|
||||
{
|
||||
public static string jsonPath = "";
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
#region Economy Commands
|
||||
|
||||
|
@ -37,7 +37,7 @@ namespace SuperMachoBot.Commands
|
|||
public void CreateEconomyEntry(ulong userid, UserData data, ulong guildid)
|
||||
{
|
||||
// Add a new entry to the dictionary
|
||||
string jsonFilePath = @$"{jsonPath}{guildid}.json";
|
||||
string jsonFilePath = @$"{jsonPath}/{guildid}/Economy.json";
|
||||
|
||||
ulong newUserId = userid;
|
||||
|
||||
|
@ -55,7 +55,11 @@ namespace SuperMachoBot.Commands
|
|||
|
||||
public void CreateEconomyFile(ulong initialUserID, UserData initialUserData, ulong guildid)
|
||||
{
|
||||
string jsonFilePath = @$"{jsonPath}{guildid}.json";
|
||||
if (!Directory.Exists(@$"{jsonPath}/{guildid}/"))
|
||||
{
|
||||
Directory.CreateDirectory(@$"{jsonPath}/{guildid}/");
|
||||
}
|
||||
string jsonFilePath = @$"{jsonPath}/{guildid}/Economy.json";
|
||||
var dataDict = new Dictionary<ulong, UserData>();
|
||||
dataDict.Add(initialUserID, initialUserData);
|
||||
string newJson = JsonConvert.SerializeObject(dataDict, Formatting.Indented);
|
||||
|
@ -64,8 +68,12 @@ namespace SuperMachoBot.Commands
|
|||
|
||||
public UserData GetEconomyEntry(ulong userid, ulong guildid)
|
||||
{
|
||||
string jsonFilePath = @$"{jsonPath}{guildid}.json";
|
||||
string jsonFilePath = @$"{jsonPath}/{guildid}/Economy.json";
|
||||
// Read the JSON file and deserialize it into a dictionary
|
||||
if (!Directory.Exists(jsonFilePath))
|
||||
{
|
||||
Directory.CreateDirectory(@$"{jsonPath}/{guildid}/");
|
||||
}
|
||||
if (!File.Exists(jsonFilePath))
|
||||
{
|
||||
File.Create(jsonFilePath).Close();
|
||||
|
@ -101,7 +109,7 @@ namespace SuperMachoBot.Commands
|
|||
|
||||
public Dictionary<ulong, UserData> GetEconomyEntries(ulong guildid)
|
||||
{
|
||||
string jsonFilePath = @$"{jsonPath}{guildid}.json";
|
||||
string jsonFilePath = @$"{jsonPath}/{guildid}/Economy.json";
|
||||
// Read the JSON file and deserialize it into a dictionary
|
||||
if (!File.Exists(jsonFilePath))
|
||||
{
|
||||
|
@ -121,7 +129,7 @@ namespace SuperMachoBot.Commands
|
|||
|
||||
public void EditEconomyEntry(ulong userid, UserData data, ulong guildid)
|
||||
{
|
||||
string jsonFilePath = @$"{jsonPath}{guildid}.json";
|
||||
string jsonFilePath = @$"{jsonPath}/{guildid}/Economy.json";
|
||||
string json = File.ReadAllText(jsonFilePath);
|
||||
var userDataDict = JsonConvert.DeserializeObject<Dictionary<ulong, UserData>>(json);
|
||||
|
||||
|
@ -232,7 +240,6 @@ namespace SuperMachoBot.Commands
|
|||
[SlashCommand("Betflip", "Bet your money on a coin flip!")]
|
||||
public async Task BetFlipCommand(InteractionContext ctx, [Option("Amount", "Amount to bet")] long amount, [Option("Choice", "Make your choice....")] BetflipChoice choice = BetflipChoice.heads)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
var entry = GetEconomyEntry(ctx.User.Id, ctx.Guild.Id);
|
||||
if (entry == null)
|
||||
{
|
||||
|
@ -310,7 +317,6 @@ namespace SuperMachoBot.Commands
|
|||
[SlashCommand("Wheel", "Spin the wheel of CobFortune™")]
|
||||
public async Task WheelCommand(InteractionContext ctx, [Option("Amount", "Amount to bet")] long amount)
|
||||
{
|
||||
Random rnd = new Random();
|
||||
var entry = GetEconomyEntry(ctx.User.Id, ctx.Guild.Id);
|
||||
if(entry == null)
|
||||
{
|
||||
|
@ -318,6 +324,7 @@ namespace SuperMachoBot.Commands
|
|||
}
|
||||
var roll = rnd.Next(0, 7);
|
||||
double multiplier = 1;
|
||||
double[] multiplierTable = new double[] { -1.4, -0.8, -0.4, 1, 1.4, 1.8, 2.4 };
|
||||
if (amount <= 0)
|
||||
{
|
||||
await ctx.CreateResponseAsync($"Invalid amount! Try again!");
|
||||
|
@ -327,30 +334,7 @@ namespace SuperMachoBot.Commands
|
|||
await ctx.CreateResponseAsync($"YOU CANNOT AFFORD! TRY AGAIN!");
|
||||
return;
|
||||
}
|
||||
switch (roll)
|
||||
{
|
||||
case 0:
|
||||
multiplier = -1.4;
|
||||
break;
|
||||
case 1:
|
||||
multiplier = -0.8;
|
||||
break;
|
||||
case 2:
|
||||
multiplier = -0.4;
|
||||
break;
|
||||
case 3:
|
||||
multiplier = 1;
|
||||
break;
|
||||
case 4:
|
||||
multiplier = 1.4;
|
||||
break;
|
||||
case 5:
|
||||
multiplier = 1.8;
|
||||
break;
|
||||
case 6:
|
||||
multiplier = 2.4;
|
||||
break;
|
||||
}
|
||||
multiplier = multiplierTable[roll];
|
||||
var money = amount * multiplier - amount;
|
||||
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money + (long)money, lastDaily = entry.lastDaily }, ctx.Guild.Id);
|
||||
if(money < 0)
|
||||
|
|
|
@ -166,6 +166,7 @@ namespace SuperMachoBot.Commands
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Hidden]
|
||||
[Command("setactivity")]
|
||||
private async Task SetActivityCommand(CommandContext ctx)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using DSharpPlus.Entities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using Newtonsoft.Json;
|
||||
using static System.Net.WebRequestMethods;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SuperMachoBot.Commands
|
||||
{
|
||||
|
@ -88,14 +86,65 @@ namespace SuperMachoBot.Commands
|
|||
await ctx.CreateResponseAsync(embed);
|
||||
}
|
||||
|
||||
[SlashCommand("OwnerSetup", "Allows the owner to setup/change their guilds SuperMachoBot settings.")]
|
||||
public async Task OwnerSetupCommand(InteractionContext ctx, [Option("gemboard", "Channel to designate as gemboard.")] DiscordChannel dc,
|
||||
[Option("gemamount", "Amount of gems required for a message to be added to gemboard.")] long gemAmount,
|
||||
[Option("turboamount", "Amount of gem/coal required for a message to be added to gemboard as a gemerald/brimstone.")] long turboAmount,
|
||||
[Option("gemEmoteId", "ID of emote to use as gem.")] string gemEmoteId,
|
||||
[Option("coalEmoteId", "ID of emote to use as coal.")] string coalEmoteId)
|
||||
{
|
||||
if (ctx.Member.IsOwner)
|
||||
{
|
||||
if (!Directory.Exists(@$"{Program.databasePath}/{ctx.Guild.Id}/"))
|
||||
{
|
||||
Directory.CreateDirectory(@$"{Program.databasePath}/{ctx.Guild.Id}/");
|
||||
}
|
||||
if (!File.Exists(@$"{Program.databasePath}/{ctx.Guild.Id}/Config.json"))
|
||||
{
|
||||
File.Create(@$"{Program.databasePath}/{ctx.Guild.Id}/Config.json").Close();
|
||||
}
|
||||
if(!ulong.TryParse(gemEmoteId, out var gemEmoteParsed))
|
||||
{
|
||||
await ctx.CreateResponseAsync("Invalid gem id! Try again!");
|
||||
} else if (!ulong.TryParse(coalEmoteId, out var coalEmoteParsed))
|
||||
{
|
||||
await ctx.CreateResponseAsync("Invalid coal id! Try again!");
|
||||
} else {
|
||||
var config = new List<GuildConfig>();
|
||||
var configuration = new GuildConfig()
|
||||
{
|
||||
gemboardChannelId = dc.Id,
|
||||
gemAmount = gemAmount,
|
||||
turboAmount = turboAmount,
|
||||
gemEmoteId = gemEmoteParsed,
|
||||
coalEmoteId = coalEmoteParsed
|
||||
};
|
||||
if(Tools.General.CreateConfig(configuration, ctx.Guild.Id))
|
||||
{
|
||||
await ctx.CreateResponseAsync($"Configuration applied successfully!");
|
||||
} else
|
||||
{
|
||||
await ctx.CreateResponseAsync($"Configuration NOT applied successfully! Yell at bot developer! NOW!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await ctx.CreateResponseAsync("You aren't owner. Stop trying to do owner stuff when you aren't an owner, peasant.");
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("EmbeddingTest", "Sends a placeholder embed for gemboard.")]
|
||||
public async Task UserInfoCommand(InteractionContext ctx)
|
||||
{
|
||||
var bruhgimus = new DiscordEmbedBuilder { Title = $"GEM ALERT!",
|
||||
var bruhgimus = new DiscordEmbedBuilder
|
||||
{
|
||||
Title = $"GEM ALERT!",
|
||||
Description = $@"""https://twitter.com/cametek/status/1626024042254962688?t=qO5w7KG_5pAO2fBc0D3zOg&s=19""" + "\n" + "",
|
||||
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://images-ext-2.discordapp.net/external/eF0rSZ4LMUqftzoQmSqKq9P4-nGoyU7W7G74KSnLSls/https/pbs.twimg.com/ext_tw_video_thumb/1626022911822934016/pu/img/7yXC_-9lc9dWtC07.jpg"},
|
||||
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://images-ext-2.discordapp.net/external/eF0rSZ4LMUqftzoQmSqKq9P4-nGoyU7W7G74KSnLSls/https/pbs.twimg.com/ext_tw_video_thumb/1626022911822934016/pu/img/7yXC_-9lc9dWtC07.jpg" },
|
||||
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = ctx.User.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = "TestUser#0000" },
|
||||
Color = DiscordColor.Red }.AddField("Gem:", "[link](https://discord.com/channels/977270567881298021/977270567881298024/1075763823740461056)").Build();
|
||||
Color = DiscordColor.Red
|
||||
}.AddField("Gem:", "[link](https://discord.com/channels/977270567881298021/977270567881298024/1075763823740461056)").Build();
|
||||
await ctx.CreateResponseAsync(bruhgimus);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
using DSharpPlus;
|
||||
using DSharpPlus.CommandsNext;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using SuperMachoBot.Commands;
|
||||
using Newtonsoft.Json;
|
||||
using DSharpPlus.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Drawing;
|
||||
using Emzi0767.Utilities;
|
||||
using DSharpPlus.SlashCommands;
|
||||
using Newtonsoft.Json;
|
||||
using SuperMachoBot.Commands;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace SuperMachoBot
|
||||
{
|
||||
|
@ -16,7 +15,7 @@ namespace SuperMachoBot
|
|||
public static bool moneyCooldown = true;
|
||||
public static List<Config> configItems = new List<Config>();
|
||||
public static DiscordClient discord;
|
||||
public static string pinnedPath = "";
|
||||
public static string databasePath = "";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
MainAsync().GetAwaiter().GetResult();
|
||||
|
@ -43,26 +42,26 @@ namespace SuperMachoBot
|
|||
|
||||
};
|
||||
|
||||
pinnedPath = @$"{configItems[0].EconomyDatabasePath}Pinned.txt";
|
||||
discord.MessageReactionAdded += async (s, e) =>
|
||||
databasePath = configItems[0].EconomyDatabasePath;
|
||||
discord.MessageReactionAdded += async (s, e) => //Spaghetti central.
|
||||
{
|
||||
if (e.Emoji.Id == 1075778692959183049) //Gem
|
||||
try //I don't think this is good practice. Fuck it.
|
||||
{
|
||||
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
|
||||
{
|
||||
var message = await e.Channel.GetMessageAsync(e.Message.Id);
|
||||
if(message.Reactions[0].Count > 4 && !CheckPinID(message.Id))
|
||||
foreach (var reaction in message.Reactions)
|
||||
{
|
||||
string thumbnailURL = "";
|
||||
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 = "";
|
||||
if (message.Embeds.Count > 0)
|
||||
{
|
||||
//thumbnailURL = bruh.Embeds[0].Image.Url.ToString();
|
||||
}
|
||||
if (message.Attachments.Count > 0)
|
||||
{
|
||||
thumbnailURL = message.Attachments[0].Url;
|
||||
}
|
||||
|
||||
if(message.Content != "")
|
||||
if (message.Content != "")
|
||||
{
|
||||
desc = $@"""{message.Content}""";
|
||||
}
|
||||
|
@ -76,29 +75,55 @@ namespace SuperMachoBot
|
|||
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(1075588362230042694).Result, bruhgimus);
|
||||
File.AppendAllText(pinnedPath, message.Id.ToString() + "\n");
|
||||
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, bruhgimus);
|
||||
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/Pinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
|
||||
}
|
||||
}
|
||||
if (e.Emoji.Id == 1075778708629110885) //Coal
|
||||
}
|
||||
}
|
||||
if (e.Emoji.Id == config[0].gemEmoteId) //GEMERALD!!
|
||||
{
|
||||
var message = await e.Channel.GetMessageAsync(e.Message.Id);
|
||||
foreach (var reaction in message.Reactions)
|
||||
{
|
||||
if(reaction.Emoji.Id == 1075778708629110885)
|
||||
if (reaction.Emoji.Id == config[0].gemEmoteId)
|
||||
{
|
||||
if (reaction.Count > 4 && !CheckPinID(message.Id))
|
||||
if (reaction.Count > config[0].turboAmount - 1 && !CheckUltraPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
|
||||
{
|
||||
string thumbnailURL = "";
|
||||
string thumbnailURL = GetRelevantEmbedURL(message);
|
||||
string desc = "";
|
||||
if(message.Embeds.Count > 0)
|
||||
|
||||
if (message.Content != "")
|
||||
{
|
||||
thumbnailURL = message.Embeds[0].Image.Url.ToString();
|
||||
desc = $@"""{message.Content}""";
|
||||
}
|
||||
if (message.Attachments.Count > 0)
|
||||
|
||||
var bruhgimus = new DiscordEmbedBuilder
|
||||
{
|
||||
thumbnailURL = message.Attachments[0].Url;
|
||||
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);
|
||||
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/UltraPinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (e.Emoji.Id == config[0].coalEmoteId) //Coal
|
||||
{
|
||||
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].gemAmount - 1 && !CheckPinID(message.Id, message.Channel.GuildId) && message.ChannelId != config[0].gemboardChannelId && !message.Channel.IsNSFW)
|
||||
{
|
||||
string thumbnailURL = GetRelevantEmbedURL(message);
|
||||
string desc = "";
|
||||
|
||||
if (message.Content != "")
|
||||
{
|
||||
|
@ -114,8 +139,40 @@ namespace SuperMachoBot
|
|||
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(1075588362230042694).Result, embed);
|
||||
File.AppendAllText(pinnedPath, message.Id.ToString() + "\n");
|
||||
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
|
||||
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/Pinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 = "";
|
||||
|
||||
if (message.Content != "")
|
||||
{
|
||||
desc = $@"""{message.Content}""";
|
||||
}
|
||||
|
||||
var embed = new DiscordEmbedBuilder
|
||||
{
|
||||
Title = $"BRIMSTONE!!!! HELLISH TORTURECOAL ALERT!!!! {config[0].turboAmount}+ COALS!!!!",
|
||||
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("Brimstone:", $"[link]({message.JumpLink})").Build();
|
||||
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
|
||||
File.AppendAllText($"{databasePath}/{message.Channel.GuildId}/Pinned.txt", message.Id.ToString() + $",{message.Author.Id}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,10 +180,10 @@ namespace SuperMachoBot
|
|||
bool debug = true;
|
||||
if (e.Emoji.Id == 959642740277252136) //Delete
|
||||
{
|
||||
var bruh = await e.Channel.GetMessageAsync(e.Message.Id);
|
||||
if(e.User.Id == 304033317513199617 && bruh.Author.Id == 305520963238494219) //Only let me delete messages from the bot, so it's not a le epic backdoor.
|
||||
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 bruh.DeleteAsync();
|
||||
await bruha.DeleteAsync();
|
||||
}
|
||||
}
|
||||
if (e.Emoji.Id == 820033186008399903) //Debug
|
||||
|
@ -146,7 +203,7 @@ namespace SuperMachoBot
|
|||
{
|
||||
thumbnailURL = message.Embeds[0].Thumbnail.Url.ToString();
|
||||
var video = message.Embeds[0].Video;
|
||||
if(video != null)
|
||||
if (video != null)
|
||||
{
|
||||
thumbnailURL = video.Url.ToString();
|
||||
}
|
||||
|
@ -170,13 +227,18 @@ namespace SuperMachoBot
|
|||
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(1075588362230042694).Result, embed);
|
||||
await discord.SendMessageAsync(discord.GetChannelAsync(config[0].gemboardChannelId).Result, embed);
|
||||
//File.AppendAllText(pinnedPath, bruh.Id.ToString() + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var commands = discord.UseCommandsNext(new CommandsNextConfiguration()
|
||||
|
@ -190,7 +252,6 @@ namespace SuperMachoBot
|
|||
EconomyCommands.jsonPath = configItems[0].EconomyDatabasePath;
|
||||
|
||||
Console.WriteLine(EconomyCommands.jsonPath);
|
||||
Console.WriteLine(pinnedPath);
|
||||
|
||||
await discord.ConnectAsync();
|
||||
await Task.Delay(-1);
|
||||
|
@ -202,17 +263,85 @@ namespace SuperMachoBot
|
|||
moneyCooldown = false;
|
||||
}
|
||||
|
||||
static bool CheckPinID(ulong messageid)
|
||||
static bool CheckPinID(ulong messageid, ulong? guildid)
|
||||
{
|
||||
foreach (var line in File.ReadAllLines(pinnedPath))
|
||||
if (!Directory.Exists($"{databasePath}/{guildid}/"))
|
||||
{
|
||||
if(line == messageid.ToString())
|
||||
Directory.CreateDirectory(@$"{databasePath}/{guildid}/");
|
||||
}
|
||||
if (!File.Exists($"{databasePath}/{guildid}/Pinned.txt"))
|
||||
{
|
||||
File.Create(@$"{databasePath}/{guildid}/Pinned.txt").Close();
|
||||
}
|
||||
foreach (var line in File.ReadAllLines($"{databasePath}/{guildid}/Pinned.txt"))
|
||||
{
|
||||
if (line.Split(',')[0] == messageid.ToString())
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
public class Config
|
||||
{
|
||||
|
@ -220,4 +349,13 @@ namespace SuperMachoBot
|
|||
public ulong OwnerID;
|
||||
public string EconomyDatabasePath;
|
||||
}
|
||||
|
||||
public class GuildConfig
|
||||
{
|
||||
public ulong gemboardChannelId;
|
||||
public long gemAmount;
|
||||
public long turboAmount;
|
||||
public ulong gemEmoteId;
|
||||
public ulong coalEmoteId;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using DSharpPlus.Entities;
|
||||
using DSharpPlus;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SuperMachoBot.Tools
|
||||
{
|
||||
|
@ -43,6 +44,20 @@ namespace SuperMachoBot.Tools
|
|||
return du.GetAvatarUrl(ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CreateConfig (GuildConfig guildConfig, ulong guildId)
|
||||
{
|
||||
try {
|
||||
var config = new List<GuildConfig>();
|
||||
config.Add(guildConfig);
|
||||
string newJson = JsonConvert.SerializeObject(config, Formatting.Indented);
|
||||
File.WriteAllText(@$"{Program.databasePath}/{guildId}/Config.json", newJson);
|
||||
return true;
|
||||
} catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Exception occured in config creation: {e.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
class Economy
|
||||
{
|
||||
|
@ -54,3 +69,4 @@ namespace SuperMachoBot.Tools
|
|||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue