diff --git a/ChaosBot/ChaosBot.csproj b/ChaosBot/ChaosBot.csproj
index 3794272..7e33e70 100644
--- a/ChaosBot/ChaosBot.csproj
+++ b/ChaosBot/ChaosBot.csproj
@@ -19,9 +19,6 @@
PreserveNewest
-
- PreserveNewest
-
diff --git a/ChaosBot/ChaosBot.csproj.user b/ChaosBot/ChaosBot.csproj.user
new file mode 100644
index 0000000..cff74a9
--- /dev/null
+++ b/ChaosBot/ChaosBot.csproj.user
@@ -0,0 +1,6 @@
+
+
+
+ IIS Express
+
+
\ No newline at end of file
diff --git a/ChaosBot/Discord/Modules/ConfigCommands.cs b/ChaosBot/Discord/Modules/ConfigCommands.cs
new file mode 100644
index 0000000..64bafce
--- /dev/null
+++ b/ChaosBot/Discord/Modules/ConfigCommands.cs
@@ -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("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(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 ");
+
+ /*
+ * Add the string to the Embed
+ */
+ embed.Description = sb.ToString();
+
+ /*
+ * Reply with the Embed created above
+ */
+ await ReplyAsync(null, false, embed.Build());
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/ChaosBot/Discord/Modules/RaffleSystem.cs b/ChaosBot/Discord/Modules/RaffleSystem.cs
index 5e01484..c954d1d 100644
--- a/ChaosBot/Discord/Modules/RaffleSystem.cs
+++ b/ChaosBot/Discord/Modules/RaffleSystem.cs
@@ -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("Discord.Prefix");
+ string prefix = ConfigurationRepository.GetValue("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("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($"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($"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 raffleList = new List();
+ 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($"Raffle:Max", Context.Guild.Id).ToString()} tickets.", false);
+ _logger.Warn($"{Context.User.Username} has bought {amount} tickets!");
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ChaosBot/Properties/launchSettings.json b/ChaosBot/Properties/launchSettings.json
new file mode 100644
index 0000000..157927c
--- /dev/null
+++ b/ChaosBot/Properties/launchSettings.json
@@ -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"
+ }
+ }
+}
\ No newline at end of file