public static string input(SocketCommandContext context, IEnumerable<IMessage> messages) { StringBuilder input = new StringBuilder(); string formatter = ConfigMan.Get("messageFormat"); foreach (var message in messages.ToArray().Reverse()) { if(!string.IsNullOrEmpty(formatter)) input.Append((formatter + "\r\n").Replace("[author]", message.Author.Username).Replace("[content]", message.Content);
public async Task Config() { StringBuilder bob = new StringBuilder(); bob.Append($"Generating text from last {ConfigMan.Get("numMessages")} messages (numMessages)\r\n"); bob.Append($"1/{ConfigMan.Get("respChance")} chance of responding (respChance)\r\n"); bob.Append($"Conversation weighted by {ConfigMan.Get("weightFactor")} (weightFactor)\r\n"); await Context.Channel.SendMessageAsync(bob.ToString()); }
public async Task Debug() { string users = ConfigMan.Get("adminUsers"); if (string.IsNullOrEmpty(users) || users.Split(",").Any(x => x.ToLower().Trim() == Context.Message.Author.Username.ToLower())) { Program.debug = !Program.debug; await Context.Channel.SendMessageAsync((Program.debug ? "Entering debug mode" : "Exiting debug mode")); } else { await Context.Channel.SendMessageAsync("You do not have permission to perform that action"); } }
private async Task HandleCommandAsync(SocketMessage messageParam) { // Don't process the command if it was a system message var message = messageParam as SocketUserMessage; if (message == null) { return; } // Create a number to track where the prefix ends and the command begins int argPos = 0; //Ignore bots if (message.Author.IsBot) { return; } // Create a WebSocket-based command context based on the message var context = new SocketCommandContext(_client, message); messageNum = int.Parse(ConfigMan.Get("NumMessages")); var messages = await context.Channel.GetMessagesAsync(context.Message, Direction.Before, int.Parse(ConfigMan.Get("NumMessages"))).FlattenAsync(); if (message.HasCharPrefix(ConfigMan.Get("Prefix")[0], ref argPos)) { if (Program.debug || Regex.IsMatch(message.Content.Trim(), @"\+debug", RegexOptions.IgnoreCase)) { // Execute the command with the command context we just // created, along with the service provider for precondition checks. await _commands.ExecuteAsync( context : context, argPos : argPos, services : null); } else { await context.Channel.SendMessageAsync("This command requires debug mode, send +debug to toggle debug mode."); } } else if ((BLL.ShouldRandomlySend(context, messages, _client.CurrentUser) || Program.talkative) || message.HasMentionPrefix(_client.CurrentUser, ref argPos) && !BLL.CheckIsOtherBotPrefix(message.Content[0])) { /*@ people properly*/ await context.Channel.SendMessageAsync(); } }
public async Task StartAsync() { _client = new DiscordSocketClient(); _client.Log += Log; var token = ConfigMan.Get("Token"); await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); CommandHandler handler = new CommandHandler(_client, new Discord.Commands.CommandService()); await handler.InstallCommandsAsync(); // Block this task until the program is closed. await Task.Delay(-1); }
public async Task Input() { var messages = await Context.Channel.GetMessagesAsync(Context.Message, Direction.Before, int.Parse(ConfigMan.Get("NumMessages"))).FlattenAsync(); await Context.Channel.SendMessageAsync(BLL.input(Context, messages)); }