public async Task CommandCustomList() { var prefix = await _command.GetPrefix(Context.Guild.Id); var commands = await _command.GetAllCustom(Context.Guild.Id); var commandMsg = string.Join("\n", commands.Select(x => $"{prefix}{x.Command}")); await ReplyAsync(_localization.GetMessage("Command custom list", commandMsg)); }
public async Task DefaultChat() { var commandPrefix = await _command.GetPrefix(Context.Guild.Id); ChatSession session; try { session = await _chat.CreateSession(Context.User as SocketGuildUser, Context.Channel); } catch (SessionExistsException e) { await ReplyAsync(_localization.GetMessage("Chat error exists", commandPrefix)); await _logs.Write("Chat", e, Context.Guild); return; } await ReplyAsync(_localization.GetMessage("Chat start")); while (!session.HasEnded) { var userMessage = await Interactive.NextMessageAsync(Context, timeout : TimeSpan.FromMinutes(1)); if (userMessage == null) { if (session.HasEnded) { break; } await ReplyAsync(_localization.GetMessage("Chat end timeout")); return; } if (userMessage.Content.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase) || userMessage.Content.StartsWith(Context.Client.CurrentUser.Mention, StringComparison.OrdinalIgnoreCase)) { if (userMessage.Content.EndsWith("chat stop", StringComparison.OrdinalIgnoreCase)) { break; } continue; } var response = await session.GetResponse(userMessage.Content); await ReplyAsync(response); } await ReplyAsync(_localization.GetMessage("Chat end")); }
public async Task CommandPrefixDefault() { await ReplyAsync(_localization.GetMessage("Command prefix default", await _command.GetPrefix(Context.Guild.Id), Context.Guild.Name)); }
private async Task HandleCommandAsync(SocketMessage s) { try { if (s.Author.IsBot) { return; } if (!(s is SocketUserMessage msg)) { return; } var context = new ShardedCommandContext(Client, msg); var prefix = "/"; try { prefix = await _commandService.GetPrefix(context.Guild.Id); } catch (UnknownServerException e) { await _server.Update(context.Guild); } var argPos = 0; if (!msg.HasStringPrefix(prefix, ref argPos) && !msg.HasMentionPrefix(Client.CurrentUser, ref argPos)) { return; } #if DEBUG if (!s.Author.Id.Equals(255453041531158538)) { await context.Channel.SendMessageAsync("Sorry, I cannot do that right now. I'm under development"); return; } #endif await Logs.Write("Commands", $"{context.User.Username} executed command '{context.Message}'.", context.Guild); var result = await _dcService.ExecuteAsync(context, argPos, _serviceProvider); if (result.IsSuccess) { return; } await Logs.Write("Commands", $"Execution failed. Error code: {result.ErrorReason}.", context.Guild); await _localization.Load(await _language.GetLanguage(context.Guild.Id)); switch (result.Error) { case CommandError.UnmetPrecondition: await context.Channel.SendMessageAsync(_localization.GetMessage("Command invalid permissions")); break; case CommandError.BadArgCount: await context.Channel.SendMessageAsync(_localization.GetMessage("Command invalid arguments", prefix)); break; default: if (await SendCustomCommand(context, argPos)) { return; } await context.Channel.SendMessageAsync(_localization.GetMessage("Command invalid", prefix)); break; } } catch (Exception e) { if ((s.Channel as SocketGuildChannel).Guild.Id.Equals(264445053596991498)) { return; } await Logs.Write("Crashes", "CommandHandler crashed.", e); } }
private async Task Prepare() { _prefix = await _command.GetPrefix(Context.Guild.Id); await _localization.Load(await _language.GetLanguage(Context.Guild.Id)); }