mirror of
https://github.com/Brazmann/SuperMachoBot.git
synced 2025-01-03 10:46:44 +00:00
Removed code commentsDatabase/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
fae4dc0ec9
|
@ -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)
|
||||
|
@ -383,312 +367,6 @@ namespace SuperMachoBot.Commands
|
|||
await ctx.CreateResponseAsync($"Can't claim daily yet! Come back in {displayInfo} hours! coalposter!");
|
||||
}
|
||||
}
|
||||
|
||||
/*[SlashCommand("Balance", "Checks your balance")]
|
||||
public async Task BalanceCommand(InteractionContext ctx, [Option("User", "User to check balance of")] DiscordUser du)
|
||||
{
|
||||
var entry = EconDatabaseChecker(du.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
if (entry[0] == "noentry")
|
||||
{
|
||||
await ctx.CreateResponseAsync("No entry found! Generating one, please try again.");
|
||||
}
|
||||
await ctx.CreateResponseAsync($"{du.Username}: ${entryParsed[1]}");
|
||||
}
|
||||
|
||||
|
||||
[ContextMenu(ApplicationCommandType.UserContextMenu, "Check balance")]
|
||||
public async Task BalanceMenuCommand(ContextMenuContext ctx)
|
||||
{
|
||||
var entry = EconDatabaseChecker(ctx.TargetUser.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
if (entry[0] == "noentry")
|
||||
{
|
||||
await ctx.CreateResponseAsync("No entry found! Generating one, please try again.");
|
||||
}
|
||||
await ctx.CreateResponseAsync($"{ctx.TargetUser.Username}: ${entryParsed[1]}");
|
||||
}
|
||||
|
||||
[SlashCommand("Daily", "Adds $100 to your balance")]
|
||||
public async Task DailyCommand(InteractionContext ctx)
|
||||
{
|
||||
var path = $@"{rootPath}\EconomyDatabase\{ctx.Guild.Id}.csv";
|
||||
var amount = 100;
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
if (entryParsed[2] == "none")
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{entryParsed[0]}|{entryParsed[1]}|{unixTimestamp}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync("First daily! Come back in 24 hours!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 secondsSinceLastDaily = unixTimestamp - Convert.ToInt32(entryParsed[2]);
|
||||
if (secondsSinceLastDaily > 86400) //Check if a day has passed
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{entryParsed[0]}|{entryParsed[1]}|{unixTimestamp}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync("Daily claimed! Come back in 24 hours!");
|
||||
}
|
||||
else if (secondsSinceLastDaily < 86400)
|
||||
{
|
||||
var secondsUntilClaim = 86400 - secondsSinceLastDaily;
|
||||
await ctx.CreateResponseAsync($"Daily already claimed! Come back in {secondsUntilClaim / 3600} hours!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("Transfer", "Transfer your money to another user.")]
|
||||
public async Task TransferCommand(InteractionContext ctx, [Option("Amount", "Amount to transfer")] long amount, [Option("User", "User to transfer money to")] DiscordUser du)
|
||||
{
|
||||
if (amount < 0)
|
||||
{
|
||||
await ctx.CreateResponseAsync("Negative amount detected! Sorry, robbery has not been implemented yet!");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, -amount);
|
||||
AddSubtractUserMoney(du.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync($"${amount} transferred from {ctx.User.Mention} to {du.Mention}");
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("Twash", "The.")]
|
||||
public async Task TwashCommand(InteractionContext ctx, [Option("Year", "Age")]long age)
|
||||
{
|
||||
string message = $"{age} year old Twash be like: anyone under {age + 4} is an infant to me now.";
|
||||
await ctx.CreateResponseAsync(message);
|
||||
}
|
||||
|
||||
[SlashCommand("Betflip", "Heads or Tails coinflip!")]
|
||||
public async Task BetflipCommand(InteractionContext ctx, [Option("Choice", "Heads or Tails? H or T? Choose your path wisely.")] string choice, [Option("Amount", "Real: (typing 'All' currently doesn't work, do it manually.)")] long betAmount)
|
||||
{
|
||||
var uid = ctx.User.Id;
|
||||
var gid = ctx.Guild.Id;
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var playerMoney = Convert.ToInt64(entryParsed[1]);
|
||||
var moneyEarned = 0;
|
||||
if (betAmount > playerMoney)
|
||||
{
|
||||
await ctx.CreateResponseAsync("You do not have enough money!");
|
||||
}
|
||||
else
|
||||
{
|
||||
int flip = rnd.Next(1, 3); // 1 = heads, 2 = tails
|
||||
string decision = "";
|
||||
string headsURL = "https://cdn.discordapp.com/attachments/978411926222684220/1006493578186469376/domcoinheads.png";
|
||||
string tailsURL = "https://cdn.discordapp.com/attachments/978411926222684220/1006493587342622730/domcointails.png";
|
||||
switch (choice.ToLower())
|
||||
{
|
||||
case "h":
|
||||
case "head":
|
||||
case "heads":
|
||||
decision = "heads";
|
||||
break;
|
||||
case "t":
|
||||
case "tail":
|
||||
case "tails":
|
||||
decision = "tails";
|
||||
break;
|
||||
}
|
||||
if (decision.ToLower() == "heads")
|
||||
{
|
||||
switch (flip)
|
||||
{
|
||||
case 1:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Heads! You win ${betAmount}!", ImageUrl = headsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, betAmount);
|
||||
break;
|
||||
case 2:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Tails! You lose ${betAmount}!", ImageUrl = tailsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, -betAmount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (decision.ToLower() == "tails")
|
||||
{
|
||||
switch (flip)
|
||||
{
|
||||
case 1:
|
||||
await ctx.CreateResponseAsync("Heads! You lose!");
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Heads! You lose ${betAmount}!", ImageUrl = headsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, -betAmount);
|
||||
break;
|
||||
case 2:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Tails! You win ${betAmount}!", ImageUrl = tailsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, betAmount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[SlashCommand("Wheel", "Roll the wheel of Macho Fortune!")]
|
||||
public async Task WheelCommand(InteractionContext ctx, [Option("Amount", "Real: (typing 'All' currently doesn't work, do it manually.)")] long betAmount)
|
||||
{
|
||||
if (betAmount < 0)
|
||||
{
|
||||
await ctx.CreateResponseAsync("Negative numbers are not allowed!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
double playerMoney = Convert.ToDouble(entryParsed[1]);
|
||||
double moneyEarned = 0;
|
||||
if (betAmount > playerMoney)
|
||||
{
|
||||
await ctx.CreateResponseAsync("You do not have enough money!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var roll = rnd.Next(1, 8);
|
||||
double multiplier = 1;
|
||||
bool shit = false;
|
||||
switch (roll)
|
||||
{
|
||||
case 1:
|
||||
multiplier = 2.4;
|
||||
shit = true;
|
||||
break;
|
||||
case 2:
|
||||
multiplier = 1.8;
|
||||
shit = true;
|
||||
break;
|
||||
case 3:
|
||||
multiplier = 1.4;
|
||||
shit = true;
|
||||
break;
|
||||
case 4:
|
||||
multiplier = 0;
|
||||
break;
|
||||
case 5:
|
||||
multiplier = 1.4;
|
||||
break;
|
||||
case 6:
|
||||
multiplier = 1.8;
|
||||
break;
|
||||
case 7:
|
||||
multiplier = 2.4;
|
||||
break;
|
||||
}
|
||||
if (shit == true)
|
||||
{
|
||||
moneyEarned = betAmount * multiplier;
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, -Convert.ToInt64(moneyEarned));
|
||||
await ctx.CreateResponseAsync($"Money multiplied by -{multiplier}x, lost ${moneyEarned}! Sad!");
|
||||
}
|
||||
else
|
||||
{
|
||||
moneyEarned = betAmount * multiplier;
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, Convert.ToInt64(moneyEarned));
|
||||
await ctx.CreateResponseAsync($"Money multiplied by {multiplier}x, ${moneyEarned}!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Economy Tools (I really need to stuff this into the library)
|
||||
public void AddSubtractUserMoney(ulong userID, ulong guildID, long amount)
|
||||
{
|
||||
var entry = EconDatabaseChecker(userID, guildID);
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var currentAmount = entryParsed[1];
|
||||
long finalAmount = Convert.ToInt64(currentAmount) + amount;
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{userID}|{finalAmount.ToString()}|{entryParsed[2]}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
}
|
||||
//Thank you microsoft for requiring a rewrite of your entire method just to not have it add an extra new line at the end of a file. :tf:
|
||||
public static void WriteAllLinesBetter(string path, params string[] lines)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
if (lines == null)
|
||||
throw new ArgumentNullException("lines");
|
||||
|
||||
using (var stream = File.OpenWrite(path))
|
||||
using (StreamWriter writer = new StreamWriter(stream))
|
||||
{
|
||||
if (lines.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < lines.Length - 1; i++)
|
||||
{
|
||||
writer.WriteLine(lines[i]);
|
||||
}
|
||||
writer.Write(lines[lines.Length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void MultiplyUserMoney(ulong userID, ulong guildID, float multiplier)
|
||||
{
|
||||
var entry = EconDatabaseChecker(userID, guildID);
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var currentAmount = entryParsed[1];
|
||||
float finalAmount = float.Parse(currentAmount) * multiplier;
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{userID}|{finalAmount.ToString()}";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds the economy database entry for the specified UserID, or creates a new entry for the server/user if an entry for one is missing.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The contents, and line number of the entry if found, in a string array.
|
||||
/// </returns>
|
||||
public static string[] EconDatabaseChecker(ulong userID, ulong guildID)
|
||||
{
|
||||
int lineCount = 0;
|
||||
string[] entry = { "noentry", "bingus" };
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
if (File.Exists(path) == false)
|
||||
{
|
||||
string entryToCreate = $"{userID}|100|none";
|
||||
File.AppendAllText(path, entryToCreate);
|
||||
}
|
||||
|
||||
foreach (var line in File.ReadAllLines(path))
|
||||
{
|
||||
var entryparsed = line.Split('|');
|
||||
lineCount++;
|
||||
if (entryparsed[0] == userID.ToString())
|
||||
{
|
||||
entry[0] = line; //Contents of entry line
|
||||
entry[1] = $"{lineCount}"; //Number of line in .csv file
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry[0] == "noentry") //If after the file has been searched, no entry has been found, create a new one and stuff it in the 'entry' variable
|
||||
{
|
||||
string entryToCreate = $"{userID}|100|none";
|
||||
File.AppendAllText(path, Environment.NewLine + entryToCreate);
|
||||
return entry;
|
||||
}
|
||||
return entry;
|
||||
}*/
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class UserData
|
||||
|
|
|
@ -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,422 +86,67 @@ 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" },
|
||||
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);
|
||||
}
|
||||
|
||||
/*[SlashCommand("Testing", "Tests.")]
|
||||
public async Task TestingCommand(InteractionContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
int[] row1 = new int[6] { 0, 0, 0, 0, 0, 0 }; //row = Y axis, entries within array = X axis. 0 = empty, 1 = player.
|
||||
StringBuilder sb = new StringBuilder("", row1.Length);
|
||||
var path = @$"{rootPath}\FunDatabase\MapTest\{ctx.User.Id}.json";
|
||||
|
||||
if (File.Exists(path) == false)
|
||||
{
|
||||
List<PlayerData> playerData = new List<PlayerData>();
|
||||
|
||||
playerData.Add(new PlayerData()
|
||||
{
|
||||
CoordinateY = 1,
|
||||
CoordinateX = 4
|
||||
});
|
||||
string json = JsonConvert.SerializeObject(playerData.ToArray());
|
||||
|
||||
File.AppendAllText(path, json);
|
||||
}
|
||||
string playerDataJson = File.ReadAllText(path);
|
||||
|
||||
var playerDataParsed = JsonConvert.DeserializeObject<List<PlayerData>>(playerDataJson);
|
||||
|
||||
|
||||
for (int i = 0; i < row1.Length; i++)
|
||||
{
|
||||
if (i == playerDataParsed[0].CoordinateX)
|
||||
{
|
||||
sb.Append(":person_in_motorized_wheelchair:");
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (row1[i])
|
||||
{
|
||||
case 0:
|
||||
sb.Append(":eight_pointed_black_star:");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var builder = new DiscordMessageBuilder().WithContent(sb.ToString()).AddComponents(new DiscordComponent[]
|
||||
{
|
||||
new DiscordButtonComponent(ButtonStyle.Primary, "1_left", "Left"),
|
||||
new DiscordButtonComponent(ButtonStyle.Secondary, "2_up", "Up"),
|
||||
new DiscordButtonComponent(ButtonStyle.Success, "3_down", "Down"),
|
||||
new DiscordButtonComponent(ButtonStyle.Danger, "4_right", "Right")
|
||||
}).SendAsync(ctx.Channel);
|
||||
|
||||
ctx.Client.ComponentInteractionCreated += async (s, e) =>
|
||||
{
|
||||
Console.WriteLine("Ben?");
|
||||
int playerY = playerDataParsed[0].CoordinateY;
|
||||
int playerX = playerDataParsed[0].CoordinateX;
|
||||
switch (e.Interaction.Data.CustomId)
|
||||
{
|
||||
case "1_left":
|
||||
if(playerX > 0)
|
||||
{
|
||||
playerX = playerX - 1;
|
||||
}
|
||||
break;
|
||||
case "2_up":
|
||||
break;
|
||||
case "3_down":
|
||||
break;
|
||||
case "4_right":
|
||||
if(playerX < 5)
|
||||
{
|
||||
playerX++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
Console.WriteLine($"playerX: {playerX} playerY: {playerY}");
|
||||
await e.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, new DiscordInteractionResponseBuilder().WithContent(":thumbsup:"));
|
||||
|
||||
List<PlayerData> playerDataNew = new List<PlayerData>();
|
||||
|
||||
playerDataNew.Add(new PlayerData()
|
||||
{
|
||||
CoordinateY = playerY,
|
||||
CoordinateX = playerX
|
||||
});
|
||||
string json = JsonConvert.SerializeObject(playerDataNew.ToArray());
|
||||
|
||||
File.WriteAllText(path, json);
|
||||
TestingCommand(ctx);
|
||||
|
||||
};
|
||||
} catch (Exception ex)
|
||||
{
|
||||
await ctx.CreateResponseAsync(ex.Message);
|
||||
}
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
#region Economy Commands
|
||||
/*[SlashCommand("Balance", "Checks your balance")]
|
||||
public async Task BalanceCommand(InteractionContext ctx, [Option("User", "User to check balance of")] DiscordUser du)
|
||||
{
|
||||
var entry = EconDatabaseChecker(du.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
if (entry[0] == "noentry")
|
||||
{
|
||||
await ctx.CreateResponseAsync("No entry found! Generating one, please try again.");
|
||||
}
|
||||
await ctx.CreateResponseAsync($"{du.Username}: ${entryParsed[1]}");
|
||||
}
|
||||
|
||||
|
||||
[ContextMenu(ApplicationCommandType.UserContextMenu, "Check balance")]
|
||||
public async Task BalanceMenuCommand(ContextMenuContext ctx)
|
||||
{
|
||||
var entry = EconDatabaseChecker(ctx.TargetUser.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
if (entry[0] == "noentry")
|
||||
{
|
||||
await ctx.CreateResponseAsync("No entry found! Generating one, please try again.");
|
||||
}
|
||||
await ctx.CreateResponseAsync($"{ctx.TargetUser.Username}: ${entryParsed[1]}");
|
||||
}
|
||||
|
||||
[SlashCommand("Daily", "Adds $100 to your balance")]
|
||||
public async Task DailyCommand(InteractionContext ctx)
|
||||
{
|
||||
var path = $@"{rootPath}\EconomyDatabase\{ctx.Guild.Id}.csv";
|
||||
var amount = 100;
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
if (entryParsed[2] == "none")
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{entryParsed[0]}|{entryParsed[1]}|{unixTimestamp}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync("First daily! Come back in 24 hours!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Int32 secondsSinceLastDaily = unixTimestamp - Convert.ToInt32(entryParsed[2]);
|
||||
if (secondsSinceLastDaily > 86400) //Check if a day has passed
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{entryParsed[0]}|{entryParsed[1]}|{unixTimestamp}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync("Daily claimed! Come back in 24 hours!");
|
||||
}
|
||||
else if (secondsSinceLastDaily < 86400)
|
||||
{
|
||||
var secondsUntilClaim = 86400 - secondsSinceLastDaily;
|
||||
await ctx.CreateResponseAsync($"Daily already claimed! Come back in {secondsUntilClaim / 3600} hours!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("Transfer", "Transfer your money to another user.")]
|
||||
public async Task TransferCommand(InteractionContext ctx, [Option("Amount", "Amount to transfer")] long amount, [Option("User", "User to transfer money to")] DiscordUser du)
|
||||
{
|
||||
if (amount < 0)
|
||||
{
|
||||
await ctx.CreateResponseAsync("Negative amount detected! Sorry, robbery has not been implemented yet!");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, -amount);
|
||||
AddSubtractUserMoney(du.Id, ctx.Guild.Id, amount);
|
||||
await ctx.CreateResponseAsync($"${amount} transferred from {ctx.User.Mention} to {du.Mention}");
|
||||
}
|
||||
}
|
||||
|
||||
[SlashCommand("Twash", "The.")]
|
||||
public async Task TwashCommand(InteractionContext ctx, [Option("Year", "Age")]long age)
|
||||
{
|
||||
string message = $"{age} year old Twash be like: anyone under {age + 4} is an infant to me now.";
|
||||
await ctx.CreateResponseAsync(message);
|
||||
}
|
||||
|
||||
[SlashCommand("Betflip", "Heads or Tails coinflip!")]
|
||||
public async Task BetflipCommand(InteractionContext ctx, [Option("Choice", "Heads or Tails? H or T? Choose your path wisely.")] string choice, [Option("Amount", "Real: (typing 'All' currently doesn't work, do it manually.)")] long betAmount)
|
||||
{
|
||||
var uid = ctx.User.Id;
|
||||
var gid = ctx.Guild.Id;
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var playerMoney = Convert.ToInt64(entryParsed[1]);
|
||||
var moneyEarned = 0;
|
||||
if (betAmount > playerMoney)
|
||||
{
|
||||
await ctx.CreateResponseAsync("You do not have enough money!");
|
||||
}
|
||||
else
|
||||
{
|
||||
int flip = rnd.Next(1, 3); // 1 = heads, 2 = tails
|
||||
string decision = "";
|
||||
string headsURL = "https://cdn.discordapp.com/attachments/978411926222684220/1006493578186469376/domcoinheads.png";
|
||||
string tailsURL = "https://cdn.discordapp.com/attachments/978411926222684220/1006493587342622730/domcointails.png";
|
||||
switch (choice.ToLower())
|
||||
{
|
||||
case "h":
|
||||
case "head":
|
||||
case "heads":
|
||||
decision = "heads";
|
||||
break;
|
||||
case "t":
|
||||
case "tail":
|
||||
case "tails":
|
||||
decision = "tails";
|
||||
break;
|
||||
}
|
||||
if (decision.ToLower() == "heads")
|
||||
{
|
||||
switch (flip)
|
||||
{
|
||||
case 1:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Heads! You win ${betAmount}!", ImageUrl = headsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, betAmount);
|
||||
break;
|
||||
case 2:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Tails! You lose ${betAmount}!", ImageUrl = tailsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, -betAmount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (decision.ToLower() == "tails")
|
||||
{
|
||||
switch (flip)
|
||||
{
|
||||
case 1:
|
||||
await ctx.CreateResponseAsync("Heads! You lose!");
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Heads! You lose ${betAmount}!", ImageUrl = headsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, -betAmount);
|
||||
break;
|
||||
case 2:
|
||||
await ctx.CreateResponseAsync(embed: new DiscordEmbedBuilder { Title = $"Tails! You win ${betAmount}!", ImageUrl = tailsURL }.Build());
|
||||
AddSubtractUserMoney(uid, gid, betAmount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[SlashCommand("Wheel", "Roll the wheel of Macho Fortune!")]
|
||||
public async Task WheelCommand(InteractionContext ctx, [Option("Amount", "Real: (typing 'All' currently doesn't work, do it manually.)")] long betAmount)
|
||||
{
|
||||
if (betAmount < 0)
|
||||
{
|
||||
await ctx.CreateResponseAsync("Negative numbers are not allowed!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entry = EconDatabaseChecker(ctx.User.Id, ctx.Guild.Id);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
double playerMoney = Convert.ToDouble(entryParsed[1]);
|
||||
double moneyEarned = 0;
|
||||
if (betAmount > playerMoney)
|
||||
{
|
||||
await ctx.CreateResponseAsync("You do not have enough money!");
|
||||
}
|
||||
else
|
||||
{
|
||||
var roll = rnd.Next(1, 8);
|
||||
double multiplier = 1;
|
||||
bool shit = false;
|
||||
switch (roll)
|
||||
{
|
||||
case 1:
|
||||
multiplier = 2.4;
|
||||
shit = true;
|
||||
break;
|
||||
case 2:
|
||||
multiplier = 1.8;
|
||||
shit = true;
|
||||
break;
|
||||
case 3:
|
||||
multiplier = 1.4;
|
||||
shit = true;
|
||||
break;
|
||||
case 4:
|
||||
multiplier = 0;
|
||||
break;
|
||||
case 5:
|
||||
multiplier = 1.4;
|
||||
break;
|
||||
case 6:
|
||||
multiplier = 1.8;
|
||||
break;
|
||||
case 7:
|
||||
multiplier = 2.4;
|
||||
break;
|
||||
}
|
||||
if (shit == true)
|
||||
{
|
||||
moneyEarned = betAmount * multiplier;
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, -Convert.ToInt64(moneyEarned));
|
||||
await ctx.CreateResponseAsync($"Money multiplied by -{multiplier}x, lost ${moneyEarned}! Sad!");
|
||||
}
|
||||
else
|
||||
{
|
||||
moneyEarned = betAmount * multiplier;
|
||||
AddSubtractUserMoney(ctx.User.Id, ctx.Guild.Id, Convert.ToInt64(moneyEarned));
|
||||
await ctx.CreateResponseAsync($"Money multiplied by {multiplier}x, ${moneyEarned}!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Economy Tools (I really need to stuff this into the library)
|
||||
public void AddSubtractUserMoney(ulong userID, ulong guildID, long amount)
|
||||
{
|
||||
var entry = EconDatabaseChecker(userID, guildID);
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var currentAmount = entryParsed[1];
|
||||
long finalAmount = Convert.ToInt64(currentAmount) + amount;
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{userID}|{finalAmount.ToString()}|{entryParsed[2]}|";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
}
|
||||
//Thank you microsoft for requiring a rewrite of your entire method just to not have it add an extra new line at the end of a file. :tf:
|
||||
public static void WriteAllLinesBetter(string path, params string[] lines)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException("path");
|
||||
if (lines == null)
|
||||
throw new ArgumentNullException("lines");
|
||||
|
||||
using (var stream = File.OpenWrite(path))
|
||||
using (StreamWriter writer = new StreamWriter(stream))
|
||||
{
|
||||
if (lines.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < lines.Length - 1; i++)
|
||||
{
|
||||
writer.WriteLine(lines[i]);
|
||||
}
|
||||
writer.Write(lines[lines.Length - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void MultiplyUserMoney(ulong userID, ulong guildID, float multiplier)
|
||||
{
|
||||
var entry = EconDatabaseChecker(userID, guildID);
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
var entryNumber = Int32.Parse(entry[1]);
|
||||
var entryParsed = entry[0].Split('|');
|
||||
var currentAmount = entryParsed[1];
|
||||
float finalAmount = float.Parse(currentAmount) * multiplier;
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
lines[entryNumber - 1] = $"{userID}|{finalAmount.ToString()}";
|
||||
WriteAllLinesBetter(path, lines);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds the economy database entry for the specified UserID, or creates a new entry for the server/user if an entry for one is missing.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The contents, and line number of the entry if found, in a string array.
|
||||
/// </returns>
|
||||
public static string[] EconDatabaseChecker(ulong userID, ulong guildID)
|
||||
{
|
||||
int lineCount = 0;
|
||||
string[] entry = { "noentry", "bingus" };
|
||||
var path = $@"{rootPath}\EconomyDatabase\{guildID}.csv";
|
||||
if (File.Exists(path) == false)
|
||||
{
|
||||
string entryToCreate = $"{userID}|100|none";
|
||||
File.AppendAllText(path, entryToCreate);
|
||||
}
|
||||
|
||||
foreach (var line in File.ReadAllLines(path))
|
||||
{
|
||||
var entryparsed = line.Split('|');
|
||||
lineCount++;
|
||||
if (entryparsed[0] == userID.ToString())
|
||||
{
|
||||
entry[0] = line; //Contents of entry line
|
||||
entry[1] = $"{lineCount}"; //Number of line in .csv file
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry[0] == "noentry") //If after the file has been searched, no entry has been found, create a new one and stuff it in the 'entry' variable
|
||||
{
|
||||
string entryToCreate = $"{userID}|100|none";
|
||||
File.AppendAllText(path, Environment.NewLine + entryToCreate);
|
||||
return entry;
|
||||
}
|
||||
return entry;
|
||||
}*/
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class PlayerData
|
||||
|
|
|
@ -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,24 +42,24 @@ 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 != "")
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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