protected PaginatorBuilder WithDefaultEmotes() { Emotes.Clear(); Emotes.Add(new Emoji("◀"), PaginatorAction.Backward); Emotes.Add(new Emoji("▶"), PaginatorAction.Forward); Emotes.Add(new Emoji("⏮"), PaginatorAction.SkipToStart); Emotes.Add(new Emoji("⏭"), PaginatorAction.SkipToEnd); Emotes.Add(new Emoji("🛑"), PaginatorAction.Exit); return(this); }
/// <summary> /// Constructor /// </summary> /// <param name="container">Dependency injection container</param> public VMEmotes(IContainer container) { Container = container; MessageService = Container.Resolve <IMessageService>(); Emotes.Add(new VMEmote() { Name = "Smile", WorldEmoteType = WorldEmoteType.Smile }); Emotes.Add(new VMEmote() { Name = "Frown", WorldEmoteType = WorldEmoteType.Frown }); }
private void AddEmote(string emoteData, int emoteId, string message, bool single = false) { int startIndex = -1, endIndex = -1; if (single) { startIndex = int.Parse(emoteData.Split(':')[1].Split('-')[0]); endIndex = int.Parse(emoteData.Split(':')[1].Split('-')[1]); } else { startIndex = int.Parse(emoteData.Split('-')[0]); endIndex = int.Parse(emoteData.Split('-')[1]); } Emotes.Add(new Emote(emoteId, message.Substring(startIndex, (endIndex - startIndex) + 1), startIndex, endIndex)); }
public BrimeChatMessage(JToken message) { // Logger.Trace("Loading Chat Message: " + message); string?__notice = message.Value <string>("__notice"); if (!string.IsNullOrWhiteSpace(__notice)) { Logger.Info("Notice: " + __notice); } string?curr = message.Value <string>("channelID"); ChannelID = (curr == null) ? "" : curr; curr = message.Value <string>("_id"); ID = (curr == null) ? "" : curr; curr = message.Value <string>("message"); Message = (curr == null) ? "" : curr; JToken?sender = message["sender"]; Sender = (sender == null) ? new BrimeUser() : new BrimeUser(sender); JToken?emotes = message["emotes"]; if (emotes != null) { foreach (JToken item in emotes) { if (item != null) { JProperty?prop = item.ToObject <JProperty>(); if (prop != null) { string name = prop.Name; string?id = prop.Value.Value <string>("_id"); if (id != null) { Emotes.Add(name, new BrimeChatEmote(id)); } } } } } Timestamp = message.Value <DateTime>("timestamp"); }
public EmoteSet(JSON.EmoteSet emoteSet) { Category = (EmoteCategory)emoteSet.category; Probability = emoteSet.probability; VendorType = (VendorType?)emoteSet.vendorType; Quest = emoteSet.quest; WeenieClassId = emoteSet.classID; Style = (MotionStance?)emoteSet.style; Substyle = (MotionCommand?)emoteSet.substyle; MinHealth = emoteSet.minhealth; MaxHealth = emoteSet.maxhealth; foreach (var emote in emoteSet.emotes) { Emotes.Add(new Emote(emote)); } }
public static void LoadGlobal() { using (var db = new Database()) { Channels.Clear(); FullChannels.Clear(); if (db.Channels.Any()) { var channelObjects = db.Channels.Include(ch => ch.GroupsChannelIsIn).ThenInclude(groupMembers => groupMembers.Group); foreach (var groupMember in channelObjects) { Channels.Add(groupMember.Name, groupMember.ChannelID); FullChannels.Add(groupMember); } } PostTargets.Clear(); foreach (var target in db.PostTargets) { PostTargets.Add(target.Name, target.ChannelId); } Roles.Clear(); if (db.Roles.Any()) { foreach (var role in db.Roles) { Roles.Add(role.Name, role.RoleID); } } ServerID = db.PersistentData .First(x => x.Name == "server_id") .Value; InfoRoleManagerMessageId = db.PersistentData .First(x => x.Name == "rolemanager_message_id") .Value; StarboardStars = db.PersistentData .First(entry => entry.Name == "starboard_stars") .Value; Level2Stars = db.PersistentData .First(entry => entry.Name == "level_2_stars") .Value; Level3Stars = db.PersistentData .First(entry => entry.Name == "level_3_stars") .Value; Level4Stars = db.PersistentData .First(entry => entry.Name == "level_4_stars") .Value; DecayDays = db.PersistentData .First(entry => entry.Name == "decay_days") .Value; IllegalUserNameRegex = new Regex(db.PersistentData .First(entry => entry.Name == "illegal_user_name_regex") .StringValue, RegexOptions.Singleline | RegexOptions.Compiled); XPGainDisabled = db.PersistentData .First(entry => entry.Name == "xp_disabled") .Value == 1; InviteLinks.Clear(); foreach (var link in db.InviteLinks) { InviteLinks.Add(link); } ModmailCategoryId = db.PersistentData .First(entry => entry.Name == "modmail_category_id") .Value; XPGainRangeMin = (int)db.PersistentData .First(entry => entry.Name == "xp_gain_range_min") .Value; XPGainRangeMax = (int)db.PersistentData .First(entry => entry.Name == "xp_gain_range_max") .Value; Emotes.Clear(); if (db.Emotes.Any()) { foreach (var post in db.Emotes) { Emotes.Add(post.Key, post); } } StarboardPosts.Clear(); if (db.StarboardMessages.Any()) { foreach (var post in db.StarboardMessages) { StarboardPosts.Add(post); } } ProfanityChecks.Clear(); if (db.ProfanityChecks.Any()) { foreach (var word in db.ProfanityChecks) { word.RegexObj = new Regex(word.Word, RegexOptions.Singleline | RegexOptions.Compiled); ProfanityChecks.Add(word); } } var ReadChannels = db.FAQCommandChannels .Include(faqComand => faqComand.Command) .Include(faqComand => faqComand.ChannelGroupReference) .Include(faqComand => faqComand.CommandChannelEntries) .OrderBy(command => command.Command.ID) .ToList(); FAQCommands.Clear(); FAQCommandChannels.Clear(); FAQCommandChannels = ReadChannels; FAQCommands = db.FAQCommands.ToList(); Commands = db.Commands .Include(co => co.GroupsCommandIsIn).ThenInclude(grp => grp.ChannelGroupReference).ThenInclude(ch => ch.Channels) .ToList(); } ReloadModmailThreads(); }
protected PaginatorBuilder AddEmote(PaginatorAction action, IEmote emote) { Emotes.Add(emote, action); return(this); }
/// <summary> /// Creates a HTML version of the message text. /// </summary> private void Humanise() { DiscordMessage message = this.OriginalMessage; string humanised = message.Content; this.SenderDisplayName = (message.Author as DiscordMember).DisplayName; this.SenderAvatarUrl = message.Author.AvatarUrl; this.Emotes = new List <RemoteEmote>(); this.Channels = new List <RemoteChannel>(); this.Users = new List <RemoteUser>(); this.Roles = new List <RemoteRole>(); // Mapping mention to names // Mention string is key, name with symbol (@, #) is value Dictionary <string, string> MentionNamePairs = new Dictionary <string, string>(); foreach (DiscordChannel channel in message.MentionedChannels) { MentionNamePairs.Add(channel.Mention, "#" + channel.Name); Channels.Add(new RemoteChannel { HumanName = "#" + channel.Name, DiscordChannel = channel }); } foreach (DiscordUser user in message.MentionedUsers) { if (user is DiscordMember mentionedMember) { MentionNamePairs.Add(user.Mention, "@" + mentionedMember.DisplayName); Users.Add(new RemoteUser { HumanName = "@" + mentionedMember.DisplayName, DiscordUser = user }); } else { MentionNamePairs.Add(user.Mention, $"@invalid user ({user.Username}#{user.Discriminator})"); Users.Add(new RemoteUser { HumanName = $"@invalid user ({user.Username}#{user.Discriminator})", DiscordUser = user }); } } foreach (DiscordRole role in message.MentionedRoles) { MentionNamePairs.Add(role.Mention, "@" + role.Name); Roles.Add(new RemoteRole { HumanName = "@" + role.Name, DiscordRole = role }); } foreach (KeyValuePair <string, string> mentionMap in MentionNamePairs) { humanised = humanised.Replace(mentionMap.Key, mentionMap.Value); humanised = humanised.Replace(mentionMap.Key.Replace("!", ""), mentionMap.Value); } // Sanitise HTML before adding emotes. // Emoji are passed as normal Unicode characters. humanised = SanitiseHtml(humanised); // Matches emote names and IDs, names (without colons) are group 1 ("Name"), IDs are group 2 ("Id") // Original Regex: @"<a?:(?<Name>[a-zA-Z0-9_~]+):(?<Id>\d+)>" MatchCollection emotes = Regex.Matches(humanised, @"<a?:(?<Name>[a-zA-Z0-9_~]+):(?<Id>\d+)>"); foreach (Match emote in emotes) { RemoteEmote remoteEmote = new RemoteEmote { HumanName = emote.Groups["Name"].Value, Id = ulong.Parse(emote.Groups["Id"].Value) }; Emotes.Add(remoteEmote); humanised = humanised.Replace(emote.Value, $"<img class=\"emote\" src=\"{remoteEmote.Url}\" alt=\":{remoteEmote.HumanName}:\" />"); } if (message.Attachments.Count != 0) { foreach (DiscordAttachment attachment in message.Attachments) { if (attachment.Height != 0 && !attachment.FileName.EndsWith("mp4") && !attachment.FileName.EndsWith("webm")) { humanised = humanised.Insert(0, $"<img class=\"discordAttachment\" src=\"{attachment.Url}\" alt=\"Message attachment\" height=\"{attachment.Height}\" width=\"{attachment.Width}\"> <br>"); } else { humanised = $"(attachment posted) <br> {humanised}"; } } } if (message.Embeds.Count > 0) { if (!string.IsNullOrWhiteSpace(humanised)) { humanised = $"{humanised} <br> "; } humanised = humanised + ConvertEmbeds(message); } // Parse Markdown text humanised = Markdown.ToHtml(humanised, MarkdownPipeline); this._HumanText = humanised; }
/// <summary> /// Default constructor /// </summary> /// <param name="_server"></param> public EmoteModule(VirtualServer _server) : base(_server, "emote") { Emotes = PersistantDict <ulong, EmoteStats> .load(_server, "EmoteStats.xml"); // Get the last reset date var res = server.FileSetup(_resetDateFile); if (res.Count > 0) { LastResetDate = res[0]; } else { _lastResetDate = new DateTimeOffset(DateTime.Now).ToString(); server.fileCommand(_resetDateFile, x => System.IO.File.WriteAllText(x, LastResetDate)); } Action <Emote> f = (emote) => { // Create a new entry if it doesn't have one if (!Emotes.ContainsKey(emote.Id)) { Emotes.Add(emote.Id, new EmoteStats() { Counter = 0, LastPosted = new DateTimeOffset(DateTime.Now).ToString(), Name = emote.Name }); } // Increment the counter Emotes[emote.Id].Counter++; Emotes[emote.Id].LastPosted = new DateTimeOffset(DateTime.Now).ToString(); Emotes.persist(); }; // Listen to all incoming messages from the server server.MessageRecieved += (s, e) => { if (!on) { return; } List <Emote> usedEmotes = new List <Emote>(); if (!e.Author.IsBot && e.msg.Tags.Any((t) => t.Type == TagType.Emoji && server.getServer().Emotes.Contains(t.Value))) { lock (_lock) { // Go over all the server emotes that weren't already posted foreach (var tag in e.msg.Tags.Where(t => t.Type == TagType.Emoji && server.getServer().Emotes.Contains(t.Value) && !usedEmotes.Contains(t.Value))) { // Add it to the previously posted list Emote emote = tag.Value as Emote; usedEmotes.Add(emote); if (emote != null) { f(emote); } } } } }; // Count for reactions server.ReactionAdded += (s, reaction) => { if (!on) { return; } // If a real user reacted wit ha server emote if (!reaction.User.Value.IsBot && server.getServer().Emotes.Contains(reaction.Emote)) { Emote emote = reaction.Emote as Emote; if (emote != null) { lock (_lock) { f(emote); } } } }; server.ReactionRemoved += (s, reaction) => { if (!on) { return; } // If a real user removed their server emote reaction if (!reaction.User.Value.IsBot && server.getServer().Emotes.Contains(reaction.Emote)) { Emote emote = reaction.Emote as Emote; if (emote != null) { lock (_lock) { // Decrement the counter if (Emotes.ContainsKey(emote.Id)) { Emotes[emote.Id].Counter--; Emotes.persist(); } } } } }; }
public void Add(Emote emote) { Emotes.Add(emote); }
public static void LoadGlobal() { using (var db = new Database()) { Channels.Clear(); FullChannels.Clear(); if (db.Channels.Any()) { var channelObjects = db.Channels.Include(ch => ch.GroupsChannelIsIn).ThenInclude(groupMembers => groupMembers.Group).ToList(); foreach (var groupMember in channelObjects) { Channels.Add(groupMember.Name, groupMember.ChannelID); FullChannels.Add(groupMember); } } PostTargets.Clear(); foreach (var target in db.PostTargets.ToList()) { PostTargets.Add(target.Name, target.ChannelId); } Roles.Clear(); if (db.Roles.Any()) { foreach (var role in db.Roles.ToList()) { Roles.Add(role.Name, role.RoleID); } } ServerID = PersistentData.GetConfiguredInt("server_id", db); InfoRoleMessageIds = new List <ulong>(); InfoRoleMessageIds.Add(PersistentData.GetConfiguredInt("rolemanager_message_id", db)); InfoRoleMessageIds.Add(PersistentData.GetConfiguredInt("rolemanager_message_id_2", db)); AutoMuteMaxLevel = PersistentData.GetConfiguredInt("auto_mute_max_level", db); AutoMutePingCount = PersistentData.GetConfiguredInt("auto_mute_ping_count", db); StarboardStars = PersistentData.GetConfiguredInt("starboard_stars", db); Level2Stars = PersistentData.GetConfiguredInt("level_2_stars", db); Level3Stars = PersistentData.GetConfiguredInt("level_3_stars", db); ModModeRoleId = PersistentData.GetConfiguredInt("mod_mode_role_id", db); ModModeRoleColor = Convert.ToUInt32(PersistentData.GetConfiguredString("mod_mode_role_color", db), 16); Level4Stars = PersistentData.GetConfiguredInt("level_4_stars", db); DecayDays = PersistentData.GetConfiguredInt("decay_days", db); LegalUserNameRegex = new Regex(PersistentData.GetConfiguredString("legal_user_name_regex", db), RegexOptions.Singleline | RegexOptions.Compiled); XPGainDisabled = PersistentData.GetConfiguredInt("xp_disabled", db) == 1; ProfanityVoteThreshold = (int)PersistentData.GetConfiguredInt("profanity_votes_threshold", db); InviteLinks.Clear(); foreach (var link in db.InviteLinks.ToList()) { InviteLinks.Add(link); } ModmailCategoryId = PersistentData.GetConfiguredInt("modmail_category_id", db); XPGainRangeMin = (int)PersistentData.GetConfiguredInt("xp_gain_range_min", db); XPGainRangeMax = (int)PersistentData.GetConfiguredInt("xp_gain_range_max", db); FilteredUdWords.Clear(); FilteredUdWords.AddRange(db.FilteredUDWords); Emotes.Clear(); if (db.Emotes.Any()) { foreach (var post in db.Emotes.ToList()) { Emotes.Add(post.Key, post); } } TrackedEmotes.Clear(); if (db.Emotes.Any()) { foreach (var post in db.Emotes.AsQueryable().Where(e => !e.TrackingDisabled).ToList()) { TrackedEmotes.Add(post.Key, post); } } FeatureFlags.Clear(); if (db.FeatureFlags.Any()) { foreach (var featureFlag in db.FeatureFlags.AsQueryable().ToList()) { FeatureFlags.Add(featureFlag.FeatureName, featureFlag); } } StarboardPosts.Clear(); if (db.StarboardMessages.Any()) { foreach (var post in db.StarboardMessages.ToList()) { StarboardPosts.Add(post); } } Categories.Clear(); if (db.Categories.Any()) { foreach (var category in db.Categories.ToList()) { Categories.Add(category); } } ProfanityChecks.Clear(); if (db.ProfanityChecks.Any()) { foreach (var word in db.ProfanityChecks.ToList()) { word.RegexObj = new Regex(word.Word, RegexOptions.Singleline | RegexOptions.Compiled); ProfanityChecks.Add(word); } } var ReadChannels = db.FAQCommandChannels .Include(faqComand => faqComand.Command) .Include(faqComand => faqComand.ChannelGroupReference) .Include(faqComand => faqComand.CommandChannelEntries) .OrderBy(command => command.Command.ID) .ToList(); FAQCommands.Clear(); FAQCommandChannels.Clear(); FAQCommandChannels = ReadChannels; FAQCommands = db.FAQCommands.ToList(); Commands = db.Commands .Include(co => co.GroupsCommandIsIn).ThenInclude(grp => grp.ChannelGroupReference).ThenInclude(ch => ch.Channels) .ToList(); } ReloadModmailThreads(); }