Economy updates & gemboard

This commit is contained in:
Brazman 2023-02-16 12:20:08 -06:00
parent d698716cf4
commit 24fff63160
6 changed files with 262 additions and 27 deletions

View file

@ -11,7 +11,7 @@ namespace SuperMachoBot.Commands
#region Economy Commands
[SlashCommand("Shutdown", "Kills the SuperMachoBot with a password.")]
/*[SlashCommand("Shutdown", "Kills the SuperMachoBot with a password.")]
public async Task EconTestCommand(InteractionContext ctx, [Option("Password", "Enter it.")] string pass)
{
string shutdownPass = "TRUTH HAD GONE, TRUTH HAD GONE, AND TRUTH HAD GONE. AH, NOW TRUTH IS ASLEEP IN THE DARKNESS OF THE SINISTER HAND.";
@ -24,6 +24,14 @@ namespace SuperMachoBot.Commands
{
await ctx.CreateResponseAsync("Wrong password! Try again! :P");
}
}*/
public enum BetflipChoice
{
[ChoiceName("heads")]
heads,
[ChoiceName("tails")]
tails,
}
public void CreateEconomyEntry(ulong userid, UserData data, ulong guildid)
@ -112,20 +120,24 @@ namespace SuperMachoBot.Commands
[SlashCommand("Balance", "Check users balance")]
public async Task BalanceCommand(InteractionContext ctx, [Option("User", "User to check balance of")] DiscordUser du)
public async Task BalanceCommand(InteractionContext ctx, [Option("User", "User to check balance of")] DiscordUser du = null)
{
// Access the data using the userid key
if(du == null)
{
du = ctx.User;
}
ulong userid = du.Id;
UserData userData = GetEconomyEntry(userid, ctx.Guild.Id);
if (userData != null)
{
var money = userData.money;
var lastDaily = userData.lastDaily;
await ctx.CreateResponseAsync($"{du.Username}#{du.Discriminator}:{money}$ Last claimed daily:(Unix){lastDaily}");
await ctx.CreateResponseAsync($"{du.Username}: {money}$");
}
else //TODO: Fix bug which causes the response after new entry creation to not be sent, requiring the user to query again to see their balance.
{
await ctx.CreateResponseAsync($"No entry found! Creating new one....");
await ctx.CreateResponseAsync($"No entry found! Creating new one. Please run this command again.");
Thread.Sleep(1000);
var newData = GetEconomyEntry(userid, ctx.Guild.Id);
var money = newData.money;
@ -168,20 +180,115 @@ 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)
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)
{
entry = GetEconomyEntry(ctx.User.Id, ctx.Guild.Id); //Get it again. Chud.
}
if(amount < 0)
{
await ctx.CreateResponseAsync($"Invalid amount!");
}
if(amount > entry.money)
{
await ctx.CreateResponseAsync($"Invalid amount!");
}
int result = rnd.Next(0, 2);
int result = rnd.Next(0, 2); //Could massively reduce the amount of lines below, but I want custom messages dependent on all the outcomes, so COPE.
if (result == 0) //Heads
{
if(choice == BetflipChoice.heads)
{
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money + amount, lastDaily = entry.lastDaily}, ctx.Guild.Id);
await ctx.CreateResponseAsync($"Heads! You win ${amount}!");
}
else
{
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money - amount, lastDaily = entry.lastDaily }, ctx.Guild.Id);
await ctx.CreateResponseAsync($"Drat, heads! You lose ${amount}!");
}
}
else if (result == 1) //Tails
{
if (choice == BetflipChoice.tails)
{
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money + amount, lastDaily = entry.lastDaily }, ctx.Guild.Id);
await ctx.CreateResponseAsync($"Tails! You win ${amount}!");
}
else
{
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money - amount, lastDaily = entry.lastDaily }, ctx.Guild.Id);
await ctx.CreateResponseAsync($"Drat, tails! You lose ${amount}!");
}
}
await ctx.CreateResponseAsync("Gem.");
}
[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)
{
entry = GetEconomyEntry(ctx.User.Id, ctx.Guild.Id); //Get it again. Chud.
}
var roll = rnd.Next(0, 7);
double multiplier = 1;
if (amount <= 0)
{
await ctx.CreateResponseAsync($"Invalid amount! Try again!");
} else if(entry.money < amount)
{
await ctx.CreateResponseAsync($"YOU CANNOT AFFORD! TRY AGAIN!");
}
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;
}
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)
{
await ctx.CreateResponseAsync($"{ctx.User.Username} lost {money}$!");
}
await ctx.CreateResponseAsync($"{ctx.User.Username} gained {money}!");
}
[SlashCommand("Daily", "Claim your daily 100$!")]
public async Task DailyCommand(InteractionContext ctx, [Option("Amount", "Amount to bet")] long amount)
{
var entry = GetEconomyEntry(ctx.User.Id, ctx.Guild.Id);
ulong time = (ulong)(DateTimeOffset.UtcNow.ToUnixTimeSeconds());
if (time - entry.lastDaily > 86400)
{
EditEconomyEntry(ctx.User.Id, new UserData { money = entry.money + 100, lastDaily = time }, ctx.Guild.Id);
await ctx.CreateResponseAsync($"Daily claimed!");
}
await ctx.CreateResponseAsync($"Can't claim daily yet! Come back tomorrow, coalposter!");
}
/*[SlashCommand("Balance", "Checks your balance")]

View file

@ -1,8 +1,8 @@
using DSharpPlus;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using Newtonsoft.Json;
using System.Text;
using static System.Net.WebRequestMethods;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace SuperMachoBot.Commands
{
@ -88,7 +88,18 @@ namespace SuperMachoBot.Commands
await ctx.CreateResponseAsync(embed);
}
[SlashCommand("Testing", "Tests.")]
[SlashCommand("EmbeddingTest", "Sends a placeholder embed for gemboard.")]
public async Task UserInfoCommand(InteractionContext ctx)
{
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();
await ctx.CreateResponseAsync(bruhgimus);
}
/*[SlashCommand("Testing", "Tests.")]
public async Task TestingCommand(InteractionContext ctx)
{
try
@ -184,7 +195,7 @@ namespace SuperMachoBot.Commands
{
await ctx.CreateResponseAsync(ex.Message);
}
}
}*/
#endregion
#region Economy Commands

View file

@ -1,6 +1,6 @@
{
"304033317513199617": {
"money": 400,
"money": 2480,
"lastDaily": 0
},
"305520963238494219": {
@ -12,7 +12,19 @@
"lastDaily": 0
},
"315595591029751808": {
"money": 150,
"lastDaily": 0
},
"295717168694296577": {
"money": 0,
"lastDaily": 0
},
"747584541840900237": {
"money": 2148482648,
"lastDaily": 0
},
"692815026909741057": {
"money": 100,
"lastDaily": 0
}
}

View file

@ -0,0 +1,27 @@
1075610686757019759
1075614835737378816
1075614444685643776
1075616767080149104
1075616976556273674
1075617655416963144
1075619705957666856
1075619715621322792
1075620041313239090
1075619830859841546
1075763823740461056
1075762857041461338
1075758398253051945
1075738002761977876
1075684440728145961
1075683894386499594
1075682766479433748
1075771345834622986
1075772918866378853
1075773508291923989
1075774698983522304
1075774690112569395
1075773675690795099
1075715014096338968
1075775020699222110
1075779077463613560
1075781283281633363

View file

@ -4,6 +4,8 @@ using DSharpPlus.SlashCommands;
using SuperMachoBot.Commands;
using Newtonsoft.Json;
using DSharpPlus.Entities;
using Microsoft.Extensions.Logging;
using System.Drawing;
namespace SuperMachoBot
{
@ -13,6 +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 = "";
static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
@ -28,17 +31,81 @@ namespace SuperMachoBot
discord = new DiscordClient(new DiscordConfiguration()
{
Token = configItems[0].Token,
TokenType = TokenType.Bot
TokenType = TokenType.Bot,
Intents = DiscordIntents.Guilds | DiscordIntents.GuildMembers | DiscordIntents.GuildMessages | DiscordIntents.GuildMessageReactions | DiscordIntents.DirectMessages | DiscordIntents.MessageContents
});
var slash = discord.UseSlashCommands();
discord.MessageCreated += async (s, e) =>
{
if (e.Message.Content.Contains("money") && e.Message.Content.Contains("tenor") == false && moneyCooldown == false)
};
pinnedPath = @$"{configItems[0].EconomyDatabasePath}Pinned.txt";
discord.MessageReactionAdded += async (s, e) =>
{
if (e.Emoji.Id == 1075778692959183049) //Gem
{
await e.Message.RespondAsync("https://tenor.com/view/money-breaking-bad-sleep-on-money-lay-on-money-money-pile-gif-5382667");
cooldown();
var bruh = await e.Channel.GetMessageAsync(e.Message.Id);
if(bruh.Reactions[0].Count > 4 && !CheckPinID(bruh.Id))
{
string thumbnailURL = "";
string desc = "";
if(bruh.Attachments.Count > 0)
{
thumbnailURL = bruh.Attachments[0].Url;
}
if(bruh.Content != "")
{
desc = $@"""{bruh.Content}""";
}
var bruhgimus = new DiscordEmbedBuilder
{
Title = $"GEM ALERT!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1075774698744455168/Gemson.png" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = bruh.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{bruh.Author.Username}#{bruh.Author.Discriminator}" },
Color = DiscordColor.PhthaloBlue
}.AddField("Gem:", $"[link]({bruh.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(1075588362230042694).Result, bruhgimus);
File.AppendAllText(pinnedPath, bruh.Id.ToString() + "\n");
}
}
if (e.Emoji.Id == 1075778708629110885) //Coal
{
var bruh = await e.Channel.GetMessageAsync(e.Message.Id);
if (bruh.Reactions[0].Count > 4 && !CheckPinID(bruh.Id))
{
string thumbnailURL = "";
string desc = "";
if (bruh.Attachments.Count > 0)
{
thumbnailURL = bruh.Attachments[0].Url;
}
if (bruh.Content != "")
{
desc = $@"""{bruh.Content}""";
}
var bruhgimus = new DiscordEmbedBuilder
{
Title = $"COAL!!!! STINKY PISSCOAL ALERT!!!!",
Description = desc + "\n" + "",
ImageUrl = thumbnailURL,
Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = "https://cdn.discordapp.com/attachments/977270567881298024/1075774690062249992/Coalson.png" },
Footer = new DiscordEmbedBuilder.EmbedFooter { IconUrl = bruh.Author.GetAvatarUrl(DSharpPlus.ImageFormat.Png, 256), Text = $"{bruh.Author.Username}#{bruh.Author.Discriminator}" },
Color = DiscordColor.Black
}.AddField("Coal:", $"[link]({bruh.JumpLink})").Build();
await discord.SendMessageAsync(discord.GetChannelAsync(1075588362230042694).Result, bruhgimus);
File.AppendAllText(pinnedPath, bruh.Id.ToString() + "\n");
}
}
};
@ -47,11 +114,10 @@ namespace SuperMachoBot
StringPrefixes = new[] { "tf" }
});
commands.RegisterCommands<GeneralCommands>();
slash.RegisterCommands<SlashCommands>();
slash.RegisterCommands<EconomyCommands>();
EconomyCommands.jsonPath = @"C:\repos\bots\SuperMachoBot\Super-Macho-Bot\SuperMachoBot\EconomyDatabase\";
EconomyCommands.jsonPath = configItems[0].EconomyDatabasePath;
await discord.ConnectAsync();
await Task.Delay(-1);
@ -62,6 +128,18 @@ namespace SuperMachoBot
Thread.Sleep(10000);
moneyCooldown = false;
}
static bool CheckPinID(ulong messageid)
{
foreach (var line in File.ReadAllLines(pinnedPath))
{
if(line == messageid.ToString())
{
return true;
}
}
return false;
}
}
public class Config
{

View file

@ -2,19 +2,19 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartupObject></StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.3.0-nightly-01171" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.3.0-nightly-01171" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.3.0-nightly-01171" />
<PackageReference Include="DSharpPlus.Lavalink" Version="4.3.0-nightly-01171" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.3.0-nightly-01171" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-00009" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-00009" />
<PackageReference Include="DSharpPlus.Interactivity" Version="5.0.0-nightly-00009" />
<PackageReference Include="DSharpPlus.Lavalink" Version="5.0.0-nightly-00009" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-00009" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3-beta1" />
<Protobuf Include="**/*.proto" />
</ItemGroup>