public async Task FilterExclude(CommandContext ctx, string word) { if (ctx.Member.GetRole().IsSeniorModOrHigher()) { await ctx.TriggerTypingAsync(); // Cancels: if (FilterSystem.IsWord(word)) { await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Cannot add that word. It's a filter word...")); return; } if (Excludes.IsExcluded(word)) { await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Cannot add that word. It's already excluded...")); return; } Excludes.AddWord(word); Excludes.Save(); await ctx.Channel.SendMessageAsync( ChatObjects.GetSuccessMessage( String.Format("I excluded the word {0}!", word))); } }
public async Task GetUserInfo(CommandContext ctx, DiscordMember member) { if (ctx.Member.GetRole().IsCHOrHigher()) { await ctx.Channel.TriggerTypingAsync(); if (ctx.Guild.Members.ContainsKey(member.Id)) { // DEB! var deb = new DiscordEmbedBuilder(); deb.WithColor(DiscordColor.Aquamarine); deb.WithTitle("User Info"); deb.WithThumbnailUrl(member.AvatarUrl); deb.AddField(@"Joined Discord:", GetDateString(GetJoinedDiscordTime(member.Id))); deb.AddField($"Joined {ctx.Guild.Name}:", GetDateString(member.JoinedAt)); await ctx.Channel.SendMessageAsync(embed : deb); } else { await ctx.Channel.SendMessageAsync(ChatObjects.GetErrMessage("User not found!")); } } }
public async Task ExcludeChannel(CommandContext ctx, [Description("Exclude a channel")] DiscordChannel chan) { // Check if the user can use config commands. if (ctx.Member.GetRole().IsBotManagerOrHigher()) { await ctx.Channel.TriggerTypingAsync(); // Cancels: if (BotSettings.IsChannelExcluded(chan)) { // This channel does not exist. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Unable to uexclude channel. This channel is already excluded...")); return; } if (!ctx.Guild.Channels.ContainsKey(chan.Id)) { // This channel is not in the guild. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Unable to exclude channel. This channel does not exist in this server...")); return; } BotSettings.ExcludeChannel(chan); BotSettings.Save(); await ctx.Channel.SendMessageAsync( ChatObjects.GetSuccessMessage( String.Format("{0} was successfully excluded!", chan.Mention))); } }
public async Task SetFilterChannel(CommandContext ctx, [Description("The channel to set the filter logs to.")] DiscordChannel chan) { // Check if the user can use these sorts of commands. if (ctx.Member.GetRole().IsBotManagerOrHigher()) { await ctx.TriggerTypingAsync(); // Cancels: if (BotSettings.FilterChannelId == chan.Id) { // Trying to set the channel to itself. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Unable to set filter channel. That's already the channel...")); return; } if (!ctx.Guild.Channels.ContainsKey(chan.Id)) { // Channel does not exist. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Unable to set filter channel. Does not exist or is not in this guild...")); return; } // Update the settings. BotSettings.FilterChannelId = chan.Id; BotSettings.Save(); // Success message. await ctx.Channel.SendMessageAsync( ChatObjects.GetSuccessMessage( String.Format("Filter channel set to {0}!", chan.Mention))); } }
public async Task RemoveReminder(CommandContext ctx, string reminderId) { if (ctx.Member.GetRole().IsCHOrHigher()) { await ctx.TriggerTypingAsync(); // Cancels: if (!ReminderSystem.IsReminder(reminderId)) { await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"That is not a valid Reminder ID...")); return; } Reminder reminderToRemove = ReminderSystem.GetReminderFromId(reminderId); // DEB! DiscordEmbedBuilder deb = new DiscordEmbedBuilder(); DateTimeOffset dto = DateTimeOffset.FromUnixTimeMilliseconds(reminderToRemove.Time); // The reminder's DTO. TimeSpan remainingTime = dto.Subtract(DateTimeOffset.UtcNow); // The remaining time left for the reminder. string originalAuthorMention = String.Format("<@{0}>", reminderToRemove.User); deb.WithTitle(@"Notification Removed"); deb.AddField(@"User", originalAuthorMention); deb.AddField(@"Time", dto.ToString()); deb.AddField(@"Remaining time", String.Format("{0}day {1}hr {2}min {3}sec", remainingTime.Days, remainingTime.Hours, remainingTime.Minutes, remainingTime.Seconds)); deb.AddField(@"Message", reminderToRemove.Text); deb.AddField(@"Notification Identifier", reminderId); deb.WithColor(DiscordColor.LightGray); deb.WithThumbnailUrl(ChatObjects.URL_REMINDER_DELETED); ReminderSystem.RemoveReminder(reminderToRemove); ReminderSystem.Save(); await ctx.Channel.SendMessageAsync(originalAuthorMention, false, deb); } }
public async Task FilterInclude(CommandContext ctx, string word) { if (ctx.Member.GetRole().IsSeniorModOrHigher()) { await ctx.TriggerTypingAsync(); if (!Excludes.IsExcluded(word)) { await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Cannot un-exclude that word. It's not already excluded...")); } else { Excludes.RemoveWord(word); Excludes.Save(); await ctx.Channel.SendMessageAsync( ChatObjects.GetSuccessMessage(@"I removed that word from exclusion!")); } } }
public async Task AddReminder(CommandContext ctx, params string[] paramsList) { if (ctx.Member.GetRole().IsCHOrHigher()) { string args = ctx.RawArgumentString; int firstQuote = args.IndexOf('['); int secondQuote = args.LastIndexOf(']'); // Let's try to get the date, first of all. string dateSubstring; // If there's no quote, let's just see what happens if we put the whole string in. if (firstQuote == -1) { dateSubstring = args.TrimStart(); } else { dateSubstring = args.TrimStart(' ').Substring(0, firstQuote); } MatchCollection matches = DateRegex.Matches(dateSubstring); DateTimeOffset dto = ctx.Message.CreationTimestamp.UtcDateTime; foreach (Match match in matches) { if (match.Groups.Count == 3) { // Check if it's an integer just in case... if (Int32.TryParse(match.Groups[1].Value, out int measure)) { InterpretTime( measure: measure, unit: match.Groups[2].Value, dto: ref dto); } } } // Cancels: ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! if (dto.UtcTicks == ctx.Message.CreationTimestamp.UtcTicks) { // No time has been added. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"Invalid time string...")); return; } DateTimeOffset yearFromNow = new DateTimeOffset(ctx.Message.CreationTimestamp.UtcDateTime).AddYears(1); if (dto.UtcTicks > yearFromNow.UtcTicks) { // More than a year away. await ctx.Channel.SendMessageAsync( ChatObjects.GetErrMessage(@"That's more than one year away. Please reduce your time...")); return; } // Great, so now we have our time string. Now we need to try and figure out what our message string is. string msgString = @"no message provided"; // Just checking to make sure everything is in bounds. if (firstQuote != -1 && firstQuote + 1 < args.Length && secondQuote - 1 > firstQuote) { if (secondQuote == -1) { msgString = args.Substring(firstQuote + 1); } else { msgString = args.Substring(firstQuote + 1, secondQuote - firstQuote - 1); } } // Now we have our message string. Let's see if there are any mentions. IEnumerable <ulong> mentionIds = from mentionId in ctx.Message.MentionedUsers.Select(a => a.Id).Distinct() where mentionId != 669347771312111619 && // Do not allow mentions of the bot, mentionId != 676710243878830090 && // the dev bot, mentionId != ctx.Message.Author.Id // or the user who called the function. select mentionId; StringBuilder sb = new StringBuilder(); // DEB! DiscordEmbedBuilder deb = new DiscordEmbedBuilder(); Reminder reminder = new Reminder { Text = msgString, Time = dto.ToUnixTimeMilliseconds(), User = ctx.Member.Id, Channel = ctx.Channel.Id, UsersToNotify = mentionIds.ToArray() }; foreach (ulong mentionId in mentionIds) { sb.Append(String.Format("<@{0}> ", mentionId)); } deb.WithTitle(@"Notification"); deb.AddField(@"User", ctx.Member.Mention); deb.AddField(@"Time", dto.ToString()); deb.AddField(@"Message", msgString); if (sb.Length > 0) { deb.AddField(@"Users to notify:", sb.ToString().TrimEnd()); } deb.AddField(@"Notification Identifier", reminder.GetIdentifier()); deb.WithThumbnailUrl(ChatObjects.URL_REMINDER_GENERIC); ReminderSystem.AddReminder(reminder); ReminderSystem.Save(); await ctx.Channel.SendMessageAsync(String.Empty, false, deb); } }