protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer args = new ArgumentContainer(); if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out args.TargetUser, allowSelf: false, allowName: false)) { return(Task.FromResult(new ArgumentParseResult(ARGS[0]))); } context.Arguments.Index++; args.Reason = context.Arguments.First; return(Task.FromResult(new ArgumentParseResult(args))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer argOut = new ArgumentContainer(); if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out argOut.TargetUser)) { return(Task.FromResult(new ArgumentParseResult(Arguments[0]))); } context.Arguments.Index++; argOut.Warning = context.Arguments.First; return(Task.FromResult(new ArgumentParseResult(argOut))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer argOut = new ArgumentContainer(); if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out argOut.TargetUser)) { return(Task.FromResult(new ArgumentParseResult(Arguments[0], $"Could not parse {context.Arguments.First} to a discord guild user!"))); } context.Arguments.Index++; argOut.NewNickname = context.Arguments.First; return(Task.FromResult(new ArgumentParseResult(argOut))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer argOut = new ArgumentContainer(); if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out argOut.TargetUser)) { if (!ulong.TryParse(context.Arguments.First, out argOut.UserId)) { argOut.TargetUser = null; argOut.UserId = 0; return(Task.FromResult(new ArgumentParseResult(Arguments[0]))); } } else { argOut.UserId = argOut.TargetUser.Id; } return(Task.FromResult(new ArgumentParseResult(argOut))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { SocketUser User; if (context.Arguments.Count == 0) { User = context.User; } else { if (ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out SocketGuildUser guildUser)) { User = guildUser; } else { return(Task.FromResult(new ArgumentParseResult(Arguments[0], "Failed to parse to a User!"))); } } return(Task.FromResult(new ArgumentParseResult(User))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer args = new ArgumentContainer(); if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out args.TargetUser, allowName: false, allowSelf: false)) { return(Task.FromResult(new ArgumentParseResult(Arguments[0]))); } context.Arguments.Index++; if (context.Arguments.First.ToLower() == "perma") { args.MuteUntil = DateTimeOffset.MaxValue; } else { if (context.Arguments.First.Length == 1) { return(Task.FromResult(new ArgumentParseResult(Arguments[1]))); } char format = context.Arguments.First[context.Arguments.First.Length - 1]; string amount_str = context.Arguments.First.Substring(0, context.Arguments.First.Length - 1); if (double.TryParse(amount_str, out double amount)) { switch (format) { case 'm': args.Duration = TimeSpan.FromMinutes(amount); break; case 'h': args.Duration = TimeSpan.FromHours(amount); break; case 'd': args.Duration = TimeSpan.FromDays(amount); break; case 'M': args.Duration = TimeSpan.FromDays(amount * 30.4375); break; case 'y': args.Duration = TimeSpan.FromDays(amount * 365.25); break; default: return(Task.FromResult(new ArgumentParseResult(Arguments[1]))); } args.MuteUntil = DateTimeOffset.UtcNow + args.Duration; } else { return(Task.FromResult(new ArgumentParseResult(Arguments[1]))); } } context.Arguments.Index++; args.Reason = context.Arguments.First; return(Task.FromResult(new ArgumentParseResult(args))); }
protected override Task <ArgumentParseResult> ParseArgumentsGuildAsync(IGuildCommandContext context) { ArgumentContainer argOut = new ArgumentContainer(); if (!Enum.TryParse(context.Arguments.First, true, out argOut.Filter)) { return(Task.FromResult(new ArgumentParseResult(Arguments[0], $"Could not select a filter mode from `{context.Arguments.First}`!"))); } if (argOut.Filter == SelectFilter.User) { context.Arguments.Index++; if (!ArgumentParsing.TryParseGuildUser(context, context.Arguments.First, out argOut.User)) { return(Task.FromResult(new ArgumentParseResult(Arguments[1], $"Could not select a user from `{context.Arguments.First}`!"))); } } context.Arguments.Index++; if (!Enum.TryParse(context.Arguments.First, true, out argOut.End)) { return(Task.FromResult(new ArgumentParseResult(Arguments[2], $"Could not select an end mode from `{context.Arguments.First}`!"))); } context.Arguments.Index++; if (context.Arguments.Count == 0) { return(Task.FromResult(new ArgumentParseResult(Arguments[3], $"You need to supply an argument for the endmode!"))); } switch (argOut.End) { case EndMode.Count: if (uint.TryParse(context.Arguments.First, out argOut.RemoveCount)) { if (argOut.Filter == SelectFilter.All) { argOut.InitalCount = (int)argOut.RemoveCount; } else { argOut.InitalCount = 1000; } } else { return(Task.FromResult(new ArgumentParseResult(Arguments[3], $"Could not parse `{context.Arguments.First}` to a valid number!"))); } break; case EndMode.Time: if (!DateTimeOffset.TryParseExact(context.Arguments.First, "H:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out argOut.DeleteAfter)) { return(Task.FromResult(new ArgumentParseResult(Arguments[3], $"Could not parse `{context.Arguments.First}` to a valid date and time. Required Format: `hh:mm` UTC!"))); } argOut.InitalCount = 1000; break; case EndMode.TimeRelative: if (Macros.TryParseHumanTimeString(context.Arguments.First, out TimeSpan maxAge)) { if (maxAge.TotalHours > MAXHOURS) { return(Task.FromResult(new ArgumentParseResult(Arguments[3], "Can not purge messages older than 24 hours!"))); } else { argOut.DeleteAfter = DateTimeOffset.UtcNow - maxAge; } } else { return(Task.FromResult(new ArgumentParseResult(Arguments[3], $"Could not parse `{context.Arguments.First}` to a valid timespan. Use Format `##h` or `##m`!"))); } argOut.InitalCount = 1000; break; } return(Task.FromResult(new ArgumentParseResult(argOut))); }