Exemplo n.º 1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="_server"></param>
        public StrikeModule(VirtualServer _server) : base(_server, "strike")
        {
            UserStrikes = PersistantDict <ulong, List <StrikeDetails> > .load(_server, "UserStrikes.xml");

            // Get the strike channel to print admin alerts in
            var res = server.FileSetup(_channelFile);

            if (res.Count > 0)
            {
                StrikeChannel = server.getServer().TextChannels.FirstOrDefault(x => x.Name == res[0]);
            }
            var time = server.FileSetup(daysTillAutoresolveFile);

            if (time.Count == 1 && UInt32.TryParse(time[0], out daysTillAutoresolve))
            {
                cleanupStrikes();
            }
            else
            {
                daysTillAutoresolve = 0;
            }
        }
Exemplo n.º 2
0
        /// <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();
                            }
                        }
                    }
                }
            };
        }