示例#1
0
        public ISRMCommand Help(CmdFlags flags = FlagParameter.Broadcaster, string ShortHelp = "", Regex regexfilter = null)
        {
            this.Flags       = flags;
            this.ShortHelp   = ShortHelp;
            this.Regexfilter = regexfilter ?? _anything;

            return(this);
        }
 private void unloaddeck(ChatUser chatUser, string request, CmdFlags arg3, string arg4)
 {
     if (COMMAND.aliaslist.ContainsKey('!' + request) && deck.ContainsKey(request))
     {
         COMMAND.aliaslist.Remove('!' + request);
         deck.Remove(request);
         QueueChatMessage($"{request} unloaded.");
     }
 }
示例#3
0
        public ParseState Setup(IChatUser user, string request, CmdFlags flags, string info)
        {
            this._user    = user;
            this._request = request;
            this._flags   = flags;
            this._info    = info;

            return(this);
        }
示例#4
0
 public RequestInfo(IChatUser requestor, string request, DateTime requestTime, bool isBeatSaverId, ParseState state, CmdFlags flags = 0, string userstring = "")
 {
     this.requestor     = requestor;
     this.request       = request;
     this.isBeatSaverId = isBeatSaverId;
     this.requestTime   = requestTime;
     this.state         = state;
     this.flags         = flags;
     this.requestInfo   = userstring;
 }
示例#5
0
        public ParseState Setup(ParseState state, string parameter = null)
        {
            // These are references
            this._user   = state._user;
            this._botcmd = state._botcmd;

            this._flags     = state._flags;
            this._parameter = state._parameter;
            if (parameter != null)
            {
                this._parameter = parameter;
            }
            this._subparameter = state._subparameter;
            this._command      = state._command;
            this._info         = state._info;
            this._sort         = state._sort;

            return(this);
        }
 public static bool HasRights(ISRMCommand botcmd, IChatUser user, CmdFlags flags)
 {
     if (flags.HasFlag(CmdFlags.Local))
     {
         return(true);
     }
     if (botcmd.Flags.HasFlag(CmdFlags.Disabled))
     {
         return(false);
     }
     if (botcmd.Flags.HasFlag(CmdFlags.Everyone))
     {
         return(true); // Not sure if this is the best approach actually, not worth thinking about right now
     }
     if (user.IsModerator & RequestBotConfig.Instance.ModFullRights)
     {
         return(true);
     }
     if (user.IsBroadcaster & botcmd.Flags.HasFlag(CmdFlags.Broadcaster))
     {
         return(true);
     }
     if (user.IsModerator & botcmd.Flags.HasFlag(CmdFlags.Mod))
     {
         return(true);
     }
     if (user is TwitchUser twitchUser && twitchUser.IsSubscriber & botcmd.Flags.HasFlag(CmdFlags.Sub))
     {
         return(true);
     }
     if (user is TwitchUser twitchUser1 && twitchUser1.IsVip & botcmd.Flags.HasFlag(CmdFlags.VIP))
     {
         return(true);
     }
     return(false);
 }
示例#7
0
        public void ExecuteCommand()
        {
            if (!this._commandManager.Aliases.TryGetValue(this._command, out this._botcmd))
            {
                return; // Unknown command
            }

            // Permissions for these sub commands will always be by Broadcaster,or the (BUG: Future feature) user list of the EnhancedTwitchBot command. Note command behaviour that alters with permission should treat userlist as an escalation to Broadcaster.
            // Since these are never meant for an end user, they are not going to be configurable.

            // Example: !challenge/allow myfriends
            //          !decklist/setflags SUB
            //          !lookup/sethelp usage: %alias%<song name or id>
            //
            while (true)
            {
                var errormsg = this.ExecuteSubcommand();
                Logger.Debug($"errormsg : {errormsg}");
                if (errormsg == notsubcommand)
                {
                    break;
                }
                if (errormsg != "")
                {
                    if (errormsg == _done)
                    {
                        this._flags |= CmdFlags.Disabled; // Temporarily disable the rest of the command - flags is local parse state flag.
                        continue;
                    }
                    else
                    {
                        this._chatManager.QueueChatMessage(errormsg);
                        //ShowHelpMessage(ref botcmd, ref user, parameter, false);
                    }
                    return;
                }
            }

            if (this._botcmd.ChangedParameters != 0 && !this._botcmd.ChangedParameters.HasFlag(ChangedFlags.Saved))
            {
                this._commandManager.WriteCommandConfiguration();
                this._botcmd.ChangedParameters |= ChangedFlags.Saved;
            }

            if (this._botcmd.Flags.HasFlag(CmdFlags.Disabled) || this._flags.HasFlag(CmdFlags.Disabled))
            {
                return; // Disabled commands fail silently
            }
            // Check permissions first

            var allow = Utility.HasRights(this._botcmd, this._user, this._flags);


            // Num is Nani?
            if (!allow && !this._botcmd.Flags.HasFlag(CmdFlags.BypassRights) && !this._listCollectionManager.Contains(this._botcmd.Permittedusers, this._user.UserName.ToLower()))
            {
                var twitchpermission = this._botcmd.Flags & CmdFlags.TwitchLevel;
                if (!this._botcmd.Flags.HasFlag(CmdFlags.SilentCheck))
                {
                    this._chatManager.QueueChatMessage($"{this._command} is restricted to {twitchpermission.ToString()}");
                }
                return;
            }

            if (this._parameter == "?") // Handle per command help requests - If permitted.
            {
                this._commandManager.ShowHelpMessage(this._botcmd, this._user, this._parameter, true);
                return;
            }

            // Check regex

            if (!this._botcmd.Regexfilter.IsMatch(this._parameter))
            {
                if (!this._botcmd.Flags.HasFlag(CmdFlags.SilentCheck))
                {
                    this._commandManager.ShowHelpMessage(this._botcmd, this._user, this._parameter, false);
                }
                return;
            }

            try {
                var errormsg = this._botcmd.Execute(this); // Call the command
                if (errormsg != "" && !this._flags.HasFlag(CmdFlags.SilentError))
                {
                    this._chatManager.QueueChatMessage(errormsg);
                }
            }
            catch (Exception ex) {
                // Display failure message, and lock out command for a time period. Not yet.
                Logger.Error(ex);
            }
        }