internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/ban [i|id=1] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" +
                    " r|reason=\"asdfsadf asdfadsf\"\n\n" +
                    "m: 分钟, h: 小时, d: 天\n" +
                    "from 选项仅在 id 未被定义时起作用\n" +
                    "ID 选择优先级: 手动输入的 ID > 回复的被转发消息 > 回复的消息\n" +
                    "选项优先级: 简写 > 全名\n" +
                    "halal 选项只能单独使用,不能与其他选项共同使用,并且需要回复一条消息,否则将会触发异常。\n\n" +
                    "Example:\n" +
                    "/ban id=1 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/ban halal\n" +
                    "/ban halal=reply",
                    RawMessage.message_id
                    );
                return(true);
            }
            int      BanUserId   = 0;
            long     ExpiresTime = 0;
            int      Level       = 0;
            string   Reason      = "";
            UserInfo BanUserInfo = null;
            string   value       = RawMessage.text.Substring(banSpace + 1);
            int      valLen      = value.Length;
            bool     NotHalal    = true;

            if (valLen >= 5)
            {
                if (value.Substring(0, 5) == "halal")
                {
                    NotHalal = false;
                    Reason   = "Halal (中国人无法识别的语言)";
                    if (valLen > 6)
                    {
                        if (value[5] != ' ')
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                RawMessage.GetMessageChatInfo().id,
                                "您的输入有误,请检查您的输入,或使用 /ban 查看帮助。 err_a1",
                                RawMessage.message_id
                                );
                            return(true);
                        }
                        UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string> {
                            { "from", value.Substring(6) }
                        }, RawMessage);
                        if (tmpUinfo == null)
                        {
                            return(true);                  // 如果没拿到用户信息则代表出现了异常
                        }
                        else
                        {
                            BanUserId = tmpUinfo.id;
                            if (tmpUinfo.language_code != null && tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                            {
                                BanUserInfo = tmpUinfo;
                            }
                        }
                    }
                    else
                    {
                        UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string> {
                        }, RawMessage);
                        if (tmpUinfo == null)
                        {
                            return(true);                  // 如果没拿到用户信息则代表出现了异常
                        }
                        else
                        {
                            BanUserId = tmpUinfo.id;
                            if (tmpUinfo.language_code != null)
                            {
                                if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                                {
                                    BanUserInfo = tmpUinfo;
                                }
                            }
                            else
                            {
                                BanUserInfo = tmpUinfo;
                            }
                        }
                    }
                }
            }
            if (NotHalal)
            {
                try
                {
                    Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value);
                    string tmpString = "";

                    // 获取用户信息
                    UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage);
                    if (tmpUinfo == null)
                    {
                        return(true);                  // 如果没拿到用户信息则代表出现了异常
                    }
                    else
                    {
                        BanUserId = tmpUinfo.id;
                        if (tmpUinfo.language_code != null)
                        {
                            if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                            {
                                BanUserInfo = tmpUinfo;
                            }
                        }
                        else
                        {
                            BanUserInfo = tmpUinfo;
                        }
                    }

                    // 获取 ExpiresTime
                    long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage);
                    if (tmpExpiresTime == -1)
                    {
                        return(true);                      // 如果过期时间是 -1 则代表出现了异常
                    }
                    else
                    {
                        ExpiresTime = tmpExpiresTime;
                    }

                    // 获取 Level
                    tmpString = banValues.GetValueOrDefault("l", "__invalid__");
                    if (tmpString == "__invalid__")
                    {
                        tmpString = banValues.GetValueOrDefault("level", "0");
                    }
                    if (!int.TryParse(tmpString, out Level))
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            "您的输入有误,请检查您的输入,或使用 /ban 查看帮助。 err8",
                            RawMessage.message_id
                            );
                        return(true);
                    }

                    // 获取 Reason
                    Reason = new GetValues().GetReason(banValues, RawMessage);
                    if (Reason == null)
                    {
                        return(true);                // 如果 Reason 是 null 则代表出现了异常
                    }
                    if (Reason.ToLower() == "halal")
                    {
                        Reason = "Halal (中国人无法识别的语言)";
                    }
                }
                catch (DecodeException)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "您的输入有误,请检查您的输入,请使用 /ban 来查看帮助 err10",
                        RawMessage.message_id
                        );
                    return(true);
                }
            }
            bool status;

            if (BanUserInfo == null)
            {
                status = Temp.GetDatabaseManager().BanUser(
                    RawMessage.GetSendUser().id,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason
                    );
            }
            else
            {
                status = Temp.GetDatabaseManager().BanUser(
                    RawMessage.GetSendUser().id,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason,
                    RawMessage.GetMessageChatInfo().id,
                    RawMessage.GetReplyMessage().message_id,
                    BanUserInfo
                    );
            }
            if (status)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作成功。",
                    RawMessage.message_id
                    );
                return(true);
            }
            else
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作成功。\n\n请注意:转发用户消息到频道或发送用户信息到频道失败,请您手动发送至 @" + Temp.MainChannelName + " 。 err11",
                    RawMessage.message_id
                    );
                return(true);
            }
            //return false;
        }
Esempio n. 2
0
        internal bool BanMulti(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/suban [i|id=1,2,3] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" +
                    " r|reason=\"asdfsadf asdfadsf\"\n\n" +
                    "m: 分鐘, h: 小時, d: 天\n" +
                    "from 選項僅在 id 未被定義時起作用\n" +
                    "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" +
                    "選項優先度: 簡寫 > 全名\n" +
                    "halal 選項只能單獨使用,不能與其他選項共同使用,並且需要回覆一則訊息,否則將觸發異常。\n\n" +
                    "Example:\n" +
                    "/suban id=1,2,3 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/suban halal\n" +
                    "/suban halal=reply",
                    RawMessage.message_id
                    );
                return(true);
            }

            int BanUserId = 0;

            int[]  UsersArray  = { };
            long   ExpiresTime = 0;
            int    Level       = 0;
            string Reason      = "";
            string value       = RawMessage.text.Substring(banSpace + 1);
            int    valLen      = value.Length;
            bool   NotHalal    = true;
            bool   status      = false;

            if (valLen >= 5)
            {
                if (value.Substring(0, 5) == "halal")
                {
                    NotHalal = false;
                    Reason   = "無法理解的語言";
                    if (valLen > 6)
                    {
                        if (value[5] != ' ')
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                RawMessage.GetMessageChatInfo().id,
                                "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助。 err_a1",
                                RawMessage.message_id
                                );
                            return(true);
                        }

                        UsersArray =
                            new GetValues().GetUserIDs(new Dictionary <string, string> {
                            { "from", value.Substring(6) }
                        },
                                                       RawMessage);
                    }
                    else
                    {
                        UsersArray = new GetValues().GetUserIDs(new Dictionary <string, string>(), RawMessage);
                    }
                }
            }

            if (NotHalal)
            {
                try
                {
                    Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value);
                    string tmpString = "";

                    // 获取使用者
                    UsersArray = new GetValues().GetUserIDs(banValues, RawMessage);

                    // 获取 ExpiresTime
                    long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage);
                    if (tmpExpiresTime == -1)
                    {
                        return(true);                      // 如果过期时间是 -1 则代表出现了异常
                    }
                    ExpiresTime = tmpExpiresTime;

                    // 获取 Level
                    tmpString = banValues.GetValueOrDefault("l", "__invalid__");
                    if (tmpString == "__invalid__")
                    {
                        tmpString = banValues.GetValueOrDefault("level", "0");
                    }
                    if (!int.TryParse(tmpString, out Level))
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助。 err8",
                            RawMessage.message_id
                            );
                        return(true);
                    }

                    // 获取 Reason
                    Reason = new GetValues().GetReason(banValues, RawMessage);
                    if (Reason == null)
                    {
                        return(true);                // 如果 Reason 是 null 则代表出现了异常
                    }
                    if (Reason.ToLower() == "halal")
                    {
                        Reason = "無法理解的語言";
                    }
                }
                catch (DecodeException)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助 err10",
                        RawMessage.message_id
                        );
                    return(true);
                }
            }

            new Thread(delegate()
            {
                foreach (int userid in UsersArray)
                {
                    BanUserId = userid;
                    status    = Temp.GetDatabaseManager().BanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        Level,
                        ExpiresTime,
                        Reason
                        );
                    if (RAPI.getIsInWhitelist(BanUserId))
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetSendUser().id,
                            "操作失敗 : 使用者在白名單 UID" + BanUserId,
                            RawMessage.message_id
                            );
                    }
                    Thread.Sleep(3500);
                }

                //if (status)
                //{
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作成功。",
                    RawMessage.message_id
                    );
                //}
                //else
                //{
                //    TgApi.getDefaultApiConnection().sendMessage(
                //        RawMessage.GetMessageChatInfo().id,
                //        "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11",
                //        RawMessage.message_id
                //        );
                //    return true;
                //}
                //return false;
            }).Start();
            return(true);
        }
        internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/cnban [i|id=1] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" +
                    " r|reason=\"asdfsadf asdfadsf\"\n\n" +
                    "m: 分鐘, h: 小時, d: 天\n" +
                    "from 選項僅在 id 未被定義時起作用\n" +
                    "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" +
                    "選項優先度: 簡寫 > 全名\n" +
                    "halal 選項只能單獨使用,不能與其他選項共同使用,並且需要回覆一則訊息,否則將觸發異常。\n\n" +
                    "Example:\n" +
                    "/cnban id=1 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/cnban halal\n" +
                    "/cnban halal=reply",
                    RawMessage.message_id
                    );
                return(true);
            }

            int      BanUserId   = 0;
            long     ExpiresTime = 0;
            int      Level       = 0;
            string   Reason      = "";
            UserInfo BanUserInfo = null;
            string   value       = RawMessage.text.Substring(banSpace + 1);
            int      valLen      = value.Length;
            bool     NotHalal    = true;

            if (valLen >= 5)
            {
                if (value.Substring(0, 5) == "halal")
                {
                    NotHalal = false;
                    Reason   = "無法理解的語言";
                    if (valLen > 6)
                    {
                        if (value[5] != ' ')
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                RawMessage.GetMessageChatInfo().id,
                                "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助。 err_a1",
                                RawMessage.message_id
                                );
                            return(true);
                        }

                        UserInfo tmpUinfo =
                            new GetValues().GetByTgMessage(
                                new Dictionary <string, string> {
                            { "from", value.Substring(6) }
                        }, RawMessage);
                        if (tmpUinfo == null)
                        {
                            return(true);                  // 如果没拿到使用者信息则代表出现了异常
                        }
                        BanUserId = tmpUinfo.id;
                        if (tmpUinfo.language_code != null && tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                        {
                            BanUserInfo = tmpUinfo;
                        }
                    }
                    else
                    {
                        UserInfo tmpUinfo =
                            new GetValues().GetByTgMessage(new Dictionary <string, string>(), RawMessage);
                        if (tmpUinfo == null)
                        {
                            return(true);                  // 如果没拿到使用者信息则代表出现了异常
                        }
                        BanUserId = tmpUinfo.id;
                        if (tmpUinfo.language_code != null)
                        {
                            if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                            {
                                BanUserInfo = tmpUinfo;
                            }
                        }
                        else
                        {
                            BanUserInfo = tmpUinfo;
                        }
                    }
                }
            }

            if (NotHalal)
            {
                try
                {
                    Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value);
                    string tmpString = "";

                    // 获取使用者信息
                    UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage);
                    if (tmpUinfo == null)
                    {
                        return(true);                  // 如果没拿到使用者信息则代表出现了异常
                    }
                    BanUserId = tmpUinfo.id;
                    if (tmpUinfo.language_code != null)
                    {
                        if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__")
                        {
                            BanUserInfo = tmpUinfo;
                        }
                    }
                    else
                    {
                        BanUserInfo = tmpUinfo;
                    }

                    // 获取 ExpiresTime
                    long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage);
                    if (tmpExpiresTime == -1)
                    {
                        return(true);                      // 如果过期时间是 -1 则代表出现了异常
                    }
                    ExpiresTime = tmpExpiresTime;

                    // 获取 Level
                    tmpString = banValues.GetValueOrDefault("l", "__invalid__");
                    if (tmpString == "__invalid__")
                    {
                        tmpString = banValues.GetValueOrDefault("level", "0");
                    }
                    if (!int.TryParse(tmpString, out Level))
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助。 err8",
                            RawMessage.message_id
                            );
                        return(true);
                    }

                    // 获取 Reason
                    Reason = new GetValues().GetReason(banValues, RawMessage);
                    if (Reason == null)
                    {
                        return(true);                // 如果 Reason 是 null 则代表出现了异常
                    }
                    if (Reason.ToLower() == "halal")
                    {
                        Reason = "無法理解的語言";
                    }
                }
                catch (DecodeException)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助 err10",
                        RawMessage.message_id
                        );
                    return(true);
                }
            }

            if (RAPI.getIsInWhitelist(BanUserId))
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作失敗 : 使用者在白名單",
                    RawMessage.message_id
                    );
                return(false);
            }

            bool status;

            if (RawMessage.GetMessageChatInfo().id == Temp.InternGroupID && RawMessage.GetReplyMessage().GetSendUser().id == TgApi.getDefaultApiConnection().getMe().id)
            {
                status = Temp.GetDatabaseManager().BanUser(
                    1,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason,
                    RawMessage.GetMessageChatInfo().id,
                    RawMessage.GetReplyMessage().message_id,
                    BanUserInfo
                    );
            }
            else if (BanUserInfo == null)
            {
                status = Temp.GetDatabaseManager().BanUser(
                    RawMessage.GetSendUser().id,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason
                    );
            }
            else if (RawMessage.GetReplyMessage().new_chat_member != null)
            {
                status = Temp.GetDatabaseManager().BanUser(
                    RawMessage.GetSendUser().id,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason,
                    0,
                    0,
                    BanUserInfo
                    );
            }
            else
            {
                status = Temp.GetDatabaseManager().BanUser(
                    RawMessage.GetSendUser().id,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    Reason,
                    RawMessage.GetMessageChatInfo().id,
                    RawMessage.GetReplyMessage().message_id,
                    BanUserInfo
                    );
            }
            //if (status)
            //{
            TgApi.getDefaultApiConnection().sendMessage(
                RawMessage.GetMessageChatInfo().id,
                "操作成功。",
                RawMessage.message_id
                );
            return(true);
            //}
            //else
            //{
            //    TgApi.getDefaultApiConnection().sendMessage(
            //        RawMessage.GetMessageChatInfo().id,
            //        "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11",
            //        RawMessage.message_id
            //        );
            //    return true;
            //}
            //return false;
        }