Adding Raffle Buy functionality. Began Config commands for Variable Config Alterations
This commit is contained in:
parent
7046b97bee
commit
eaf5ed9889
@ -19,9 +19,6 @@
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="ChaosBotSQL.db">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
6
ChaosBot/ChaosBot.csproj.user
Normal file
6
ChaosBot/ChaosBot.csproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ActiveDebugProfile>IIS Express</ActiveDebugProfile>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
80
ChaosBot/Discord/Modules/ConfigCommands.cs
Normal file
80
ChaosBot/Discord/Modules/ConfigCommands.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using NLog;
|
||||
using System.Text;
|
||||
using ChaosBot.Database.Repository;
|
||||
|
||||
namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
public class ConfigCommands : ModuleBase
|
||||
{
|
||||
private static readonly Logger _logger = Program._logger;
|
||||
private static readonly string _prefix = ConfigurationRepository.GetValue<string>("Discord:Prefix");
|
||||
|
||||
[Command("config")]
|
||||
[RequireBotPermission(GuildPermission.ManageGuild)]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
public async Task setConfig(string configFlag = null, string value = null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
try
|
||||
{
|
||||
if (configFlag == null || value == null)
|
||||
{
|
||||
await ReplyAsync($"Syntax Wrong. Please see {_prefix}config help");
|
||||
return;
|
||||
}
|
||||
ConfigurationRepository.SetValue<String>(configFlag, Context.Guild.Id, value);
|
||||
embed.WithColor(new Color(255, 255, 0));
|
||||
embed.Title = $"Configuration Management";
|
||||
sb.AppendLine($"{Context.User.Mention} has changed the Configuration.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"{configFlag} == {value}");
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
*/
|
||||
embed.Description = sb.ToString();
|
||||
|
||||
/*
|
||||
* Reply with the Embed created above
|
||||
*/
|
||||
await ReplyAsync(null, false, embed.Build());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"ConfigCommands.setCfg: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
}
|
||||
|
||||
[Command("config help")]
|
||||
[RequireBotPermission(GuildPermission.ManageGuild)]
|
||||
[RequireUserPermission(GuildPermission.ManageGuild)]
|
||||
public async Task helpConfig(string configFlag = null, string value = null)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255, 0));
|
||||
embed.Title = $"Configuration Management Help";
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"{_prefix}config <configFlag> <value>");
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
*/
|
||||
embed.Description = sb.ToString();
|
||||
|
||||
/*
|
||||
* Reply with the Embed created above
|
||||
*/
|
||||
await ReplyAsync(null, false, embed.Build());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ using System.Threading.Tasks;
|
||||
using ChaosBot.Database.Entity;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using ChaosBot.Database.Repository;
|
||||
|
||||
@ -17,12 +16,30 @@ namespace ChaosBot.Discord.Modules
|
||||
private static Logger _logger = Program._logger;
|
||||
|
||||
[Command("raffle")]
|
||||
[Alias("raffle info")]
|
||||
public async Task RaffleStatus()
|
||||
{
|
||||
long userAmount = RaffleRepository.Count(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id));
|
||||
long totalAmount = RaffleRepository.Count(Convert.ToInt64(Context.Guild.Id));
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine($"{Context.User.Mention}, you have {userAmount} rafflepoints.");
|
||||
sb.AppendLine($"There is a total of {totalAmount} rafflepoints.");
|
||||
|
||||
eb.Title = "Raffle System";
|
||||
eb.Description = sb.ToString();
|
||||
|
||||
await ReplyAsync(null, false, eb.Build());
|
||||
}
|
||||
|
||||
[Command("raffle help")]
|
||||
[Alias("raffle ?")]
|
||||
public async Task RaffleInfo()
|
||||
{
|
||||
var eb = new EmbedBuilder();
|
||||
var sb = new StringBuilder();
|
||||
string prefix = ConfigurationRepository.GetValue<string>("Discord.Prefix");
|
||||
string prefix = ConfigurationRepository.GetValue<string>("Discord.Prefix", Context.Guild.Id);
|
||||
|
||||
sb.AppendLine($"{Context.User.Mention} has requested raffle information.");
|
||||
sb.AppendLine();
|
||||
@ -40,25 +57,6 @@ namespace ChaosBot.Discord.Modules
|
||||
|
||||
await ReplyAsync(null, false, eb.Build());
|
||||
}
|
||||
|
||||
[Command("raffle status")]
|
||||
public async Task RaffleStatus()
|
||||
{
|
||||
long userAmount = RaffleRepository.Count(Convert.ToInt64(Context.Guild.Id), Convert.ToInt64(Context.User.Id));
|
||||
long totalAmount = RaffleRepository.Count(Convert.ToInt64(Context.Guild.Id));
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
var sb = new StringBuilder();
|
||||
string prefix = ConfigurationRepository.GetValue<string>("Discord.Prefix");
|
||||
|
||||
sb.AppendLine($"{Context.User.Mention}, you have {userAmount} rafflepoints.");
|
||||
sb.AppendLine($"There is a total of {totalAmount} rafflepoints.");
|
||||
|
||||
eb.Title = "Raffle System";
|
||||
eb.Description = sb.ToString();
|
||||
|
||||
await ReplyAsync(null, false, eb.Build());
|
||||
}
|
||||
|
||||
[Command("raffle add")]
|
||||
public async Task RaffleAdd(string userMention, int amount)
|
||||
@ -118,5 +116,40 @@ namespace ChaosBot.Discord.Modules
|
||||
|
||||
await ReplyAsync(null, false, eb.Build());
|
||||
}
|
||||
|
||||
[Command("raffle buy")]
|
||||
public async Task RaffleCommandBuy(int amount = 1)
|
||||
{
|
||||
int cost = ConfigurationRepository.GetValue<int>($"Raffle:Cost", Context.Guild.Id) * amount;
|
||||
long curPoints = PointsRepository.Total(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id));
|
||||
int curRaffle = RaffleRepository.Count(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id));
|
||||
int maxRaffle = ConfigurationRepository.GetValue<int>($"Raffle:Max", Context.Guild.Id);
|
||||
int newRaffle = curRaffle + amount;
|
||||
|
||||
Console.WriteLine($"curPoints: {curPoints}, curRaffle: {curRaffle}, maxRaffle: {maxRaffle}, newRaffle: {newRaffle}");
|
||||
|
||||
if (amount <= maxRaffle && newRaffle <= maxRaffle)
|
||||
{
|
||||
if (curPoints > cost)
|
||||
{
|
||||
long newPoints = PointsRepository.Remove(Convert.ToInt64(Context.User.Id), cost, Convert.ToInt64(Context.Guild.Id));
|
||||
|
||||
List<Raffle> raffleList = new List<Raffle>();
|
||||
for (int i = 0; i < amount; i++)
|
||||
raffleList.Add(new Raffle(Convert.ToInt64(Context.User.Id), Convert.ToInt64(Context.Guild.Id)));
|
||||
RaffleRepository.MassInsert(raffleList);
|
||||
|
||||
await ReplyAsync($"You have spent {cost} points and bought {amount} tickets. You have {newPoints} left.", false);
|
||||
}
|
||||
else
|
||||
await ReplyAsync($"That will cost {cost} points, you only have {curPoints}.", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyAsync(
|
||||
$"You cannot buy more then {ConfigurationRepository.GetValue<int>($"Raffle:Max", Context.Guild.Id).ToString()} tickets.", false);
|
||||
_logger.Warn($"{Context.User.Username} has bought {amount} tickets!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
ChaosBot/Properties/launchSettings.json
Normal file
27
ChaosBot/Properties/launchSettings.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:52667/",
|
||||
"sslPort": 44315
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"ChaosBot": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user