Пример #1
0
        public DicePlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new DiceConfig(config);
            RNG               = new Random();
            CryptoRNG         = new CryptoRandom();
            ChannelToCooldown = new Dictionary <string, CooldownState>();

            ImmutableList <KeyValuePair <string, IArgumentTaker> > cryptoOption =
                CommandUtil.MakeOptions(
                    CommandUtil.MakeFlag("--crypto")
                    )
            ;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("roll"),
                    cryptoOption,
                    CommandUtil.MakeArguments(new MultiMatchTaker(RollRegex, RollSeparatorRegex, 1)),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleRollCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("yn"),
                    cryptoOption,
                    CommandUtil.MakeArguments(RestTaker.Instance),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleYesNoCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("decide"),
                    cryptoOption,
                    CommandUtil.MakeArguments(RestTaker.Instance),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDecideCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("shuffle"),
                    cryptoOption,
                    CommandUtil.MakeArguments(RestTaker.Instance),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleShuffleCommand
                );
            ConnectionManager.ChannelMessage += HandleChannelMessage;
        }
Пример #2
0
        public QuotesPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager         = connMgr;
            Config                    = new QuotesConfig(config);
            PotentialQuotesPerChannel = new Dictionary <string, List <Quote> >();
            LastQuoteIDs              = new Dictionary <string, long>();
            Randomizer                = new Random();

            ConnectionManager.ChannelMessage  += HandleChannelMessage;
            ConnectionManager.ChannelAction   += HandleChannelAction;
            ConnectionManager.BaseNickChanged += HandleBaseNickChanged;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("addquote"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        RestTaker.Instance // quote body
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleAddQuoteCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("remember"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // quote author
                        RestTaker.Instance                                 // search string
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleRememberCommand
                );

            {
                var quoteCommand = new Command(
                    CommandUtil.MakeNames("quote"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--any"),
                        CommandUtil.MakeFlag("--bad"),
                        CommandUtil.MakeFlag("-r")
                        ),
                    CommandUtil.MakeArguments(
                        RestTaker.Instance // search string (optional)
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    );
                ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(quoteCommand, HandleQuoteCommand);
                ConnectionManager.CommandManager.RegisterQueryMessageCommandHandler(quoteCommand, HandleQuoteCommand);
            }

            {
                var quoteUserCommand = new Command(
                    CommandUtil.MakeNames("quoteuser"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--any"),
                        CommandUtil.MakeFlag("--bad"),
                        CommandUtil.MakeFlag("-r")
                        ),
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker // nickname
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    );
                ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                    quoteUserCommand, HandleQuoteUserCommand
                    );
                ConnectionManager.CommandManager.RegisterQueryMessageCommandHandler(
                    quoteUserCommand, HandleQuoteUserCommand
                    );
            }

            {
                var nextQuoteCommand = new Command(
                    CommandUtil.MakeNames("nextquote"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--any"),
                        CommandUtil.MakeFlag("--bad"),
                        CommandUtil.MakeFlag("-r")
                        ),
                    CommandUtil.NoArguments,
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    );
                ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                    nextQuoteCommand, HandleNextQuoteCommand
                    );
                ConnectionManager.CommandManager.RegisterQueryMessageCommandHandler(
                    nextQuoteCommand, HandleNextQuoteCommand
                    );
            }

            {
                var upquoteCommand = new Command(
                    CommandUtil.MakeNames("upquote", "uq"),
                    forbiddenFlags: MessageFlags.UserBanned
                    );
                ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                    upquoteCommand, HandleUpquoteCommand
                    );
                ConnectionManager.CommandManager.RegisterQueryMessageCommandHandler(
                    upquoteCommand, HandleUpquoteCommand
                    );
            }

            {
                var downquoteCommand = new Command(
                    CommandUtil.MakeNames("downquote", "dq"),
                    forbiddenFlags: MessageFlags.UserBanned
                    );
                ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                    downquoteCommand, HandleDownquoteCommand
                    );
                ConnectionManager.CommandManager.RegisterQueryMessageCommandHandler(
                    downquoteCommand, HandleDownquoteCommand
                    );
            }
        }
Пример #3
0
        public ThanksPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new ThanksConfig(config);

            ConnectionManager.BaseNickChanged += HandleBaseNickChanged;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("thank", "thanks", "thx"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--force")
                        ),
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // target
                        RestTaker.Instance                                 // reason
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleThankCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("thanked"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--raw")
                        ),
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker // target
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleThankedCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("grateful"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("--raw")
                        ),
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker // target
                        ),
                    CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleGratefulCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("topthanked"),
                    tags: CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleTopThankedCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("topgrateful"),
                    tags: CommandUtil.MakeTags("fun"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleTopGratefulCommand
                );
        }
Пример #4
0
        public UnoGameMasterPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new GameMasterConfig(config);

            AttackMode           = false;
            ExtremeMode          = false;
            DrawPile             = new Pile <Card>();
            DiscardPile          = new Pile <Card>();
            Players              = new List <Player>();
            CurrentPlayerIndex   = 0;
            PlayerOrderReversed  = false;
            DrewLast             = true;
            CurrentGameState     = GameState.NoGame;
            TurnStartedUtc       = null;
            TurnTickTimer        = new Timer(TurnTickTimerElapsed, null, TimeSpan.Zero, TimeSpan.FromSeconds(1));
            TurnLock             = new object();
            Randomizer           = new Random();
            BotTestCount         = 0;
            BotTestJoinRequested = null;

            ConnectionManager.NickChange      += HandleNickChange;
            ConnectionManager.UserLeftChannel += HandleUserLeftChannel;
            ConnectionManager.UserQuitServer  += HandleUserQuitServer;

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("uno"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeFlag("+a"),
                        CommandUtil.MakeFlag("+e")
                        ),
                    CommandUtil.NoArguments,
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleUnoCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("play", "p"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // color or wildcard value
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker  // value or change-to-color
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandlePlayCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("bottest"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        new LongMatcher().ToRequiredWordTaker() // number of rounds
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleBotTestCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("join", "botjoin"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleJoinCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("leave"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleLeaveCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("deal"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDealCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("draw"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDrawCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("pass"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandlePassCommand
                );
            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("endgame"),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleEndGameCommand
                );
        }
Пример #5
0
        public DemoderationPlugin(IConnectionManager connMgr, JObject config)
        {
            ConnectionManager = connMgr;
            Config            = new DemoderationConfig(config);

            ChannelsMessages = new Dictionary <string, RingBuffer <ChannelMessage> >();
            RegexCache       = new RegexCache();

            ConnectionManager.ChannelMessage += HandleChannelMessage;
            CleanupTimer = new Timer(
                CleanupTimerElapsed, null, TimeSpan.Zero, TimeSpan.FromMinutes(Config.CleanupPeriodMinutes)
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmabuse"),
                    CommandUtil.MakeOptions(
                        CommandUtil.MakeOption("-b", CommandUtil.NonzeroStringMatcherRequiredWordTaker),
                        CommandUtil.MakeOption("--ban-time", CommandUtil.NonzeroStringMatcherRequiredWordTaker),
                        CommandUtil.MakeOption("-c", CommandUtil.NonzeroStringMatcherRequiredWordTaker),
                        CommandUtil.MakeOption("--cooldown-time", CommandUtil.NonzeroStringMatcherRequiredWordTaker)
                        ),
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // nickname
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker  // criterion name
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleAbuseCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmnew"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker, // criterion name
                        RestTaker.Instance                                 // criterion detection regex
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleNewCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmdel"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker // criterion name
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDeleteCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmrestore"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker // criterion name
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleRestoreCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmimmunity"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker,                // nickname
                        new RegexMatcher("(?:[#+&][^ ,:]+|GLOBAL)").ToRequiredWordTaker() // channel or "GLOBAL"
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleImmunityCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmdelimmunity"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker,                // nickname
                        new RegexMatcher("(?:[#+&][^ ,:]+|GLOBAL)").ToRequiredWordTaker() // channel or "GLOBAL"
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleDeleteImmunityCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmpermaban"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker,                // nickname
                        new RegexMatcher("(?:[#+&][^ ,:]+|GLOBAL)").ToRequiredWordTaker() // channel or "GLOBAL"
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandlePermabanCommand
                );

            ConnectionManager.CommandManager.RegisterChannelMessageCommandHandler(
                new Command(
                    CommandUtil.MakeNames("dmunpermaban"),
                    CommandUtil.NoOptions,
                    CommandUtil.MakeArguments(
                        CommandUtil.NonzeroStringMatcherRequiredWordTaker,                // nickname
                        new RegexMatcher("(?:[#+&][^ ,:]+|GLOBAL)").ToRequiredWordTaker() // channel or "GLOBAL"
                        ),
                    forbiddenFlags: MessageFlags.UserBanned
                    ),
                HandleUnPermabanCommand
                );

            UpdateCommandCache();
        }