public async Task GameCommand(string Action, [Remainder] string Arguments = "") { if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.Games) && Action.ToLower() != "leave") { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to manage or join games!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator.") .SendEmbed(Context.Channel); return; } string Feedback; Player Player = GamesDB.GetOrCreatePlayer(Context.User.Id); GameInstance Game = null; if (Player.Playing > 0) { Game = GamesDB.Games.Find(Player.Playing); if (Game is not null && Game.Type == GameType.Unselected) { Game = null; } } switch (Action.ToLower()) { case "new": case "create": string[] Args = Arguments.Split(" "); if (Args.Length < 2) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Invalid amount of parameters!") .WithDescription("You must at least provide a game type and a title.") .SendEmbed(Context.Channel); return; } string GameTypeStr = Args[0].ToLower(); if (!GameTypeConversion.GameNames.ContainsKey(GameTypeStr)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Game not found!") .WithDescription($"Game \"{GameTypeStr}\" not found! Currently supported games are: {string.Join(", ", Enum.GetNames<GameType>()[1..])}")
/// <summary> /// Manages the modular tasks pertaining to modification of the topic database(s). /// Or alternatively runs the topic command as usual if no reasonable alias or syntax can be leveraged. /// </summary> /// <param name="Command">The entire list of arguments used for the command, stringified.</param> /// <param name="TopicType">What type of topic database should be accessed. Either 'topic' or 'wyr'.</param> /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns> public async Task RunTopic(string Command, TopicType TopicType) { string Name = Regex.Replace(TopicType.ToString(), "([A-Z])([a-z]*)", " $1$2").Substring(1); if (!string.IsNullOrEmpty(Command)) { if (Enum.TryParse(Command.Split(" ")[0].ToLower().Pascalize(), out Enums.ActionType ActionType)) { if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.TopicManagement) && ActionType != Enums.ActionType.Get) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to manage topics!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator") .SendEmbed(Context.Channel); return; } string Topic = Command[(Command.Split(" ")[0].Length + 1)..];
/// <summary> /// The CreateSuggestion method converts the message to a proposal and suggestion object. /// This suggestion object is then sent back to the channel once deleted as a formatted embed for use to vote on. /// </summary> /// <param name="ReceivedMessage">A SocketMessage object, which contains details about the message such as its content and attachments.</param> /// <returns>A <c>Task</c> object, which can be awaited until this method completes successfully.</returns> public async Task CreateSuggestion(SocketMessage ReceivedMessage) { if (RestrictionsDB.IsUserRestricted(ReceivedMessage.Author, Restriction.Suggestions)) { await ReceivedMessage.DeleteAsync(); await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to make suggestions!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator") .SendEmbed(ReceivedMessage.Author, ReceivedMessage.Channel as ITextChannel); return; } // Check to see if the embed message length is more than 1750, else will fail the embed from sending due to character limits. if (ReceivedMessage.Content.Length > 1750) { await ReceivedMessage.DeleteAsync(); await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Your suggestion is too big!") .WithDescription("Please try to summarise your suggestion a little! " + "Keep in mind that emoji add a lot of characters to your suggestion - even if it doesn't seem like it - " + "as Discord handles emoji differently to text, so if you're using a lot of emoji try to cut down on those! <3") .SendEmbed(ReceivedMessage.Author, ReceivedMessage.Channel as ITextChannel); return; } // Remove content from suggestion from people who do not realise that a command is not needed to run the bot. string Content = ReceivedMessage.Content; if (ProposalConfiguration.CommandRemovals.Contains(Content.Split(' ')[0].ToLower())) { Content = Content[(Content.IndexOf(" ") + 1)..];
public async Task ServiceBanCommand(string Action, IUser User, [Remainder] string Restrictions = "") { string[] RestrictionsArray = Restrictions.Trim().Split(" "); Restriction Apply; bool[] Success; List <string> Errored = new(); switch (Action.ToLower()) { case "add": Apply = ParseRestriction(RestrictionsArray, out Success); for (int i = 0; i < Success.Length; i++) { if (!Success[i]) { Errored.Add(RestrictionsArray[i]); } } if (!RestrictionsDB.AddRestriction(User, Apply)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Failure!") .WithDescription($"User {User.GetUserInformation()} already has the following restrictions applied: \n" + $"{Apply}") .AddField(Errored.Count > 0, "Unrecognizable:", string.Join(", ", Errored)) .SendEmbed(Context.Channel); return; } RestrictionsDB.SaveChanges(); await BuildEmbed(EmojiEnum.Love) .WithTitle("Success!") .WithDescription($"User {User.GetUserInformation()} has had the following permissions revoked: \n" + $"{Apply}.") .AddField(Errored.Count > 0, "Unrecognizable:", string.Join(", ", Errored)) .SendEmbed(Context.Channel); return; case "remove": Apply = ParseRestriction(RestrictionsArray, out Success); for (int i = 0; i < Success.Length; i++) { if (!Success[i]) { Errored.Add(RestrictionsArray[i]); } } if (!RestrictionsDB.RemoveRestriction(User, Apply)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Failure!") .WithDescription($"User {User.GetUserInformation()} has none of the following restrictions: \n" + $"{Apply}") .AddField(Errored.Count > 0, "Unrecognizable:", string.Join(", ", Errored)) .SendEmbed(Context.Channel); return; } RestrictionsDB.SaveChanges(); await BuildEmbed(EmojiEnum.Love) .WithTitle("Success!") .WithDescription($"User {User.GetUserInformation()} has had the following restrictions removed: \n" + $"{Apply}.") .AddField(Errored.Count > 0, "Unrecognizable:", string.Join(", ", Errored)) .SendEmbed(Context.Channel); return; case "get": case "fetch": await BuildEmbed(EmojiEnum.Love) .WithTitle($"{User.Username.Possessive()} Restrictions:") .WithDescription(RestrictionsDB.GetUserRestrictions(User).ToString()) .SendEmbed(Context.Channel); return; default: await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Unable to parse action!") .WithDescription($"I wasn't able to parse Action `{Action}`, please use `ADD`, `REMOVE`, or `GET`") .SendEmbed(Context.Channel); return; } }
public async Task SendModMail([Remainder] string Message) { if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.Modmail)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to send modmails!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator") .SendEmbed(Context.Channel); return; } if (Message.Length > 1250) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Your modmail message is too big!") .WithDescription("Please try to summarise your modmail a touch! If you are unable to, try send it in two different messages! " + $"This character count should be under 1250 characters. This is due to how Discord handles embeds and the added information we need to apply to the embed. " + $"The current modmail message character count is {Message.Length}.") .SendEmbed(Context.Channel); return; } string Tracker = CreateToken(); Attachment Attachment = Context.Message.Attachments.FirstOrDefault(); string ProxyURL = string.Empty; if (Attachment != null) { ProxyURL = await Attachment.ProxyUrl.GetProxiedImage(Tracker, DiscordSocketClient, ProposalService.ProposalConfiguration); } IUserMessage UsrMessage = await(DiscordSocketClient.GetChannel(ModerationConfiguration.ModMailChannelID) as ITextChannel).SendMessageAsync( embed: BuildEmbed(EmojiEnum.Unknown) .WithTitle($"Anonymous Modmail #{ModMailDB.ModMail.Count() + 1}") .WithDescription(Message) .WithImageUrl(ProxyURL) .WithCurrentTimestamp() .WithFooter(Tracker) .Build() ); ModMail ModMail = new() { Message = Message, UserID = Context.User.Id, MessageID = UsrMessage.Id, Tracker = Tracker }; ModMailDB.ModMail.Add(ModMail); ModMailDB.SaveChanges(); await BuildEmbed(EmojiEnum.Love) .WithTitle("Successfully Sent Modmail") .WithDescription($"Haiya! Your message has been sent to the staff team.\n\n" + $"Your modmail token is: `{ModMail.Tracker}`, which is what the moderators use to reply to you. " + $"Only give this out to a moderator if you wish to be identified.\n\n" + $"Thank you~! - {DiscordSocketClient.GetGuild(BotConfiguration.GuildID).Name} Staff Team <3") .WithFooter(ModMail.Tracker) .WithCurrentTimestamp() .SendEmbed(Context.Channel); }
public async Task EventCommand(string Action, [Remainder] string Params) { CommunityEvent Event; string EventParam; IGuildUser User = Context.User as IGuildUser; if (Context.Channel is IDMChannel) { User = DiscordSocketClient.GetGuild(BotConfiguration.GuildID).GetUser(Context.User.Id); if (User == null) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Couldn't find you in the server!") .WithDescription($"Are you sure you are in USF? If this continues to fail, consider running this command in <#{BotConfiguration.BotChannels[0]}> instead.") .SendEmbed(Context.Channel); return; } } if (!Enum.TryParse(Action.ToLower().Pascalize(), out Enums.ActionType ActionType)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Action Parse Error!") .WithDescription($"Action \"{Action}\" not found! Please use `ADD`, `GET`, `REMOVE`, or `EDIT`") .SendEmbed(Context.Channel); return; } switch (ActionType) { case Enums.ActionType.Add: if (RestrictionsDB.IsUserRestricted(Context.User, Databases.UserRestrictions.Restriction.Events)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("You aren't permitted to create events!") .WithDescription("You have been blacklisted from using this service. If you think this is a mistake, feel free to personally contact an administrator.") .SendEmbed(Context.Channel); return; } string ReleaseArg = Params.Split(TimeEventSeparator)[0]; if (!LanguageHelper.TryParseTime(ReleaseArg.Trim(), CultureInfo.CurrentCulture, LanguageConfiguration, out DateTimeOffset ReleaseTime, out _)) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Unable to parse time!") .WithDescription($"I was unable to parse the time: `{ReleaseArg}`\n Make sure it follows the correct format! For more info, check out `{BotConfiguration.Prefix}checktime [Your Date]`") .SendEmbed(Context.Channel); return; } if (ReleaseArg.Length + 1 >= Params.Length) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Unable to parse event!") .WithDescription($"I found event parameters: `{Params}`. \nYou must separate time and description with a semicolon ({TimeEventSeparator})!") .SendEmbed(Context.Channel); return; } string Description = Params[(ReleaseArg.Length + TimeEventSeparator.Length)..].Trim();