internal bool BroadCast_Status(TgMessage RawMessage)
        {
            int saySpace = RawMessage.text.IndexOf(" ");

            if (saySpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/say [g|group|groupid=1] [t|text=text]" +
                    "\ng=ChatID\nt=訊息",
                    RawMessage.message_id
                    );
                return(true);
            }

            Dictionary <string, string>
            banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(saySpace + 1));

            string text = new GetValues().GetText(banValues, RawMessage);

            if (text == null)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/say [g|group|groupid=1] [t|text=text]" +
                    "\ng=ChatID\nt=訊息",
                    RawMessage.message_id
                    );
                return(true);
            }

            long groupID = new GetValues().GetGroupID(banValues, RawMessage);

            if (groupID == 0)
            {
                new Thread(delegate() { BC(RawMessage, text); }).Start();
            }
            else
            {
                TgApi.getDefaultApiConnection()
                .sendMessage(groupID, text, ParseMode: TgApi.PARSEMODE_MARKDOWN);
                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.chat.id, "傳送完畢!", RawMessage.message_id);
            }


            return(true);
        }
Ejemplo n.º 2
0
        internal bool Leave(TgMessage RawMessage)
        {
            int saySpace = RawMessage.text.IndexOf(" ");

            if (saySpace == -1)
            {
                if (RAPI.getIsBotAdmin(RawMessage.GetSendUser().id) || RAPI.getIsBotOP(RawMessage.GetSendUser().id) ||
                    TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.GetSendUser().id))
                {
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                "由 群管理 (" + RawMessage.GetSendUser().id + ") 請求離開群組", RawMessage.message_id);
                    TgApi.getDefaultApiConnection().leaveChat(RawMessage.chat.id);
                    return(true);
                }
            }

            if (TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.GetSendUser().id))
            {
                Dictionary <string, string>
                banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(saySpace + 1));

                long groupID = new GetValues().GetGroupID(banValues, RawMessage);

                if (groupID == 0)
                {
                    TgApi.getDefaultApiConnection()
                    .sendMessage(RawMessage.chat.id, "輸入錯誤!\n/leave [g=100000000]", RawMessage.message_id);
                }
                else
                {
                    TgApi.getDefaultApiConnection().sendMessage(groupID,
                                                                "由 Bot管理員 (" + RawMessage.GetSendUser().id + ") 請求離開群組", RawMessage.message_id);
                    TgApi.getDefaultApiConnection().leaveChat(groupID);
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id,
                                                                "由 Bot管理員 (" + RawMessage.GetSendUser().id + ") 請求離開群組 " + groupID, RawMessage.message_id);
                }

                return(true);
            }

            TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "您並不是群組管理或是 Bot 管理員",
                                                        RawMessage.message_id);
            return(true);
        }
Ejemplo n.º 3
0
        internal bool UnbanMulti(TgMessage RawMessage)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/suunban [i|id=1,2,3] [f|from=f|fwd|r|reply]" +
                    " r|reason=\"asdfsadf asdfadsf\"\n\n" +
                    "from 選項僅在 id 未被定義時起作用\n" +
                    "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" +
                    "選項優先度: 簡寫 > 全名\n" +
                    "Example:\n" +
                    "/suunban id=1,2,3 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/suunban",
                    RawMessage.message_id
                    );
                return(true);
            }

            int[]  UsersArray = { };
            bool   status     = false;
            int    BanUserId  = 0;
            string Reason;

            try
            {
                Dictionary <string, string> banValues =
                    CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1));

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

                Reason = new GetValues().GetReason(banValues, RawMessage);
                if (Reason == null)
                {
                    return(true);                // 如果 Reason 是 null 則代表出现了异常
                }
            }
            catch (DecodeException)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "您的輸入有錯誤,請檢查您的輸入,或使用 /suunban 取得幫助 err10",
                    RawMessage.message_id
                    );
                return(true);
            }

            new Thread(delegate()
            {
                foreach (int userid in UsersArray)
                {
                    BanUserId = userid;
                    try
                    {
                        status = Temp.GetDatabaseManager().UnbanUser(
                            RawMessage.GetSendUser().id,
                            BanUserId,
                            Reason
                            );
                    }
                    catch (InvalidOperationException)
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            "操作失敗,這位使用者(" + 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;
                //}
            }).Start();
            return(true);
        }
        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);
        }
Ejemplo n.º 5
0
        internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/twban [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" +
                    "/twban id=1 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/twban halal\n" +
                    "/twban 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,
                                "您的輸入有錯誤,請檢查您的輸入,或使用 /twban 查詢幫助。 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,
                            "您的輸入有錯誤,請檢查您的輸入,或使用 /twban 查詢幫助。 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,
                        "您的輸入有錯誤,請檢查您的輸入,或使用 /twban 查詢幫助 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;
        }
        internal bool Unban(TgMessage RawMessage)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "/cnunban [i|id=1] [f|from=f|fwd|r|reply]" +
                    " r|reason=\"asdfsadf asdfadsf\"\n\n" +
                    "from 選項僅在 id 未被定義時起作用\n" +
                    "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" +
                    "選項優先度: 簡寫 > 全名\n" +
                    "Example:\n" +
                    "/cnunban id=1 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" +
                    "/cnunban",
                    RawMessage.message_id
                    );
                return(true);
            }

            int      BanUserId = 0;
            string   Reason;
            UserInfo BanUserInfo = null;

            try
            {
                Dictionary <string, string> banValues =
                    CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1));

                // 获取使用者信息
                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;
                }

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

            new UnBanCaller().UnBanCallerThread(BanUserId);
            bool status;

            try
            {
                if (BanUserInfo == null)
                {
                    status = Temp.GetDatabaseManager().UnbanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        Reason
                        );
                }
                else
                {
                    status = Temp.GetDatabaseManager().UnbanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        Reason,
                        BanUserInfo
                        );
                }
            }
            catch (InvalidOperationException)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作失敗,這位使用者目前可能没有被封鎖。",
                    RawMessage.message_id
                    );
                return(true);
            }

            if (status)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "操作成功。",
                    RawMessage.message_id
                    );
                if (RawMessage.GetMessageChatInfo().id == Temp.CourtGroupID)
                {
                    TgApi.getDefaultApiConnection()
                    .kickChatMember(RawMessage.GetMessageChatInfo().id, BanUserId, GetTime.GetUnixTime() + 1);
                }
                return(true);
            }

            TgApi.getDefaultApiConnection().sendMessage(
                RawMessage.GetMessageChatInfo().id,
                "操作失敗,或許使用者未被封鎖。",
                RawMessage.message_id
                );
            return(false);
            //    TgApi.getDefaultApiConnection().sendMessage(
            //        RawMessage.GetMessageChatInfo().id,
            //        "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至  @" + Temp.MainChannelName + " 。 err11",
            //        RawMessage.message_id
            //        );
            //    return true;
            //return false;
        }