コード例 #1
0
        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);
        }
コード例 #2
0
        internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.BAN_HELP_MESSAGE,
                    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     notCommonBan     = true;
            int      commandBanLength = 0;
            int      banDay           = 0;

            if (valLen > 3)
            {
                if (valLen == 4)
                {
                    if (value.Substring(0, 4) == "spam")
                    {
                        commandBanLength = 4;
                        Reason           = Strings.SPAM;
                        banDay           = Config.DefaultSpamBanDay;
                        notCommonBan     = false;
                    }

                    //if (value.Substring(0, 4) == "coin")
                    //{
                    //    commandBanLength = 4;
                    //    Reason = Strings.COIN;
                    //    banDay = Config.DefaultCoinBanDay;
                    //    notCommonBan = false;
                    //}
                }

                if (valLen == 5)
                {
                    if (value.Substring(0, 5) == "halal")
                    {
                        commandBanLength = 5;
                        Reason           = Strings.HALAL;
                        banDay           = Config.DefaultHalalBanDay;
                        notCommonBan     = false;
                    }
                }

                //if(valLen == 6)
                //    if (value.Substring(0, 6) == "innsfw")
                //    {
                //        commandBanLength = 6;
                //        Reason = Strings.INNSFW;
                //        banDay = Config.DefaultInNsfwBanDay;
                //        notCommonBan = false;
                //    }

                //if (valLen == 7)
                //{
                //    if (value.Substring(0, 7) == "spammer")
                //    {
                //        commandBanLength = 7;
                //        Reason = Strings.SPAMMER;
                //        banDay = Config.DefaultSpammerBanDay;
                //        notCommonBan = false;
                //    }

                //    if (value.Substring(0, 7) == "outnsfw")
                //    {
                //        commandBanLength = 7;
                //        Reason = Strings.OUTNSFW;
                //        banDay = Config.DefaultOutNsfwBanDay;
                //        notCommonBan = false;
                //    }

                //    if (value.Substring(0, 7) == "crawler")
                //    {
                //        commandBanLength = 7;
                //        Reason = Strings.CRAWLER;
                //        banDay = Config.DefaultCrawlerBanDay;
                //        notCommonBan = false;
                //    }
                //}

                if (banDay > 0)
                {
                    ExpiresTime = GetTime.GetUnixTime() + (banDay * 86400);
                }
            }

            if (!notCommonBan)
            {
                if (valLen > (commandBanLength + 1))
                {
                    if (value[commandBanLength] != ' ')
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            Strings.BAN_ERROR_MESSAGE + " 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 (notCommonBan)
            {
                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,
                            Strings.BAN_ERROR_MESSAGE + " 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 = Strings.HALAL;
                    }
                    if (Reason.ToLower() == "spam")
                    {
                        Reason = Strings.SPAM;
                    }
                    // if (Reason.ToLower() == "spammer") Reason = Strings.SPAMMER;
                    // if (Reason.ToLower() == "innsfw") Reason = Strings.INNSFW;
                    // if (Reason.ToLower() == "outnsfw") Reason = Strings.OUTNSFW;
                    // if (Reason.ToLower() == "coin") Reason = Strings.COIN;
                    // if (Reason.ToLower() == "crawler") Reason = Strings.CRAWLER;
                }
                catch (DecodeException)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        Strings.BAN_ERROR_MESSAGE + " err10",
                        RawMessage.message_id
                        );
                    return(true);
                }
            }

            if (Config.GetIsInWhiteList(BanUserId))
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.EXEC_FAIL + Strings.BAN_ERROR_USER_IN_WHITELIST,
                    RawMessage.message_id
                    );
                return(false);
            }

            int AdminID = RawMessage.GetSendUser().id;

            if (RawMessage.GetMessageChatInfo().id == Config.InternGroupID)
            {
                AdminID = 1;
            }

            bool status;

            if (BanUserInfo == null)
            {
                status = Config.GetDatabaseManager().BanUser(
                    AdminID,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    RAPI.escapeMarkdown(Reason)
                    );
            }
            else if (RawMessage.GetReplyMessage().new_chat_member != null)
            {
                status = Config.GetDatabaseManager().BanUser(
                    AdminID,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    RAPI.escapeMarkdown(Reason),
                    0,
                    0,
                    BanUserInfo
                    );
            }
            else
            {
                status = Config.GetDatabaseManager().BanUser(
                    AdminID,
                    BanUserId,
                    Level,
                    ExpiresTime,
                    RAPI.escapeMarkdown(Reason),
                    RawMessage.GetMessageChatInfo().id,
                    RawMessage.GetReplyMessage().message_id,
                    BanUserInfo
                    );
            }
            //if (status)
            //{
            TgApi.getDefaultApiConnection().sendMessage(
                RawMessage.GetMessageChatInfo().id,
                Strings.EXEC_OK,
                RawMessage.message_id
                );
            return(true);
            //}
            //else
            //{
            //    TgApi.getDefaultApiConnection().sendMessage(
            //        RawMessage.GetMessageChatInfo().id,
            //        "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Config.MainChannelName + " 。 err11",
            //        RawMessage.message_id
            //        );
            //    return true;
            //}
            //return false;
        }
コード例 #3
0
        internal bool BanMulti(TgMessage RawMessage, string JsonMessage, string Command)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.SUPERBAN_HELP_MESSAGE,
                    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   = Strings.HALAL;
                    if (valLen > 6)
                    {
                        if (value[5] != ' ')
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                RawMessage.GetMessageChatInfo().id,
                                Strings.SUPERBAN_ERROR_MESSAGE + " 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,
                            Strings.SUPERBAN_ERROR_MESSAGE + " 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 = Strings.HALAL;
                    }
                }
                catch (DecodeException)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        Strings.SUPERBAN_ERROR_MESSAGE + " err10",
                        RawMessage.message_id
                        );
                    return(true);
                }
            }

            new Thread(delegate()
            {
                foreach (int userid in UsersArray)
                {
                    BanUserId = userid;
                    status    = Config.GetDatabaseManager().BanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        Level,
                        ExpiresTime,
                        RAPI.escapeMarkdown(Reason)
                        );
                    if (Config.GetIsInWhiteList(BanUserId))
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetSendUser().id,
                            Strings.EXEC_FAIL + Strings.BAN_ERROR_USER_IN_WHITELIST + " UID " + BanUserId,
                            RawMessage.message_id
                            );
                    }
                    Thread.Sleep(3500);
                }

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

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.SUPERUNBAN_HELP_MESSAGE,
                    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,
                    Strings.SUPERUNBAN_ERROR_MESSAGE + " err10",
                    RawMessage.message_id
                    );
                return(true);
            }


            new Thread(delegate()
            {
                foreach (int userid in UsersArray)
                {
                    BanUserId = userid;
                    try
                    {
                        status = Config.GetDatabaseManager().UnbanUser(
                            RawMessage.GetSendUser().id,
                            BanUserId,
                            RAPI.escapeMarkdown(Reason)
                            );
                    }
                    catch (InvalidOperationException)
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.GetMessageChatInfo().id,
                            Strings.UNBAN_ERROR_USER_NOT_BANNED + " UID : " + BanUserId,
                            RawMessage.message_id
                            );
                    }

                    Thread.Sleep(3500);
                }

                //if (status)
                //{
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.EXEC_OK,
                    RawMessage.message_id
                    );
                //}
                //else
                //{
                //    TgApi.getDefaultApiConnection().sendMessage(
                //        RawMessage.GetMessageChatInfo().id,
                //        "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至  @" + Config.MainChannelName + " 。 err11",
                //        RawMessage.message_id
                //        );
                //    return true;
                //}
            }).Start();
            return(true);
        }
コード例 #5
0
        internal bool Unban(TgMessage RawMessage)
        {
            int banSpace = RawMessage.text.IndexOf(" ");

            if (banSpace == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.UNBAN_HELP_MESSAGE,
                    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,
                    Strings.UNBAN_ERROR_MESSAGE + " err10",
                    RawMessage.message_id
                    );
                return(true);
            }

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

            try
            {
                if (BanUserInfo == null)
                {
                    status = Config.GetDatabaseManager().UnbanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        RAPI.escapeMarkdown(Reason)
                        );
                }
                else
                {
                    status = Config.GetDatabaseManager().UnbanUser(
                        RawMessage.GetSendUser().id,
                        BanUserId,
                        RAPI.escapeMarkdown(Reason),
                        BanUserInfo
                        );
                }
            }
            catch (InvalidOperationException)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.EXEC_FAIL + Strings.UNBAN_ERROR_USER_NOT_BANNED,
                    RawMessage.message_id
                    );
                return(true);
            }

            if (status)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    Strings.EXEC_OK,
                    RawMessage.message_id
                    );
                if (RawMessage.GetMessageChatInfo().id == Config.CourtGroupID)
                {
                    TgApi.getDefaultApiConnection()
                    .kickChatMember(RawMessage.GetMessageChatInfo().id, BanUserId, GetTime.GetUnixTime() + 1);
                }
                return(true);
            }

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