Ejemplo n.º 1
0
        public static void Execute(string command, EventSourceType sourceType, long?qqNo = null, long?groupNo = null)
        {
            UserInfo qq    = null;
            Group    group = null;

            if (qqNo.HasValue)
            {
                qq = UserManager.Get(qqNo.Value);
            }

            GroupMember member = null;

            if (qqNo.HasValue && groupNo.HasValue)
            {
                member = GroupMemberManager.Get(qqNo.Value, groupNo.Value);
            }

            if (!command.StartsWith(".") && !command.StartsWith("/"))
            {
                if (sourceType == EventSourceType.Group)
                {
                    ExecuteWithoutCommand(command, sourceType, qq, member);
                }
                return;
            }

            var commandStr  = command.Remove(0, 1);
            var commandList = TakeCommandParts(commandStr);

            var commandName = commandList.FirstOrDefault();

            if (commandName == null)
            {
                return;
            }

            var manager = GetManagerByCommand(commandName);

            if (manager == null)
            {
                if (sourceType == EventSourceType.Group)
                {
                    ExecuteWithoutCommand(command, sourceType, qq, member);
                }
                return;
            }

            commandList.RemoveAt(0);
            var args = commandList;

            Task.Run(async() => { await manager.ExecuteAsync(args, sourceType, qq, group, member); });
        }
Ejemplo n.º 2
0
        public override async Task ExecuteAsync(List <string> command, EventSourceType sourceType, UserInfo qq, Group group, GroupMember member)
        {
            var fromQQ  = 0L;
            var toGroup = 0L;
            var message = "";

            if (sourceType == EventSourceType.Private)
            {
                fromQQ = qq.QQ;
                if (command.Count < 2)
                {
                    MessageManager.Send(EventSourceType.Private, "你不说话我怎么知道你想让我帮你说什么0 0", fromQQ);
                    return;
                }

                if (!long.TryParse(command[0], out toGroup))
                {
                    MessageManager.Send(EventSourceType.Private, "小夜看不明白你想把这段话发到哪", fromQQ);
                    return;
                }

                var mem = GroupMemberManager.Get(fromQQ, toGroup);
                message = mem.GroupName + string.Join(" ", command.Skip(1));

                MessageManager.Send(EventSourceType.Group, message, fromQQ, toGroup);
            }
            else if (sourceType == EventSourceType.Group)
            {
                fromQQ  = member.QQ;
                toGroup = member.GroupNumber;
                if (!command.Any())
                {
                    MessageManager.Send(EventSourceType.Group, "你不说话我怎么知道你想让我帮你说什么0 0", fromQQ, toGroup);
                    return;
                }

                message = member.GroupName + string.Join(" ", command);

                MessageManager.Send(EventSourceType.Group, message, fromQQ, toGroup);
            }
        }