Inital bot commit

This commit is contained in:
Karolis2011
2019-06-18 19:17:06 +03:00
commit 81a82cbb5b
25 changed files with 1346 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
using Discord.Commands;
using EventBot.Entities;
using EventBot.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EventBot.Misc
{
class EventRoleTypeReader : TypeReader
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
var database = services.GetRequiredService<DatabaseService>();
if (context.Guild == null)
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Event roles are avaivable only inside guild context."));
EventRole er = null;
if (int.TryParse(input, out int id))
er = database.EventRoles.FirstOrDefault(r => r.Id == id);
else
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event role id is not a valid number."));
if(er == null)
return Task.FromResult(TypeReaderResult.FromError(CommandError.ObjectNotFound, "Specified event role was not found."));
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.FromSuccess(er));
}
}
}

View File

@@ -0,0 +1,30 @@
using Discord.Commands;
using EventBot.Entities;
using EventBot.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace EventBot.Misc
{
class EventTypeReader : TypeReader
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
var events = services.GetRequiredService<EventManagementService>();
if (context.Guild == null)
return Task.FromResult(TypeReaderResult.FromError(CommandError.UnmetPrecondition, "Events are avaivable only inside guild context."));
Event ev;
if (input == null)
ev = events.FindEventBy(context.Guild);
else if (int.TryParse(input, out int id))
ev = events.FindEventBy(context.Guild, id);
else
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Event id is not a number."));
return Task.FromResult(TypeReaderResult.FromSuccess(ev));
}
}
}