Exemple #1
0
        protected virtual void HandleChannelMessage(object sender, IChannelMessageEventArgs args, MessageFlags flags)
        {
            if (Config.CooldownUpperBoundary < 0)
            {
                // the cooldown feature is not being used
                return;
            }

            CooldownState cdState;

            if (!ChannelToCooldown.TryGetValue(args.Channel, out cdState))
            {
                cdState = new CooldownState();
                ChannelToCooldown[args.Channel] = cdState;
            }

            if (cdState.CooldownValue > 0)
            {
                --cdState.CooldownValue;
                if (cdState.CooldownValue == 0)
                {
                    cdState.CooldownTriggered = false;
                }
            }
        }
Exemple #2
0
        protected virtual bool CheckAndHandleCooldown(CommandMatch cmd, IChannelMessageEventArgs args)
        {
            if (Config.CooldownUpperBoundary < 0)
            {
                // the cooldown feature is not being used
                return(false);
            }

            CooldownState cdState;

            if (!ChannelToCooldown.TryGetValue(args.Channel, out cdState))
            {
                cdState = new CooldownState();
                ChannelToCooldown[args.Channel] = cdState;
            }

            cdState.CooldownValue += Config.CooldownPerCommandUsage;

            bool coolingDown = (cdState.CooldownTriggered)
                ? (cdState.CooldownValue > 0)
                : (cdState.CooldownValue > Config.CooldownUpperBoundary);

            if (coolingDown)
            {
                cdState.CooldownTriggered = true;
                string cdAnswer = Config.CooldownAnswers[ChosenRNG(cmd).Next(Config.CooldownAnswers.Count)];
                ConnectionManager.SendChannelMessageFormat(args.Channel, "{0}: {1}", args.SenderNickname, cdAnswer);
                return(true);
            }

            return(false);
        }