final commit
This commit is contained in:
@@ -15,16 +15,16 @@ namespace EventBot.Misc
|
|||||||
{
|
{
|
||||||
var database = services.GetRequiredService<DatabaseService>();
|
var database = services.GetRequiredService<DatabaseService>();
|
||||||
if (context.Guild == null)
|
if (context.Guild == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Event roles are available only inside guild context."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Event roles are available only inside a discord server."));
|
||||||
EventRole er = null;
|
EventRole er = null;
|
||||||
if (int.TryParse(input, out int id))
|
if (int.TryParse(input, out int id))
|
||||||
er = database.EventRoles.FirstOrDefault(r => r.Id == id);
|
er = database.EventRoles.FirstOrDefault(r => r.Id == id);
|
||||||
else
|
else
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event role id is not a valid number."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event role IS is not a valid number."));
|
||||||
if(er == null)
|
if(er == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Specified event role was not found."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Specified event role was not found."));
|
||||||
if(er.Event?.GuildId != context.Guild.Id)
|
if(er.Event?.GuildId != context.Guild.Id)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, "Cross guild event role access is denied."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.Exception, "Cross server event role access is denied."));
|
||||||
return Task.FromResult(TypeReaderResult.FromSuccess(er));
|
return Task.FromResult(TypeReaderResult.FromSuccess(er));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,14 +15,14 @@ namespace EventBot.Misc
|
|||||||
{
|
{
|
||||||
var events = services.GetRequiredService<EventManagementService>();
|
var events = services.GetRequiredService<EventManagementService>();
|
||||||
if (context.Guild == null)
|
if (context.Guild == null)
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Events are available only inside guild context."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Events are available only inside a discord server."));
|
||||||
Event ev;
|
Event ev;
|
||||||
if (input == null)
|
if (input == null)
|
||||||
ev = events.FindEventBy(context.Guild, true);
|
ev = events.FindEventBy(context.Guild, true);
|
||||||
else if (int.TryParse(input, out int id))
|
else if (int.TryParse(input, out int id))
|
||||||
ev = events.FindEventBy(context.Guild, id, true);
|
ev = events.FindEventBy(context.Guild, id, true);
|
||||||
else
|
else
|
||||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event id is not a number."));
|
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event ID is not a number."));
|
||||||
|
|
||||||
return Task.FromResult(TypeReaderResult.FromSuccess(ev));
|
return Task.FromResult(TypeReaderResult.FromSuccess(ev));
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ namespace EventBot.Services
|
|||||||
public async Task TryJoinEvent(IGuildUser user, EventRole er, string extra, bool extraChecks = true)
|
public async Task TryJoinEvent(IGuildUser user, EventRole er, string extra, bool extraChecks = true)
|
||||||
{
|
{
|
||||||
if (er.Event.GuildId != user.GuildId)
|
if (er.Event.GuildId != user.GuildId)
|
||||||
throw new Exception("Cross guild events are forbidden.");
|
throw new Exception("Cross server events are forbidden.");
|
||||||
if (extraChecks && er.ReamainingOpenings <= 0)
|
if (extraChecks && er.ReamainingOpenings <= 0)
|
||||||
throw new Exception("No openings are left.");
|
throw new Exception("No openings are left.");
|
||||||
if(er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
if(er.Event.Participants.Where(p => p.UserId == user.Id).Count() > 0)
|
||||||
|
Reference in New Issue
Block a user