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."))
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.Debug($"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}");
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}");
}
}
}

View File

@ -48,14 +48,14 @@ namespace ChaosBot.Discord.Modules.Admin
embed.Title = $"Configuration Management Help";
sb.AppendLine();
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($"{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($"{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("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
@ -124,7 +124,7 @@ namespace ChaosBot.Discord.Modules.Admin
embed.Title = $"Configuration Retrieval";
sb.AppendLine();
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

View File

@ -19,7 +19,7 @@ namespace ChaosBot.Discord.Modules.Admin
[Command("rankCheck")]
[Alias("rc")]
[CheckCommandPerm("Admin")]
public async Task rankCheck()
public async Task Check()
{
try
{
@ -38,15 +38,15 @@ namespace ChaosBot.Discord.Modules.Admin
sb.AppendLine($"**Recruits Pending Promotion to Initiate**");
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)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
if(lsId.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, (lsId.DiscordId != null ? $", linked to <@{lsId.DiscordId}>)" : "")));
else
{
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
ulong lodeId = Convert.ToUInt64(lsId.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -56,11 +56,11 @@ namespace ChaosBot.Discord.Modules.Admin
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
{
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**");
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)
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
if(lsId.DiscordId != null)
sb.AppendLine(string.Format("{0}{1}", lsId.DisplayName, (lsId.DiscordId != null ? $", linked to <@{lsId.DiscordId}>)" : "")));
else
{
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
ulong lodeId = Convert.ToUInt64(lsId.LodestoneId);
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -92,11 +92,11 @@ namespace ChaosBot.Discord.Modules.Admin
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
{
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";
sb.AppendLine();
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($"{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($"{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("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

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 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($"\tLevel: {usrXp.First().Level}");
sb.AppendLine($"\tExperience: {usrXp.First().Amount}");
sb.AppendLine($"\tNeeded to Level: {nextLevelXP}");
sb.AppendLine($"\tNeeded to Level: {nextLevelXp}");
}
else
{

View File

@ -34,7 +34,7 @@ namespace ChaosBot.Discord.Modules.User
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)
{
@ -75,26 +75,26 @@ namespace ChaosBot.Discord.Modules.User
var embed = new EmbedBuilder();
embed.WithColor(new Color(255, 255, 0));
embed.Title = $"Lodestone API Help";
embed.Title = "Lodestone API Help";
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("To get FreeCompany Info:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("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 Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone freecompany Siren Helix");
sb.AppendLine();
sb.AppendLine("To get Character Info:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("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");
if (CheckPermissions.CheckPerms(Context, "lodestone.link", "User"))
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone character 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone character Siren Luna Kaisar");
if (CheckPermissions.CheckPerms(Context, "lodestone.link"))
{
sb.AppendLine("To Link your Character:");
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("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 Id: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone link 9231394073691143535");
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}lodestone link Siren Luna Kaisar");
}
sb.AppendLine();
sb.AppendLine();
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
@ -155,13 +155,15 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine();
if (name.Length == 0)
{
character = LodestoneManager.GetCharacter(Convert.ToInt64(value));
}
else
{
character = LodestoneManager.GetCharacter(value, string.Join(" ", name));
}
Boolean linked = false;
bool linked;
using (ChaosbotContext dbContext = new ChaosbotContext())
{
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
@ -173,11 +175,11 @@ namespace ChaosBot.Discord.Modules.User
if(!linked)
{
string b64 =
System.Convert.ToBase64String(Encoding.GetEncoding(28591)
Convert.ToBase64String(Encoding.GetEncoding(28591)
.GetBytes(character.Character.ID.ToString())) + '|' +
System.Convert.ToBase64String(Encoding.GetEncoding(28591)
Convert.ToBase64String(Encoding.GetEncoding(28591)
.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))
{
@ -283,7 +285,8 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine($"Pledged to Grand Company {freeCompany.FreeCompany.GrandCompany}");
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()})
.OrderBy(x => x.Rank);
@ -316,7 +319,7 @@ namespace ChaosBot.Discord.Modules.User
sb.AppendLine($"Bio: {character.Character.Bio}");
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("All Jobs:");
@ -327,7 +330,9 @@ namespace ChaosBot.Discord.Modules.User
if (characterClassJob.Level == 0) continue;
Tuple<string, ClassType> classInfo =
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)

View File

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

View File

@ -4,10 +4,10 @@ using System.Text;
using System.Threading.Tasks;
using ChaosBot.Discord.PreConditions;
using ChaosBot.Models;
using Discord;
using Discord.Commands;
using ChaosBot.Repositories;
using ChaosBot.Services;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
namespace ChaosBot.Discord.Modules.User
@ -64,7 +64,7 @@ namespace ChaosBot.Discord.Modules.User
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();
}
@ -87,21 +87,21 @@ namespace ChaosBot.Discord.Modules.User
var embed = new EmbedBuilder();
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();
sb.AppendLine($"Usage:");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle info");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle help");
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}raffle buy <amount>");
sb.AppendLine("Usage:");
sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle info");
sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle help");
sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle buy <amount>");
sb.AppendLine();
sb.AppendLine("Moderation commands:");
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"))
{
sb.AppendLine($"{ConfigurationRepository.GetValue<string>("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 remove <discord mention> <amount>");
sb.AppendLine($"{ConfigurationRepository.GetValue("Discord:Prefix", Context.Guild.Id, "!")}raffle delete <discord mention>");
}
/*
* Add the string to the Embed
@ -139,7 +139,7 @@ namespace ChaosBot.Discord.Modules.User
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)
@ -172,8 +172,7 @@ namespace ChaosBot.Discord.Modules.User
}
await ReplyAsync(
$"{Context.User.Mention} has added {amount} tickets to {user.Mention} for a total of {cur} tickets.",
false);
$"{Context.User.Mention} has added {amount} tickets to {user.Mention} for a total of {cur} tickets.");
}
}
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;
try
@ -197,12 +196,12 @@ namespace ChaosBot.Discord.Modules.User
cur = ctxRaffleDetail.Count();
if (cur < Amount)
Amount = cur;
if (cur < amount)
amount = cur;
if (cur != 0)
{
for (int i = 0; i < Amount; i++)
for (int i = 0; i < amount; i++)
{
Raffle usrRaff = ctxRaffleDetail.First();
dbContext.Raffles.Remove(usrRaff);
@ -217,8 +216,7 @@ namespace ChaosBot.Discord.Modules.User
}
await ReplyAsync(
$"{Context.User.Mention} has taken {Amount} raffle tickets from {user.Mention} leaving them with a total of {cur-Amount} raffle tickets.",
false);
$"{Context.User.Mention} has taken {amount} raffle tickets from {user.Mention} leaving them with a total of {cur-amount} raffle tickets.");
}
public async Task DelRaffle(SocketUser user = null)
@ -243,8 +241,7 @@ namespace ChaosBot.Discord.Modules.User
}
await ReplyAsync(
$"{Context.User.Mention} has removed all raffle tickets from {user.Mention}.",
false);
$"{Context.User.Mention} has removed all raffle tickets from {user.Mention}.");
}
catch (Exception ex)
{
@ -277,14 +274,12 @@ namespace ChaosBot.Discord.Modules.User
}
await ReplyAsync(
$"{Context.User.Mention} has removed all tickets.",
false);
$"{Context.User.Mention} has removed all tickets.");
}
else
{
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```",
false);
$"{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```");
}
}
catch (Exception ex)
@ -308,14 +303,13 @@ namespace ChaosBot.Discord.Modules.User
if (ctxRaffleDetails.Any())
{
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 ReplyAsync(
$"{Context.User.Mention} drawn a ticket, <@{WinnerTicket.DiscordUserId}> has won the raffle!",
false);
$"{Context.User.Mention} drawn a ticket, <@{winnerTicket.DiscordUserId}> has won the raffle!");
}
}
}

View File

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

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using ChaosBot.Models;
using ChaosBot.Repositories;
@ -10,7 +9,7 @@ namespace ChaosBot.Services
{
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
LoggingFacade.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command}");
@ -39,7 +38,7 @@ namespace ChaosBot.Services
if (perm.TargetType == (int)PermissionTarget.Role)
{
// 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)
{
@ -72,7 +71,7 @@ namespace ChaosBot.Services
return true;
}
else
LoggingFacade.Info($"CheckCommandperm.CheckPermissionsAsync|commandPermissions: No Default");
LoggingFacade.Info("CheckCommandperm.CheckPermissionsAsync|commandPermissions: No Default");
}
// Permission denied