Fix code warnings

This commit is contained in:
Daniel_I_Am 2020-08-30 13:10:43 +02:00
parent e1d2fd26e4
commit bc20751037
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
10 changed files with 113 additions and 121 deletions

View File

@ -28,8 +28,8 @@ namespace ChaosBot.Discord.Modules.Admin
{ {
if(ex.Message.Contains("Messages must be younger than two weeks old.")) if(ex.Message.Contains("Messages must be younger than two weeks old."))
await ReplyAsync($"{Context.User.Mention}, You cannot delete messages older then 2 weeks old."); await ReplyAsync($"{Context.User.Mention}, You cannot delete messages older then 2 weeks old.");
LoggingFacade.Error($"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>."); LoggingFacade.Error($"{MethodBase.GetCurrentMethod()?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
LoggingFacade.Debug($"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}"); LoggingFacade.Debug($"{MethodBase.GetCurrentMethod()?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}");
} }
} }
} }

View File

@ -48,14 +48,14 @@ namespace ChaosBot.Discord.Modules.Admin
embed.Title = $"Configuration Management Help"; embed.Title = $"Configuration Management Help";
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To set a configuration value:"); sb.AppendLine("To set a configuration value:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config set <configFlag> <value>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config set <configFlag> <value>");
sb.AppendLine("To get a configuration value:"); sb.AppendLine("To get a configuration value:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config get <configFlag>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config get <configFlag>");
sb.AppendLine("To reset a configuration value to default:"); sb.AppendLine("To reset a configuration value to default:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config reset <configFlag>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config reset <configFlag>");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To view this help:"); sb.AppendLine("To view this help:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config help"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config help");
/* /*
* Add the string to the Embed * Add the string to the Embed
@ -124,7 +124,7 @@ namespace ChaosBot.Discord.Modules.Admin
embed.Title = $"Configuration Retrieval"; embed.Title = $"Configuration Retrieval";
sb.AppendLine(); sb.AppendLine();
sb.AppendLine($" Flag: {key}"); sb.AppendLine($" Flag: {key}");
sb.AppendLine($"Value: {ConfigurationRepository.GetValue<string>(key, Context.Guild.Id, "NotSet")}"); sb.AppendLine($"Value: {ConfigurationRepository.GetValue(key, Context.Guild.Id, "NotSet")}");
/* /*
* Add the string to the Embed * Add the string to the Embed

View File

@ -19,7 +19,7 @@ namespace ChaosBot.Discord.Modules.Admin
[Command("rankCheck")] [Command("rankCheck")]
[Alias("rc")] [Alias("rc")]
[CheckCommandPerm("Admin")] [CheckCommandPerm("Admin")]
public async Task rankCheck() public async Task Check()
{ {
try try
{ {
@ -38,15 +38,15 @@ namespace ChaosBot.Discord.Modules.Admin
sb.AppendLine($"**Recruits Pending Promotion to Initiate**"); sb.AppendLine($"**Recruits Pending Promotion to Initiate**");
if(ranks.FindAll(x => x.IngameRole == ERole.Recruit).Any()) if(ranks.FindAll(x => x.IngameRole == ERole.Recruit).Any())
{ {
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Recruit)) foreach (var lsId in ranks.FindAll(x => x.IngameRole == ERole.Recruit))
{ {
if (DateTimeOffset.Now >= lsID.RecruitDate) if (DateTimeOffset.Now >= lsId.RecruitDate)
{ {
if(lsID.DiscordId != null) if(lsId.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : ""))); sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, (lsId.DiscordId != null ? $", linked to <@{lsId.DiscordId}>)" : "")));
else else
{ {
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId); ulong lodeId = Convert.ToUInt64(lsId.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext()) using (ChaosbotContext dbContext = new ChaosbotContext())
{ {
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter; IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -56,11 +56,11 @@ namespace ChaosBot.Discord.Modules.Admin
if (lsChar.Any()) if (lsChar.Any())
{ {
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>")); sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
} }
else else
{ {
sb.AppendLine(string.Format("{0}", lsID.DisplayName)); sb.AppendLine(string.Format("{0}", lsId.DisplayName));
} }
} }
} }
@ -74,15 +74,15 @@ namespace ChaosBot.Discord.Modules.Admin
sb.AppendLine($"**Initiates Pending Promotion to Member**"); sb.AppendLine($"**Initiates Pending Promotion to Member**");
if (ranks.FindAll(x => x.IngameRole == ERole.Initiate).Any()) if (ranks.FindAll(x => x.IngameRole == ERole.Initiate).Any())
{ {
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Initiate)) foreach (var lsId in ranks.FindAll(x => x.IngameRole == ERole.Initiate))
{ {
if (DateTimeOffset.Now >= lsID.MemberDate) if (DateTimeOffset.Now >= lsId.MemberDate)
{ {
if(lsID.DiscordId != null) if(lsId.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : ""))); sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, (lsId.DiscordId != null ? $", linked to <@{lsId.DiscordId}>)" : "")));
else else
{ {
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId); ulong lodeId = Convert.ToUInt64(lsId.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext()) using (ChaosbotContext dbContext = new ChaosbotContext())
{ {
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter; IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -92,11 +92,11 @@ namespace ChaosBot.Discord.Modules.Admin
if (lsChar.Any()) if (lsChar.Any())
{ {
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>")); sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
} }
else else
{ {
sb.AppendLine(string.Format("{0}", lsID.DisplayName)); sb.AppendLine(string.Format("{0}", lsId.DisplayName));
} }
} }
} }

View File

@ -28,14 +28,14 @@ namespace ChaosBot.Discord.Modules.Admin
embed.Title = $"Role Management Help"; embed.Title = $"Role Management Help";
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To add a role-reaction to a message:"); sb.AppendLine("To add a role-reaction to a message:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}role add <emote> <role>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}role add <emote> <role>");
sb.AppendLine("To add many role-reactions to a message add more sets of emote and role:"); sb.AppendLine("To add many role-reactions to a message add more sets of emote and role:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}role add <emote> <role> <emote> <role> <emote> <role>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}role add <emote> <role> <emote> <role> <emote> <role>");
sb.AppendLine("To remove a role-reaction from a message:"); sb.AppendLine("To remove a role-reaction from a message:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}role remove <emote>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}role remove <emote>");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To view this help:"); sb.AppendLine("To view this help:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}role help"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}role help");
/* /*
* Add the string to the Embed * Add the string to the Embed

View File

@ -37,11 +37,11 @@ namespace ChaosBot.Discord.Modules.User
{ {
// ulong nextLevelXP = 1 * usrXp.First().Level * (2 * usrXp.First().Level * usrXp.First().Level + 27 * usrXp.First().Level + 91); // ulong nextLevelXP = 1 * usrXp.First().Level * (2 * usrXp.First().Level * usrXp.First().Level + 27 * usrXp.First().Level + 91);
ulong curLevel = usrXp.First().Level; ulong curLevel = usrXp.First().Level;
ulong nextLevelXP = 5 * curLevel * curLevel * curLevel + 95 * curLevel; ulong nextLevelXp = 5 * curLevel * curLevel * curLevel + 95 * curLevel;
sb.AppendLine($"Name: {Context.User.Mention}"); sb.AppendLine($"Name: {Context.User.Mention}");
sb.AppendLine($"\tLevel: {usrXp.First().Level}"); sb.AppendLine($"\tLevel: {usrXp.First().Level}");
sb.AppendLine($"\tExperience: {usrXp.First().Amount}"); sb.AppendLine($"\tExperience: {usrXp.First().Amount}");
sb.AppendLine($"\tNeeded to Level: {nextLevelXP}"); sb.AppendLine($"\tNeeded to Level: {nextLevelXp}");
} }
else else
{ {

View File

@ -34,7 +34,7 @@ namespace ChaosBot.Discord.Modules.User
await LodestoneHelp(); await LodestoneHelp();
} }
} }
else if (((cmd.ToLower() == "link") || (cmd.ToLower() == "l") || (cmd.ToLower() == "attach") || (cmd.ToLower() == "claim") || (cmd.ToLower() == "take")) && (CheckPermissions.CheckPerms(Context, "lodestone.link", "User"))) else if (((cmd.ToLower() == "link") || (cmd.ToLower() == "l") || (cmd.ToLower() == "attach") || (cmd.ToLower() == "claim") || (cmd.ToLower() == "take")) && (CheckPermissions.CheckPerms(Context, "lodestone.link")))
{ {
if(args.Length >= 1) if(args.Length >= 1)
{ {
@ -75,26 +75,26 @@ namespace ChaosBot.Discord.Modules.User
var embed = new EmbedBuilder(); var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0)); embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Lodestone API Help"; embed.Title = "Lodestone API Help";
sb.AppendLine(); sb.AppendLine();
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To get FreeCompany Info:"); sb.AppendLine("To get FreeCompany Info:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany 9231394073691143535"); sb.AppendLine($"By Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany Siren Helix"); sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany Siren Helix");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To get Character Info:"); sb.AppendLine("To get Character Info:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone character 9231394073691143535"); sb.AppendLine($"By Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone character 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone character Siren Luna Kaisar"); sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone character Siren Luna Kaisar");
if (CheckPermissions.CheckPerms(Context, "lodestone.link", "User")) if (CheckPermissions.CheckPerms(Context, "lodestone.link"))
{ {
sb.AppendLine("To Link your Character:"); sb.AppendLine("To Link your Character:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone link 9231394073691143535"); sb.AppendLine($"By Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone link 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone link Siren Luna Kaisar"); sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone link Siren Luna Kaisar");
} }
sb.AppendLine(); sb.AppendLine();
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("To view this help:"); sb.AppendLine("To view this help:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}config help"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}config help");
/* /*
* Add the string to the Embed * Add the string to the Embed
@ -155,13 +155,15 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine(); sb.AppendLine();
if (name.Length == 0) if (name.Length == 0)
{
character = LodestoneManager.GetCharacter(Convert.ToInt64(value)); character = LodestoneManager.GetCharacter(Convert.ToInt64(value));
}
else else
{ {
character = LodestoneManager.GetCharacter(value, string.Join(" ", name)); character = LodestoneManager.GetCharacter(value, string.Join(" ", name));
} }
Boolean linked = false; bool linked;
using (ChaosbotContext dbContext = new ChaosbotContext()) using (ChaosbotContext dbContext = new ChaosbotContext())
{ {
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter; IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -173,11 +175,11 @@ namespace ChaosBot.Discord.Modules.User
if(!linked) if(!linked)
{ {
string b64 = string b64 =
System.Convert.ToBase64String(Encoding.GetEncoding(28591) Convert.ToBase64String(Encoding.GetEncoding(28591)
.GetBytes(character.Character.ID.ToString())) + '|' + .GetBytes(character.Character.ID.ToString())) + '|' +
System.Convert.ToBase64String(Encoding.GetEncoding(28591) Convert.ToBase64String(Encoding.GetEncoding(28591)
.GetBytes(Context.Guild.Id.ToString())) + '|' + .GetBytes(Context.Guild.Id.ToString())) + '|' +
System.Convert.ToBase64String(Encoding.GetEncoding(28591).GetBytes(Context.User.Id.ToString())); Convert.ToBase64String(Encoding.GetEncoding(28591).GetBytes(Context.User.Id.ToString()));
if (character.Character.Bio.Contains(b64)) if (character.Character.Bio.Contains(b64))
{ {
@ -283,7 +285,8 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine($"Pledged to Grand Company {freeCompany.FreeCompany.GrandCompany}"); sb.AppendLine($"Pledged to Grand Company {freeCompany.FreeCompany.GrandCompany}");
sb.AppendLine(); sb.AppendLine();
var rankCounts = freeCompany.FreeCompanyMembers.GroupBy(m => m.Rank) var rankCounts = freeCompany.FreeCompanyMembers
.GroupBy(m => m.Rank)
.Select(g => new {Rank = g.Key, Count = g.Count()}) .Select(g => new {Rank = g.Key, Count = g.Count()})
.OrderBy(x => x.Rank); .OrderBy(x => x.Rank);
@ -316,7 +319,7 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine($"Bio: {character.Character.Bio}"); sb.AppendLine($"Bio: {character.Character.Bio}");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine( sb.AppendLine(
$"Current Job: {LodestoneManager.Classes.GetValueOrDefault(character.Character.ActiveClassJob.UnlockedState.Name)?.Item1.ToString()} {character.Character.ActiveClassJob.Level}"); $"Current Job: {LodestoneManager.Classes.GetValueOrDefault(character.Character.ActiveClassJob.UnlockedState.Name)?.Item1} {character.Character.ActiveClassJob.Level}");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("All Jobs:"); sb.AppendLine("All Jobs:");
@ -327,7 +330,9 @@ namespace ChaosBot.Discord.Modules.User
if (characterClassJob.Level == 0) continue; if (characterClassJob.Level == 0) continue;
Tuple<string, ClassType> classInfo = Tuple<string, ClassType> classInfo =
LodestoneManager.Classes.GetValueOrDefault(characterClassJob.UnlockedState.Name); LodestoneManager.Classes.GetValueOrDefault(characterClassJob.UnlockedState.Name);
classInfoList.Add(new Tuple<string, ClassType, int>(classInfo.Item1, classInfo.Item2, characterClassJob.Level)); if (classInfo != null)
classInfoList.Add(new Tuple<string, ClassType, int>(classInfo.Item1, classInfo.Item2,
characterClassJob.Level));
} }
foreach (var classTypeList in classInfoList.GroupBy(ci => ci.Item2) foreach (var classTypeList in classInfoList.GroupBy(ci => ci.Item2)

View File

@ -4,10 +4,10 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChaosBot.Discord.PreConditions; using ChaosBot.Discord.PreConditions;
using ChaosBot.Models; using ChaosBot.Models;
using Discord;
using Discord.Commands;
using ChaosBot.Repositories; using ChaosBot.Repositories;
using ChaosBot.Services; using ChaosBot.Services;
using Discord;
using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
@ -17,16 +17,16 @@ namespace ChaosBot.Discord.Modules.User
{ {
[Command("points")] [Command("points")]
[CheckCommandPerm("User")] [CheckCommandPerm("User")]
public async Task PointsCommand(string cmd = "total", SocketUser user = null, ulong Amount = 0) public async Task PointsCommand(string cmd = "total", SocketUser user = null, ulong amount = 0)
{ {
try try
{ {
if ((cmd.ToLower() == "add") || (cmd.ToLower() == "+") || (cmd.ToLower() == "give")) if ((cmd.ToLower() == "add") || (cmd.ToLower() == "+") || (cmd.ToLower() == "give"))
{ {
if(Amount != 0) if(amount != 0)
{ {
Boolean adminAccess = CheckPermissions.CheckPerms(Context, "points.add", "Admin"); Boolean adminAccess = CheckPermissions.CheckPerms(Context, "points.add", "Admin");
await AddPoints(user, Amount, adminAccess); await AddPoints(user, amount, adminAccess);
} }
else else
{ {
@ -35,9 +35,9 @@ namespace ChaosBot.Discord.Modules.User
} }
else if ((cmd.ToLower() == "remove") || (cmd.ToLower() == "rem") || (cmd.ToLower() == "take") || (cmd.ToLower() == "-")) else if ((cmd.ToLower() == "remove") || (cmd.ToLower() == "rem") || (cmd.ToLower() == "take") || (cmd.ToLower() == "-"))
{ {
if((Amount != 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin"))) if((amount != 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
{ {
await RemPoints(user, Amount); await RemPoints(user, amount);
} }
else else
{ {
@ -46,7 +46,7 @@ namespace ChaosBot.Discord.Modules.User
} }
else if ((cmd.ToLower() == "delete") || (cmd.ToLower() == "del")) else if ((cmd.ToLower() == "delete") || (cmd.ToLower() == "del"))
{ {
if((Amount == 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin"))) if((amount == 0) && (CheckPermissions.CheckPerms(Context, "points.remove", "Admin")))
{ {
await DelPoints(user); await DelPoints(user);
} }
@ -55,7 +55,7 @@ namespace ChaosBot.Discord.Modules.User
await PointsHelp(); await PointsHelp();
} }
} }
else if ((cmd.ToLower() == "=") || (cmd.ToLower() == "info") || (cmd.ToLower() == "total") || (cmd == null)) else if ((cmd.ToLower() == "=") || (cmd.ToLower() == "info") || (cmd.ToLower() == "total"))
{ {
await TotalPoints(); await TotalPoints();
} }
@ -78,17 +78,17 @@ namespace ChaosBot.Discord.Modules.User
var embed = new EmbedBuilder(); var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0)); embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Points system"; embed.Title = "Points system";
sb.AppendLine($"{Context.User.Mention} has requested points information."); sb.AppendLine($"{Context.User.Mention} has requested points information.");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine($"Usage:"); sb.AppendLine("Usage:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points info"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}points info");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points help"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}points help");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("Moderation commands:"); sb.AppendLine("Moderation commands:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}points add <discord mention> <amount>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}points add <discord mention> <amount>");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}point remove <discord mention> <amount>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}point remove <discord mention> <amount>");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}point delete <discord mention>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}point delete <discord mention>");
/* /*
* Add the string to the Embed * Add the string to the Embed
@ -126,10 +126,10 @@ namespace ChaosBot.Discord.Modules.User
LoggingFacade.Exception(ex); LoggingFacade.Exception(ex);
} }
await ReplyAsync($"{Context.User.Mention}, you have {cur} points.", false); await ReplyAsync($"{Context.User.Mention}, you have {cur} points.");
} }
public async Task RemPoints(SocketUser user = null, ulong Amount = 0) public async Task RemPoints(SocketUser user = null, ulong amount = 0)
{ {
ulong cur = 0; ulong cur = 0;
try try
@ -145,8 +145,8 @@ namespace ChaosBot.Discord.Modules.User
if(ctxusrPoint.Any()) if(ctxusrPoint.Any())
{ {
usrPoint = ctxusrPoint.First(); usrPoint = ctxusrPoint.First();
if (usrPoint.Amount >= Amount) if (usrPoint.Amount >= amount)
cur = usrPoint.Amount - Amount; cur = usrPoint.Amount - amount;
else else
cur = 0; cur = 0;
} }
@ -169,11 +169,10 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has taken {Amount} points from {user.Mention} leaving them with a total of {cur} points.", $"{Context.User.Mention} has taken {amount} points from {user.Mention} leaving them with a total of {cur} points.");
false);
} }
public async Task AddPoints(SocketUser user = null, ulong Amount = 0, bool admin = false) public async Task AddPoints(SocketUser user = null, ulong amount = 0, bool admin = false)
{ {
ulong cur = 0; ulong cur = 0;
try try
@ -190,13 +189,13 @@ namespace ChaosBot.Discord.Modules.User
if (ctxPointCheck.Any()) if (ctxPointCheck.Any())
{ {
usrPoint = ctxPointCheck.First(); usrPoint = ctxPointCheck.First();
cur = usrPoint.Amount + Amount; cur = usrPoint.Amount + amount;
} }
else else
{ {
usrPoint = new Point(); usrPoint = new Point();
cur = Amount; cur = amount;
} }
usrPoint.Amount = cur; usrPoint.Amount = cur;
usrPoint.DiscordGuildId = Context.Guild.Id; usrPoint.DiscordGuildId = Context.Guild.Id;
@ -207,8 +206,7 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has added {Amount} points to {user.Mention} for a total of {cur} points.", $"{Context.User.Mention} has added {amount} points to {user.Mention} for a total of {cur} points.");
false);
} }
else else
{ {
@ -223,9 +221,9 @@ namespace ChaosBot.Discord.Modules.User
{ {
Point usrPoint = ctxUserPoint.First(); Point usrPoint = ctxUserPoint.First();
if (usrPoint.Amount >= Amount) if (usrPoint.Amount >= amount)
{ {
usrPoint.Amount -= Amount; usrPoint.Amount -= amount;
usrPoint.DiscordGuildId = Context.Guild.Id; usrPoint.DiscordGuildId = Context.Guild.Id;
usrPoint.DiscordUserId = Context.User.Id; usrPoint.DiscordUserId = Context.User.Id;
@ -236,12 +234,12 @@ namespace ChaosBot.Discord.Modules.User
if (ctxRctPoint.Any()) if (ctxRctPoint.Any())
{ {
rctPoint = ctxRctPoint.First(); rctPoint = ctxRctPoint.First();
cur = rctPoint.Amount + Amount; cur = rctPoint.Amount + amount;
} }
else else
{ {
rctPoint = new Point(); rctPoint = new Point();
cur = Amount; cur = amount;
} }
rctPoint.Amount = cur; rctPoint.Amount = cur;
rctPoint.DiscordGuildId = Context.Guild.Id; rctPoint.DiscordGuildId = Context.Guild.Id;
@ -251,21 +249,18 @@ namespace ChaosBot.Discord.Modules.User
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync(); .On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has given {user.Mention} {Amount} points for a total of {cur} points.", $"{Context.User.Mention} has given {user.Mention} {amount} points for a total of {cur} points.");
false);
} }
else else
{ {
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention}, you do not have enough points to give {user.Mention} {Amount} points.", $"{Context.User.Mention}, you do not have enough points to give {user.Mention} {amount} points.");
false);
} }
} }
else else
{ {
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention}, you do not have enough points to give {user.Mention} {Amount} points.", $"{Context.User.Mention}, you do not have enough points to give {user.Mention} {amount} points.");
false);
} }
} }
} }
@ -298,8 +293,7 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has removed all points from {user.Mention}.", $"{Context.User.Mention} has removed all points from {user.Mention}.");
false);
} }
} }
} }

View File

@ -4,10 +4,10 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ChaosBot.Discord.PreConditions; using ChaosBot.Discord.PreConditions;
using ChaosBot.Models; using ChaosBot.Models;
using Discord;
using Discord.Commands;
using ChaosBot.Repositories; using ChaosBot.Repositories;
using ChaosBot.Services; using ChaosBot.Services;
using Discord;
using Discord.Commands;
using Discord.WebSocket; using Discord.WebSocket;
namespace ChaosBot.Discord.Modules.User namespace ChaosBot.Discord.Modules.User
@ -64,7 +64,7 @@ namespace ChaosBot.Discord.Modules.User
await RaffleHelp(); await RaffleHelp();
} }
} }
else if ((cmd.ToLower() == "=") || (cmd.ToLower() == "info") || (cmd.ToLower() == "total") || (cmd == null)) else if ((cmd.ToLower() == "=") || (cmd.ToLower() == "info") || (cmd.ToLower() == "total"))
{ {
await TotalRaffle(); await TotalRaffle();
} }
@ -87,21 +87,21 @@ namespace ChaosBot.Discord.Modules.User
var embed = new EmbedBuilder(); var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0)); embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Raffle system"; embed.Title = "Raffle system";
sb.AppendLine($"{Context.User.Mention} has requested Raffle information."); sb.AppendLine($"{Context.User.Mention} has requested Raffle information.");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine($"Usage:"); sb.AppendLine("Usage:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle info"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle info");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle help"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle help");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle buy <amount>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle buy <amount>");
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("Moderation commands:"); sb.AppendLine("Moderation commands:");
if(CheckPermissions.CheckPerms(Context, "raffle.add", "Admin")) if(CheckPermissions.CheckPerms(Context, "raffle.add", "Admin"))
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle add <discord mention> <amount>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle add <discord mention> <amount>");
if(CheckPermissions.CheckPerms(Context, "raffle.remove", "Admin")) if(CheckPermissions.CheckPerms(Context, "raffle.remove", "Admin"))
{ {
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle remove <discord mention> <amount>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle remove <discord mention> <amount>");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle delete <discord mention>"); sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle delete <discord mention>");
} }
/* /*
* Add the string to the Embed * Add the string to the Embed
@ -139,7 +139,7 @@ namespace ChaosBot.Discord.Modules.User
LoggingFacade.Exception(ex); LoggingFacade.Exception(ex);
} }
await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.", false); await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.");
} }
public async Task AddRaffle(SocketUser user = null, int amount = 0, bool admin = false) public async Task AddRaffle(SocketUser user = null, int amount = 0, bool admin = false)
@ -172,8 +172,7 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has added {amount} tickets to {user.Mention} for a total of {cur} tickets.", $"{Context.User.Mention} has added {amount} tickets to {user.Mention} for a total of {cur} tickets.");
false);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -182,7 +181,7 @@ namespace ChaosBot.Discord.Modules.User
} }
} }
public async Task RemRaffle(SocketUser user = null, int Amount = 0) public async Task RemRaffle(SocketUser user = null, int amount = 0)
{ {
int cur = 0; int cur = 0;
try try
@ -197,12 +196,12 @@ namespace ChaosBot.Discord.Modules.User
cur = ctxRaffleDetail.Count(); cur = ctxRaffleDetail.Count();
if (cur < Amount) if (cur < amount)
Amount = cur; amount = cur;
if (cur != 0) if (cur != 0)
{ {
for (int i = 0; i < Amount; i++) for (int i = 0; i < amount; i++)
{ {
Raffle usrRaff = ctxRaffleDetail.First(); Raffle usrRaff = ctxRaffleDetail.First();
dbContext.Raffles.Remove(usrRaff); dbContext.Raffles.Remove(usrRaff);
@ -217,8 +216,7 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has taken {Amount} raffle tickets from {user.Mention} leaving them with a total of {cur-Amount} raffle tickets.", $"{Context.User.Mention} has taken {amount} raffle tickets from {user.Mention} leaving them with a total of {cur-amount} raffle tickets.");
false);
} }
public async Task DelRaffle(SocketUser user = null) public async Task DelRaffle(SocketUser user = null)
@ -243,8 +241,7 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has removed all raffle tickets from {user.Mention}.", $"{Context.User.Mention} has removed all raffle tickets from {user.Mention}.");
false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -277,14 +274,12 @@ namespace ChaosBot.Discord.Modules.User
} }
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} has removed all tickets.", $"{Context.User.Mention} has removed all tickets.");
false);
} }
else else
{ {
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention}, if you wish to clear ALL tickets, please send the below command.```{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle clear confirm```", $"{Context.User.Mention}, if you wish to clear ALL tickets, please send the below command.```{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle clear confirm```");
false);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -308,14 +303,13 @@ namespace ChaosBot.Discord.Modules.User
if (ctxRaffleDetails.Any()) if (ctxRaffleDetails.Any())
{ {
var count = new Random().Next(0, ctxRaffleDetails.Count - 1); var count = new Random().Next(0, ctxRaffleDetails.Count - 1);
Raffle WinnerTicket = ctxRaffleDetail.Where(r => r.Id == ctxRaffleDetails[count].Id).First(); Raffle winnerTicket = ctxRaffleDetail.Where(r => r.Id == ctxRaffleDetails[count].Id).First();
dbContext.Raffles.Remove(WinnerTicket); dbContext.Raffles.Remove(winnerTicket);
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
await ReplyAsync( await ReplyAsync(
$"{Context.User.Mention} drawn a ticket, <@{WinnerTicket.DiscordUserId}> has won the raffle!", $"{Context.User.Mention} drawn a ticket, <@{winnerTicket.DiscordUserId}> has won the raffle!");
false);
} }
} }
} }

View File

@ -19,10 +19,10 @@ namespace ChaosBot.Discord.Modules.User
{ {
try try
{ {
string diceRecipe = null; string diceRecipe;
if (args.Length >= 1) if (args.Length >= 1)
diceRecipe = Strings.Join(args, " "); diceRecipe = Strings.Join(args);
else else
diceRecipe = "1d20"; diceRecipe = "1d20";

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using ChaosBot.Models; using ChaosBot.Models;
using ChaosBot.Repositories; using ChaosBot.Repositories;
@ -10,7 +9,7 @@ namespace ChaosBot.Services
{ {
public class CheckPermissions public class CheckPermissions
{ {
public static Boolean CheckPerms(ICommandContext context, string command, string defaultRole = "User") public static bool CheckPerms(ICommandContext context, string command, string defaultRole = "User")
{ {
// Debug information // Debug information
LoggingFacade.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command}"); LoggingFacade.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command}");
@ -39,7 +38,7 @@ namespace ChaosBot.Services
if (perm.TargetType == (int)PermissionTarget.Role) if (perm.TargetType == (int)PermissionTarget.Role)
{ {
// If it's a role, check the configuration for the role otherwise return the permission value // If it's a role, check the configuration for the role otherwise return the permission value
requiredGroup = ConfigurationRepository.GetValue<ulong>($"Role:{perm.TargetId}", context.Guild.Id, perm.TargetId); requiredGroup = ConfigurationRepository.GetValue($"Role:{perm.TargetId}", context.Guild.Id, perm.TargetId);
} }
else if (perm.TargetType == (int) PermissionTarget.User) else if (perm.TargetType == (int) PermissionTarget.User)
{ {
@ -72,7 +71,7 @@ namespace ChaosBot.Services
return true; return true;
} }
else else
LoggingFacade.Info($"CheckCommandperm.CheckPermissionsAsync|commandPermissions: No Default"); LoggingFacade.Info("CheckCommandperm.CheckPermissionsAsync|commandPermissions: No Default");
} }
// Permission denied // Permission denied