Esempio n. 1
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            if (routeMsg.MessageType == MessageType.Private)
            {
                return(null);
            }
            var auth = PermissionCheckerApp.GetActualAuthority(routeMsg, out var fullCommand);

            if (fullCommand == "poweron")
            {
                bool alive = IsMeAlive(routeMsg.CoolQIdentity);
                if (alive)
                {
                    return(routeMsg.ToSource("我还活着呢,你想干什么压"));
                }
                if (auth == Authority.Public)
                {
                    return(routeMsg.ToSource("若想开机,请联系管理员使用此命令").Handle());
                }

                while (IsScanning)
                {
                    Thread.Sleep(10);
                }
                ExpireTimeCollection[routeMsg.CoolQIdentity] = null;
                ExpireTimeCollection.Remove(routeMsg.CoolQIdentity);
                SaveConfig();
                return(routeMsg.ToSource("啊,活过来了"));
            }

            if (routeMsg.RawMessage.Contains("/poweroff") || routeMsg.RawMessage.Contains("黄花菜"))
            {
                bool alive = IsMeAlive(routeMsg.CoolQIdentity);
                if (!alive)
                {
                    return(routeMsg.ToSource("黄花菜当前是关机状态哦,若想开机请联系管理员使用/poweron命令").Handle());
                }
            }

            return(IsMeAlive(routeMsg.CoolQIdentity)
                ? null
                : routeMsg.HandleAndCancel());
        }
Esempio n. 2
0
        public override CoolQRouteMessage OnMessageReceived(CoolQScopeEventArgs scope)
        {
            var routeMsg = scope.RouteMessage;

            if (DisabledList.Keys.Contains((CoolQIdentity)routeMsg.Identity))
            {
                var guidList = DisabledList[(CoolQIdentity)routeMsg.Identity];
                PermissionCheckerApp.GetRequestAuthority(routeMsg.RawMessage, out var fullCommand);
                var cmdName = fullCommand?.Split(' ')[0];
                foreach (var plugin in Bot.Backend.PluginManager.Current.ApplicationInstances)
                {
                    if (!guidList.Contains(plugin.Guid))
                    {
                        continue;
                    }
                    scope.DisabledApplications.Add(plugin);
                }

                if (cmdName == null)
                {
                    return(null);
                }
                Guid?pluginGuid = Bot.Backend.PluginManager.Current.GetPlugin(cmdName)?.Guid;
                if (pluginGuid == null)
                {
                    return(null);
                }
                if (guidList.Contains(pluginGuid.Value))
                {
                    return(routeMsg.MessageType == MessageType.Private
                        ? routeMsg.ToSource("你已禁用此命令.").Handle()
                        : routeMsg.ToSource("本群已禁用此命令.").Handle());
                }
            }

            return(null);
        }