public void RunCommand(string cmd)
 {
     if (isAdmin)
     {
         executor.RunCommand(cmd);
     }
     else
     {
         if (cmd.Trim().StartsWith("rm"))
         {
             throw new Exception("rm Command is not allowed.");
         }
         else
         {
             executor.RunCommand(cmd);
         }
     }
 }
예제 #2
0
        private async Task RunAsyncCommand(Interaction?i)
        {
            using (var scope = Services.CreateScope())
            {
                var dbContext = scope.ServiceProvider.GetRequiredService <CoreDatabaseContext>();

                if (i?.GuildId != null && dbContext.GetGuildFor(i.GuildId) is null)
                {
                    var discordGuild = await DiscordBot.Instance.Client.GetGuildAsync(i.GuildId);

                    _logger.LogInformation("Registering guild: {GuildID}", discordGuild.Id);

                    dbContext.Add(new Guild(discordGuild.Name, discordGuild.Id.ToString()));
                    dbContext.SaveChanges();
                }

                var messageEvent = new SlashMessageEvent(i, dbContext);



                var res = Parse(i.Data);

                if (res.Callback is not null)
                {
                    if (res.Callback is CommandFunction func)
                    {
                        //func.Cmd(res, messageEvent);
                        await _executor.RunCommand(res, messageEvent);

                        //_eventBus.PostEventAsync()
                    }
                }
                else
                {
                    //await messageEvent.RespondError("Could not find the command");
                }
            }
        }