Moved some logic to commandhandler, to be able to use it externally easier

This commit is contained in:
Master Kwoth
2017-05-02 20:16:34 +02:00
parent f5523c8469
commit 8f894e095b
4 changed files with 66 additions and 16 deletions

View File

@ -41,22 +41,7 @@ namespace NadekoBot.Modules.Administration
foreach (var cmd in NadekoBot.BotConfig.StartupCommands)
{
if (cmd.GuildId != null)
{
var guild = NadekoBot.Client.GetGuild(cmd.GuildId.Value);
var channel = guild?.GetChannel(cmd.ChannelId) as SocketTextChannel;
if (channel == null)
continue;
try
{
IUserMessage msg = await channel.SendMessageAsync(cmd.CommandText).ConfigureAwait(false);
msg = (IUserMessage)await channel.GetMessageAsync(msg.Id).ConfigureAwait(false);
await NadekoBot.CommandHandler.TryRunCommand(guild, channel, msg).ConfigureAwait(false);
//msg.DeleteAfter(5);
}
catch { }
}
await NadekoBot.CommandHandler.ExecuteExternal(cmd.GuildId, cmd.ChannelId, cmd.CommandText);
await Task.Delay(400).ConfigureAwait(false);
}
});

View File

@ -55,6 +55,27 @@ namespace NadekoBot.Services
UsersOnShortCooldown.Clear();
}, null, GlobalCommandsCooldown, GlobalCommandsCooldown);
}
public async Task ExecuteExternal(ulong? guildId, ulong channelId, string commandText)
{
if (guildId != null)
{
var guild = NadekoBot.Client.GetGuild(guildId.Value);
var channel = guild?.GetChannel(channelId) as SocketTextChannel;
if (channel == null)
return;
try
{
IUserMessage msg = await channel.SendMessageAsync(commandText).ConfigureAwait(false);
msg = (IUserMessage)await channel.GetMessageAsync(msg.Id).ConfigureAwait(false);
await TryRunCommand(guild, channel, msg).ConfigureAwait(false);
//msg.DeleteAfter(5);
}
catch { }
}
}
public Task StartHandling()
{
var _ = Task.Run(async () =>