Fix some code style issues
This commit is contained in:
parent
2fb75190af
commit
f8b37391cb
7
.editorconfig
Normal file
7
.editorconfig
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
@ -114,11 +114,11 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TotalPoints()
|
public async Task TotalPoints()
|
||||||
{
|
{
|
||||||
ulong cur = 0;
|
ulong cur = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
@ -135,10 +135,8 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
_logger.Error(
|
_logger.Error(
|
||||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await ReplyAsync($"{Context.User.Mention}, you have {cur} points.", false);
|
|
||||||
|
|
||||||
|
await ReplyAsync($"{Context.User.Mention}, you have {cur} points.", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemPoints(SocketUser user = null, ulong Amount = 0)
|
public async Task RemPoints(SocketUser user = null, ulong Amount = 0)
|
||||||
@ -149,11 +147,11 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
IQueryable<Point> ctxusrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
IQueryable<Point> ctxusrPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||||
|
|
||||||
Point usrPoint;
|
Point usrPoint;
|
||||||
|
|
||||||
if(ctxusrPoint.Any())
|
if(ctxusrPoint.Any())
|
||||||
{
|
{
|
||||||
usrPoint = ctxusrPoint.First();
|
usrPoint = ctxusrPoint.First();
|
||||||
@ -196,7 +194,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
IQueryable<Point> ctxPointCheck = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
IQueryable<Point> ctxPointCheck = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||||
|
|
||||||
Point usrPoint;
|
Point usrPoint;
|
||||||
@ -217,7 +215,6 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
await dbContext.Points.Upsert(usrPoint)
|
await dbContext.Points.Upsert(usrPoint)
|
||||||
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
.On(x => new { x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyAsync(
|
await ReplyAsync(
|
||||||
@ -229,14 +226,14 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
IQueryable<Point> ctxUserPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id));
|
IQueryable<Point> ctxUserPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(Context.User.Id));
|
||||||
IQueryable<Point> ctxRctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
IQueryable<Point> ctxRctPoint = ctxPoints.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.DiscordUserId.Equals(user.Id));
|
||||||
|
|
||||||
if (ctxUserPoint.Any())
|
if (ctxUserPoint.Any())
|
||||||
{
|
{
|
||||||
Point usrPoint = ctxUserPoint.First();
|
Point usrPoint = ctxUserPoint.First();
|
||||||
|
|
||||||
if (usrPoint.Amount >= Amount)
|
if (usrPoint.Amount >= Amount)
|
||||||
{
|
{
|
||||||
usrPoint.Amount -= Amount;
|
usrPoint.Amount -= Amount;
|
||||||
@ -263,11 +260,10 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
await dbContext.Points.Upsert(rctPoint)
|
await dbContext.Points.Upsert(rctPoint)
|
||||||
.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);
|
false);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -299,7 +295,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
Point usrPoint = new Point();
|
Point usrPoint = new Point();
|
||||||
|
|
||||||
usrPoint.Amount = 0;
|
usrPoint.Amount = 0;
|
||||||
usrPoint.DiscordGuildId = Context.Guild.Id;
|
usrPoint.DiscordGuildId = Context.Guild.Id;
|
||||||
usrPoint.DiscordUserId = user.Id;
|
usrPoint.DiscordUserId = user.Id;
|
||||||
@ -319,4 +315,4 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,11 +124,11 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task TotalRaffle()
|
public async Task TotalRaffle()
|
||||||
{
|
{
|
||||||
int cur = 0;
|
int cur = 0;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
@ -145,13 +145,11 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
_logger.Error(
|
_logger.Error(
|
||||||
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
$"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.", false);
|
|
||||||
|
|
||||||
|
await ReplyAsync($"{Context.User.Mention}, you have {cur} raffle tickets.", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
int cur = 0;
|
int cur = 0;
|
||||||
try
|
try
|
||||||
@ -162,7 +160,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
for (int i = 0; i < Amount; i++)
|
for (int i = 0; i < amount; i++)
|
||||||
{
|
{
|
||||||
Raffle usrRaff = new Raffle();
|
Raffle usrRaff = new Raffle();
|
||||||
|
|
||||||
@ -181,7 +179,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);
|
false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,7 +204,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
.Where(p => p.DiscordUserId.Equals(user.Id));
|
.Where(p => p.DiscordUserId.Equals(user.Id));
|
||||||
|
|
||||||
cur = ctxRaffleDetail.Count();
|
cur = ctxRaffleDetail.Count();
|
||||||
|
|
||||||
if (cur < Amount)
|
if (cur < Amount)
|
||||||
Amount = cur;
|
Amount = cur;
|
||||||
|
|
||||||
@ -339,4 +337,4 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,10 +21,10 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
{
|
{
|
||||||
// Debug information
|
// Debug information
|
||||||
_logger.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command.Name}");
|
_logger.Trace($"CheckCommandPerm.CheckPermissionsAsync|Checking permissions for command: {command.Name}");
|
||||||
|
|
||||||
// If user is not SocketGuildUser, then return error
|
// If user is not SocketGuildUser, then return error
|
||||||
if (!(context.User is SocketGuildUser gUser)) return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command."));
|
if (!(context.User is SocketGuildUser gUser)) return Task.FromResult(PreconditionResult.FromError("You must be in a guild to run this command."));
|
||||||
|
|
||||||
// Get the possible permissions
|
// Get the possible permissions
|
||||||
List<CommandPermission> commandPermissions;
|
List<CommandPermission> commandPermissions;
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
@ -52,7 +52,7 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
{
|
{
|
||||||
if(context.User.Id == perm.TargetId)
|
if(context.User.Id == perm.TargetId)
|
||||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||||
|
|
||||||
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -60,7 +60,7 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
// Return the permission value
|
// Return the permission value
|
||||||
requiredGroup = perm.TargetId;
|
requiredGroup = perm.TargetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any of the users roles are of the required group, if so, permission granted
|
// Check if any of the users roles are of the required group, if so, permission granted
|
||||||
if (gUser.Roles.Any(r => r.Id == requiredGroup))
|
if (gUser.Roles.Any(r => r.Id == requiredGroup))
|
||||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||||
@ -86,4 +86,4 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,13 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
_logger.Trace($"CheckModuleEnabled.CheckPermissionsAsync|Checking module enabled for module: {_moduleName}");
|
_logger.Trace($"CheckModuleEnabled.CheckPermissionsAsync|Checking module enabled for module: {_moduleName}");
|
||||||
|
|
||||||
if (context.Guild == null) return Task.FromResult(PreconditionResult.FromError("This must be run in a guild."));
|
if (context.Guild == null) return Task.FromResult(PreconditionResult.FromError("This must be run in a guild."));
|
||||||
|
|
||||||
// Check if module enabled in database
|
// Check if module enabled in database
|
||||||
bool isModuleEnabled = GetResult(context, _moduleName);
|
bool isModuleEnabled = GetResult(context, _moduleName);
|
||||||
|
|
||||||
if (isModuleEnabled)
|
if (isModuleEnabled)
|
||||||
return Task.FromResult(PreconditionResult.FromSuccess());
|
return Task.FromResult(PreconditionResult.FromSuccess());
|
||||||
|
|
||||||
// Permission denied
|
// Permission denied
|
||||||
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
return Task.FromResult(PreconditionResult.FromError($"You do not have access to this command."));
|
||||||
}
|
}
|
||||||
@ -36,10 +36,10 @@ namespace ChaosBot.Discord.PreConditions
|
|||||||
public static bool GetResult(ICommandContext context, string moduleName)
|
public static bool GetResult(ICommandContext context, string moduleName)
|
||||||
{
|
{
|
||||||
if (context.Guild == null) throw new Exception("This must be run in a guild");
|
if (context.Guild == null) throw new Exception("This must be run in a guild");
|
||||||
|
|
||||||
// Check if module enabled in database
|
// Check if module enabled in database
|
||||||
return Convert.ToBoolean(ConfigurationRepository.GetValue<string>($"Module:{moduleName}:Enabled",
|
return Convert.ToBoolean(ConfigurationRepository.GetValue<string>($"Module:{moduleName}:Enabled",
|
||||||
context.Guild.Id, "true"));
|
context.Guild.Id, "true"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,10 +115,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
.On(x => new {x.DiscordGuildId, x.DiscordUserId}).RunAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server.");
|
await user.Guild.SystemChannel.SendMessageAsync($"{user.Username} has joined the server.");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -213,4 +210,4 @@ namespace ChaosBot.Discord.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,4 +44,4 @@ namespace ChaosBot.Discord.Services
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
@ -116,4 +116,4 @@ namespace ChaosBot.Discord.Services
|
|||||||
return curLevel;
|
return curLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
public static void Initialize(IServiceProvider services)
|
public static void Initialize(IServiceProvider services)
|
||||||
{
|
{
|
||||||
_client = services.GetRequiredService<DiscordSocketClient>();
|
_client = services.GetRequiredService<DiscordSocketClient>();
|
||||||
|
|
||||||
foreach (IConfigurationSection serverConfig in Program.AppSettingsHandler.GetSection("Servers").GetChildren())
|
foreach (IConfigurationSection serverConfig in Program.AppSettingsHandler.GetSection("Servers").GetChildren())
|
||||||
{
|
{
|
||||||
long? lodestoneChannelSloganDescriptionId = serverConfig.GetValue<long?>("Lodestone:SloganDescription:Channel", null);
|
long? lodestoneChannelSloganDescriptionId = serverConfig.GetValue<long?>("Lodestone:SloganDescription:Channel", null);
|
||||||
@ -50,13 +50,13 @@ namespace ChaosBot.Discord.Services
|
|||||||
_logger.Warn($"Could not cast channel {socketChannel.Id} to ITextChannel");
|
_logger.Warn($"Could not cast channel {socketChannel.Id} to ITextChannel");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!guild.GetUser(_client.CurrentUser.Id).GetPermissions(channel).ManageChannel) return;
|
if (!guild.GetUser(_client.CurrentUser.Id).GetPermissions(channel).ManageChannel) return;
|
||||||
|
|
||||||
string description = LodestoneManager
|
string description = LodestoneManager
|
||||||
.GetFreeCompanyById(serverConfig.GetValue<string>("Lodestone:FreeCompanyId")).FreeCompany
|
.GetFreeCompanyById(serverConfig.GetValue<string>("Lodestone:FreeCompanyId")).FreeCompany
|
||||||
.Slogan;
|
.Slogan;
|
||||||
|
|
||||||
await channel.ModifyAsync(x => { x.Topic = description; });
|
await channel.ModifyAsync(x => { x.Topic = description; });
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -69,4 +69,4 @@ namespace ChaosBot.Discord.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user