Example #1
0
        public void Handle(SocketUserMessage userMsg)
        {
            string fullMessage = userMsg.Content.ToLower();

            List <string> args = fullMessage.Split(' ').ToList();

            string trigger = args[0];

            var cmd = Triggers.Find(triggerInList => triggerInList == trigger);

            if (string.IsNullOrEmpty(cmd) == false)
            {
                args.RemoveAt(0);

                if (!IsEnabled)
                {
                    userMsg.Channel.SendMessageAsync("This command has been disabled for some reason :thinking:");
                    return;
                }

                if (Cooldown > 0)
                {
                    if (cooldownDictionary.TryGetValue(userMsg.Author.Id, out var lastInvokeTime))
                    {
                        var timeDiff = DateTime.Now - lastInvokeTime;
                        if (timeDiff.TotalSeconds < Cooldown)
                        {
                            userMsg.Channel.SendMessageAsync($"You are on cooldown! **{(Cooldown - timeDiff.TotalSeconds):F2}s** left");
                            return;
                        }
                        else
                        {
                            cooldownDictionary[userMsg.Author.Id] = DateTime.Now;
                        }
                    }
                    else
                    {
                        cooldownDictionary.Add(userMsg.Author.Id, DateTime.Now);
                    }
                }
                onActivate?.Invoke(userMsg, new CommandBuffer(args, trigger));
                CoreModule.TotalCommandsHandled++;
            }
        }
Example #2
0
 internal EventTrigger FindTrigger(int x, int y)
 {
     return(Triggers.Find(t => x >= t.x && x < t.x + t.width && y >= t.y && y < t.y + t.height));
 }