예제 #1
0
        internal bool addOP(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/addop", "").Replace(" ", "");

            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /addop UID",
                                                            RawMessage.message_id);

                return(false);
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            jsonObj["op_list"].Add(Convert.ToInt32(UID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);

            RAPI.reloadConfig();

            return(true);
        }
        internal bool addBlockGroup(TgMessage RawMessage)
        {
            string ChatID_Value = RawMessage.text.Replace("/block", "").Replace(" ", "");

            if (ChatID_Value.Length < 10)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /block ChatID",
                                                            RawMessage.message_id);
                return(false);
            }

            if (ChatID_Value.Length == 10 && Convert.ToInt64(ChatID_Value) > 0)
            {
                ChatID_Value = "-100" + ChatID_Value;
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["blockgroup_list"])
            {
                if (jsonObj["blockgroup_list"][i] == ChatID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已經在名單內了!", RawMessage.message_id);
                return(false);
            }

            jsonObj["blockgroup_list"].Add(Convert.ToInt64(ChatID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);
            try
            {
                TgApi.getDefaultApiConnection().sendMessage(Convert.ToInt64(ChatID_Value), "此群組禁止使用本服務。");
                TgApi.getDefaultApiConnection().leaveChat(Convert.ToInt64(ChatID_Value));
            }
            catch
            {
            }

            RAPI.reloadConfig();

            return(true);
        }
        internal bool deleteWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/delwl", "").Replace(" ", "");

            ;
            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /delwl UID",
                                                            RawMessage.message_id);

                return(false);
            }

            if (UID_Value.Length == 10 && Convert.ToInt64(UID_Value) > 0)
            {
                UID_Value = "-100" + UID_Value;
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["whitelist"])
            {
                if (jsonObj["whitelist"][i] == UID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                jsonObj["whitelist"].Remove(jsonObj["whitelist"][i]);
                string output =
                    JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                File.WriteAllText("config.json", output);
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "刪除成功!", RawMessage.message_id);

                RAPI.reloadConfig();
            }
            else
            {
                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.chat.id, "找不到User!", RawMessage.message_id);
            }

            return(true);
        }
        internal bool addHKWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/addhk", "").Replace(" ", "");

            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /addhk UID",
                                                            RawMessage.message_id);
                return(false);
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["hk_whitelist"])
            {
                if (jsonObj["hk_whitelist"][i] == UID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已經在名單內了!", RawMessage.message_id);
                return(false);
            }

            jsonObj["hk_whitelist"].Add(Convert.ToInt64(UID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);

            RAPI.reloadConfig();

            return(true);
        }