public void AddAndUseCommand() { Assert.False(CustomCommand.CommandExists(commandName)); CustomCommand.CustomCommands.Add(new CustomCommand(author, commandName, commandContent)); Assert.True(CustomCommand.CommandExists(commandName)); string result = CustomCommand.UseCustomCommand(commandName, argument, author, userList); Assert.Equal(result, "~~~" + argument + " " + randomUser + "!"); }
private static async Task CheckForCustomCommand(MessageCreateEventArgs a) { string[] split = a.Message.Content.Split(new char[] { ' ' }, 2); string arguments = split.Length > 1 ? split[1] : string.Empty; string senderUsername = Useful.GetUsername(a); string command = split[0].TrimStart(Settings.Default.commandChar); if (CustomCommand.CommandExists(command)) { string result = CustomCommand.UseCustomCommand(command, arguments, senderUsername, GetUserList(a.Channel.Guild, senderUsername)); if (!string.IsNullOrEmpty(result)) { await a.Message.RespondAsync(result).ConfigureAwait(false); } } }
public async Task AddCustomCommand(CommandContext ctx, string commandName, [RemainingText] string format) { logger.Info("addcmd Command", Useful.GetDiscordName(ctx)); if (CustomCommand.CommandExists(commandName) == true) { string message = "Command " + commandName + " already exists."; await ctx.RespondAsync(message).ConfigureAwait(false); } if (string.IsNullOrWhiteSpace(format)) { return; } CustomCommand.CustomCommands.Add(new CustomCommand(ctx.User.Username, commandName, format)); CustomCommand.SaveCustomCommands(); }
public async Task AddCustomCommand(CommandContext ctx) { Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "addcmd Command"); string nick = ctx.User.Username; string[] splits; string message; splits = ctx.Message.Content.Split(new char[] { ' ' }, 3); if (CustomCommand.CommandExists(splits[0], CustomCommand.CustomCommands) == true) { message = "Command " + splits[0] + " already exists."; await ctx.RespondAsync(message).ConfigureAwait(false); } CustomCommand.CustomCommands.Add(new CustomCommand(nick, splits[1], splits[2])); CustomCommand.SaveCustomCommands(CustomCommand.CustomCommands); }