コード例 #1
0
        public static void SendMessage(CommonMessageResponse resp)
        {
            var msg = (resp.EnableAt && resp.MessageType != MessageType.Private ? new At(resp.UserId) + " " : "") +
                      resp.Message;
            var info = SessionInfo[resp.Identity] == null
                ? $"{resp.Identity.Type}{resp.Identity.Id}"
                : SessionInfo[resp.Identity].Name;
            string status;

            switch (resp.MessageType)
            {
            case MessageType.Group:
                status = CqApi.SendGroupMessageAsync(resp.GroupId, msg).Status;
                break;

            case MessageType.Discuss:
                status = CqApi.SendDiscussMessageAsync(resp.DiscussId, msg).Status;
                break;

            case MessageType.Private:
                status = CqApi.SendPrivateMessageAsync(resp.UserId, msg).Status;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Message(string.Format("({0}) 我: {{status: {1}}}\r\n  {2}", info, status, CqCode.DecodeToString(msg)));
        }
コード例 #2
0
        private static void HandleMessageCmd(CommonMessage cm)
        {
            string          fullCmd = cm.FullCommand;
            CommandAnalyzer ca      = new CommandAnalyzer(new ParamDividerV2());

            ca.Analyze(fullCmd, cm);
            CommonMessageResponse replyObj = null;

            if (!PluginManager.CommandMap.ContainsKey(cm.Command))
            {
                return;
            }

            Type t = PluginManager.CommandMap[cm.Command];

            if (ValidateDisabled(cm, t))
            {
                SendMessage(new CommonMessageResponse("本群已禁用此命令...", cm));
                return;
            }

            CommandPlugin plugin = t == typeof(ExtendPlugin) ? PluginManager.CommandMapStatic[cm.Command] : GetInstance(t);

            if (!CommandHot.Keys.Contains(cm.Command))
            {
                CommandHot.TryAdd(cm.Command, 1);
            }
            else
            {
                CommandHot[cm.Command]++;
            }

            Settings.SaveSettings(CommandHot, "CommandHot");
            Task.Run(() =>
            {
                try
                {
                    SetValues(cm, t, plugin);
                    replyObj = plugin.Message_Received(cm);
                }
                catch (Exception ex)
                {
                    Exception(ex, fullCmd, plugin?.Name ?? "Unknown plugin");
                }

                if (replyObj == null)
                {
                    return;
                }
                SendMessage(replyObj);
            }
                     );
        }
コード例 #3
0
ファイル: Food.cs プロジェクト: Gtsz/Daylily
        private bool ValidateCount(string[] album, out CommonMessageResponse response)
        {
            if (album.Length > 1)
            {
                response = new CommonMessageResponse($"包含多个相册:\"{string.Join(',', album)}\"", _cm);
                return(true);
            }

            if (album.Length == 0)
            {
                response = new CommonMessageResponse($"没有找到相册 \"{EnabledAlbumId}\"", _cm);
                return(true);
            }

            response = null;
            return(false);
        }
コード例 #4
0
        private static void HandleMesasgeApp(CommonMessage cm)
        {
            foreach (var item in PluginManager.ApplicationList)
            {
                Type t = item.GetType();
                if (ValidateDisabled(cm, t))
                {
                    continue;
                }

                Task.Run(() =>
                {
                    CommonMessageResponse replyObj = item.Message_Received(cm);
                    if (replyObj != null)
                    {
                        SendMessage(replyObj);
                    }
                });
            }
        }
コード例 #5
0
ファイル: M4MMatch.cs プロジェクト: Gtsz/Daylily
        /// <summary>
        /// 更改摸图偏好会话
        /// </summary>
        private bool SessionMode(out CommonMessageResponse sessionNoMap)
        {
            SendMessage(new CommonMessageResponse("请告诉我你的摸图偏好,可多选。\r\n" +
                                                  "如发送 \"013\" 即指接受std、taiko、mania的地图\r\n" +
                                                  "【0】osu!standard\r\n" +
                                                  "【1】osu!taiko\r\n" +
                                                  "【2】osu!catch\r\n" +
                                                  "【3】osu!mania", _cm));

            if (SessionMultiCondition(out char[] choices, '0', '1', '2', '3'))
            {
                for (int i = 0; i < _myInfo.Preference.Length; i++)
                {
                    _myInfo.Preference[i] = false;
                }

                foreach (var item in choices)
                {
                    _myInfo.Preference[int.Parse(item.ToString())] = true;
                }

                SaveMatchList(); //apply
                SendMessage(new CommonMessageResponse($"你的摸图偏好已更新为:{_myInfo.GetPreferenceString()}", _cm));
            }
コード例 #6
0
 protected static void SendMessage(CommonMessageResponse response) => CoolQDispatcher.SendMessage(response);