private void ProcessMessage(SpamMessage smsg, int MsgID, long ChatID, UserInfo SendUserInfo)
        {
            long banUtilTime;

            if (smsg.BanDays == 0 && smsg.BanHours == 0 && smsg.BanMinutes == 0)
            {
                banUtilTime = 0;
            }
            else
            {
                banUtilTime = GetTime.GetUnixTime() + (smsg.BanDays * 86400) + (smsg.BanHours * 3600) + (smsg.BanMinutes * 60);
            }
            if (smsg.AutoBlackList)
            {
                if (Temp.GetDatabaseManager().GetUserBanStatus(SendUserInfo.id).Ban == 0)
                {
                    return;
                }
                new Task(() =>
                {
                    Temp.GetDatabaseManager().BanUser(
                        0,
                        SendUserInfo.id,
                        smsg.BanLevel,
                        banUtilTime,
                        "System AUTO BAN: \n" + smsg.FriendlyName,
                        ChatID,
                        MsgID,
                        SendUserInfo
                        );
                }).Start();
            }
            if (smsg.AutoDelete)
            {
                new Task(() =>
                {
                    TgApi.getDefaultApiConnection().deleteMessage(ChatID, MsgID);
                }).Start();
            }
            if (smsg.AutoKick)
            {
                new Task(() =>
                {
                    TgApi.getDefaultApiConnection().kickChatMember(ChatID, SendUserInfo.id, banUtilTime);
                }).Start();
            }
            if (smsg.AutoMute)
            {
                TgApi.getDefaultApiConnection().restrictChatMember(
                    ChatID,
                    SendUserInfo.id,
                    banUtilTime,
                    SendMessage: true,
                    SendMedia: false
                    );
            }
        }
        public CallbackMessage OnSupergroupMemberJoinReceive(TgMessage RawMessage, string JsonMessage, UserInfo JoinedUser)
        {
            if (JoinedUser.id == TgApi.getDefaultApiConnection().getMe().id)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "欢迎使用 @" + TgApi.getDefaultApiConnection().getMe().username + "\n" +
                    "请您进行一些设置:\n" +
                    "1.在您的群组中给予 @" + TgApi.getDefaultApiConnection().getMe().username + " 管理员权限\n" +
                    "2.使用 /soamenable 启用一些功能\n" +
                    "3.Enjoy it!\n\n" +
                    "注: 默认开启的功能有 BlackList AutoKick AntiHalal AutoDeleteSpamMessage 这 4 个,您可以根据您的需要来禁用或启用。",
                    RawMessage.message_id
                    );
                return(new CallbackMessage());
            }
            if (Temp.DisableBanList)
            {
                return(new CallbackMessage());
            }
            DatabaseManager dbmgr = Temp.GetDatabaseManager();

            if (RawMessage.GetMessageChatInfo().id == -1001079439348)
            {
                BanUser banUser = dbmgr.GetUserBanStatus(JoinedUser.id);
                if (banUser.Ban == 0)
                {
                    string resultmsg = "这位用户被封禁了";
                    if (banUser.ChannelMessageID != 0)
                    {
                        resultmsg += ", [原因请点击这里查看](https://t.me/" + Temp.MainChannelName + "/" + banUser.ChannelMessageID + ")";
                    }
                    else
                    {
                        resultmsg += ",原因是:\n" + banUser.Reason;
                    }
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        resultmsg,
                        RawMessage.message_id,
                        ParseMode: TgApi.PARSEMODE_MARKDOWN
                        );
                }
                else
                {
                    TgApi.getDefaultApiConnection().restrictChatMember(
                        RawMessage.GetMessageChatInfo().id,
                        JoinedUser.id,
                        GetTime.GetUnixTime() + 60
                        );
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "您未被封禁,请闲杂人等退群。如果您想加入这个群组,您可以去多点群发一些广告,然后您被 ban 了就能加入了。\n\n" +
                        "您将在 60 秒后自动退群。",
                        RawMessage.message_id,
                        ParseMode: TgApi.PARSEMODE_MARKDOWN
                        );
                    new Thread(delegate() {
                        Thread.Sleep(60000);
                        TgApi.getDefaultApiConnection().kickChatMember(
                            RawMessage.GetMessageChatInfo().id,
                            JoinedUser.id,
                            GetTime.GetUnixTime() + 60
                            );
                    }).Start();
                }
                return(new CallbackMessage());
            }
            GroupCfg groupCfg = dbmgr.GetGroupConfig(RawMessage.GetMessageChatInfo().id);

            if (groupCfg.BlackList == 0)
            {
                BanUser banUser   = dbmgr.GetUserBanStatus(JoinedUser.id);
                string  resultmsg = "警告: ";
                if (banUser.Ban == 0)
                {
                    string banReason;
                    if (banUser.ChannelMessageID != 0)
                    {
                        banReason = ", [原因请点击这里查看](https://t.me/" + Temp.MainChannelName + "/" + banUser.ChannelMessageID + ")";
                    }
                    else
                    {
                        banReason = "\n\n原因是:\n" + banUser.Reason;
                    }
                    if (banUser.Level == 0)
                    {
                        resultmsg += "这位用户可能存在风险,已被封禁" + banReason + "\n\n" +
                                     "对于被封禁的用户,您可以通过 [点击这里](https://t.me/" + TgApi.getDefaultApiConnection().getMe().username + "?start=soam_req_unban) 以请求解封。";
                        if (groupCfg.AutoKick == 0)
                        {
                            SetActionResult result = TgApi.getDefaultApiConnection().kickChatMember(
                                RawMessage.GetMessageChatInfo().id,
                                JoinedUser.id,
                                GetTime.GetUnixTime() + 86400
                                );
                            if (!result.ok)
                            {
                                resultmsg += "\n\n请注意: 您的群组当前打开了自动移除危险成员但机器人没有相应的管理员权限" +
                                             ",请您关闭此功能或者将机器人设置为管理员并给予相应的权限(Ban users)。";
                            }
                        }
                    }
                    else if (banUser.Level == 1)
                    {
                        resultmsg += "这位用户可能存在不良行为" + banReason + "\n\n" +
                                     "对于群组的管理员: 您可以观察这位用户在您的群组当中是否存在不良行为后再决定是否移除该成员\n" +
                                     "对于被封禁的用户,您可以通过 [点击这里](https://t.me/" + TgApi.getDefaultApiConnection().getMe().username + "?start=soam_req_unban) 以请求解封。";
                    }
                }
                else
                {
                    return(new CallbackMessage()
                    {
                    });
                }
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    resultmsg,
                    RawMessage.message_id,
                    ParseMode: TgApi.PARSEMODE_MARKDOWN
                    );
                return(new CallbackMessage()
                {
                    StopProcess = true
                });
            }
            return(new CallbackMessage());
        }
        public CallbackMessage OnSupergroupMemberJoinReceive(TgMessage RawMessage, string JsonMessage,
                                                             UserInfo JoinedUser)
        {
            DatabaseManager dbmgr    = Temp.GetDatabaseManager();
            GroupCfg        groupCfg = dbmgr.GetGroupConfig(RawMessage.GetMessageChatInfo().id);

            if (groupCfg.AntiBot == 0 && JoinedUser.is_bot && !TgApi.getDefaultApiConnection()
                .checkIsAdmin(RawMessage.GetMessageChatInfo().id, RawMessage.from.id))
            {
                SetActionResult result = TgApi.getDefaultApiConnection()
                                         .kickChatMember(RawMessage.GetMessageChatInfo().id, JoinedUser.id, GetTime.GetUnixTime() + 300);
                if (result.ok)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "機器人 : " + JoinedUser.GetUserTextInfo() + "\n由於開啟了 AntiBot ,已自動移除機器人。"
                        );
                }
                else
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "機器人 : " + JoinedUser.GetUserTextInfo() + "\n由於開啟了 AntiBot ,但沒有 (Ban User) 權限,請設定正確的權限。"
                        );
                }

                new Task(() =>
                {
                    long banUtilTime = GetTime.GetUnixTime() + 86400;
                    Temp.GetDatabaseManager().BanUser(
                        0,
                        RawMessage.GetSendUser().id,
                        0,
                        banUtilTime,
                        "自動封鎖 - 拉入機器人 " + JoinedUser.GetUserTextInfo(),
                        RawMessage.GetMessageChatInfo().id,
                        0,
                        RawMessage.GetSendUser()
                        );
                }).Start();
            }

            if (JoinedUser.id == TgApi.getDefaultApiConnection().getMe().id)
            {
                if (RAPI.getIsBlockGroup(RawMessage.GetMessageChatInfo().id))
                {
                    new Thread(delegate()
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "此群組禁止使用本服務。");
                        Thread.Sleep(1000);
                        TgApi.getDefaultApiConnection().leaveChat(RawMessage.GetMessageChatInfo().id);
                    }).Start();
                    return(new CallbackMessage());
                }

                if (RawMessage.GetMessageChatInfo().type == "group")
                {
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                "一般群組無法使用本服務,如有疑問請至 @ChineseBlackList ");
                    Thread.Sleep(2000);
                    TgApi.getDefaultApiConnection().leaveChat(RawMessage.GetMessageChatInfo().id);
                    return(new CallbackMessage());
                }

                if (!new CheckHelper().CheckAdminInReportGroup(RawMessage.GetMessageChatInfo().id))
                {
                    new Thread(delegate()
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                    "群管理必須加入[項目群組](https://t.me/" + Temp.ReportGroupName + ")才可使用本服務。", ParseMode: TgApi.PARSEMODE_MARKDOWN);
                        Thread.Sleep(2000);
                        TgApi.getDefaultApiConnection().leaveChat(RawMessage.GetMessageChatInfo().id);
                    }).Start();
                    return(new CallbackMessage());
                }

                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "歡迎使用 @" + TgApi.getDefaultApiConnection().getMe().username + "\n" +
                    "1.請在群組中给予 @" + TgApi.getDefaultApiConnection().getMe().username + " 管理員權限\n" +
                    "2.使用 /help 可查閱使用說明\n" +
                    "預設開啟的功能有 BlackList AutoKick AntiHalal SubscribeBanList,可以根據需要來調整。\n\n" +
                    "注意 : 加入機器人即同意讓渡部分 Ban Users 權限予本項目組,並授權本組依據 @ChineseBlackList 置頂規定,代表群管理對群組內成員逕行封鎖\n" +
                    "如不同意請立即移除此機器人,且禁止違背群主意願私自添加",
                    RawMessage.message_id
                    );
                return(new CallbackMessage());
            }

            if (Temp.DisableBanList)
            {
                return(new CallbackMessage());
            }

            if (Temp.CourtGroupName != null && RawMessage.GetMessageChatInfo().username == Temp.CourtGroupName)
            {
                BanUser banUser = dbmgr.GetUserBanStatus(JoinedUser.id);
                if (banUser.Ban == 0)
                {
                    string resultmsg = "這位使用者被封鎖了\n請先閱讀置頂及公告區\n未依規定發表的任何訊息皆不回應\n\n" + banUser.GetBanMessage_ESCMD();
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        resultmsg,
                        RawMessage.message_id,
                        TgApi.PARSEMODE_MARKDOWN
                        );
                }
                else
                {
                    if (RAPI.getIsInWhitelist(JoinedUser.id))
                    {
                        return(new CallbackMessage());
                    }
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        "您未被封鎖,請離開,本群僅提供被 CNBL 封鎖者申訴",
                        RawMessage.message_id,
                        TgApi.PARSEMODE_MARKDOWN
                        );

                    TgApi.getDefaultApiConnection().restrictChatMember(
                        RawMessage.GetMessageChatInfo().id,
                        JoinedUser.id,
                        0, false, false, false, false);
                    new Thread(delegate()
                    {
                        Thread.Sleep(30000);
                        try
                        {
                            TgApi.getDefaultApiConnection().kickChatMember(
                                RawMessage.GetMessageChatInfo().id,
                                JoinedUser.id,
                                GetTime.GetUnixTime() + 300
                                );
                            TgApi.getDefaultApiConnection().restrictChatMember(
                                RawMessage.GetMessageChatInfo().id,
                                JoinedUser.id,
                                0, true, false, false, false);
                        }
                        catch
                        {
                        }
                    }).Start();
                }

                return(new CallbackMessage());
            }

            if (groupCfg.BlackList == 0)
            {
                BanUser banUser   = dbmgr.GetUserBanStatus(JoinedUser.id);
                string  resultmsg = "";
                if (banUser.Ban == 0)
                {
                    string banReason;
                    if (banUser.ChannelMessageID != 0 && Temp.MainChannelName != null)
                    {
                        banReason = "[原因請點選這裡查看](https://t.me/" + Temp.MainChannelName + "/" +
                                    banUser.ChannelMessageID + ")\n";
                    }
                    else
                    {
                        banReason = "\n原因 : " + RAPI.escapeMarkdown(banUser.Reason) + "\n";
                    }
                    if (banUser.Level == 0)
                    {
                        resultmsg += "警告 : 這個使用者「將會」對群組造成負面影響\n" +
                                     banReason +
                                     "\n若有誤判,可以到 [這個群組](https://t.me/" + Temp.CourtGroupName + ") 尋求申訴";
                        if (groupCfg.AutoKick == 0)
                        {
                            try
                            {
                                SetActionResult result = TgApi.getDefaultApiConnection().kickChatMember(
                                    RawMessage.GetMessageChatInfo().id,
                                    JoinedUser.id,
                                    GetTime.GetUnixTime() + 300
                                    );
                                if (!result.ok)
                                {
                                    resultmsg += "\n注意 : 由於開啟了 AutoKick 但沒有 Ban Users 權限" +
                                                 ",請關閉此功能或給予權限(Ban users)。";
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    else if (banUser.Level == 1)
                    {
                        resultmsg += "警告 : 這個使用者「可能」對群組造成負面影響" + banReason + "\n" +
                                     "請群組管理員多加留意\n" +
                                     "對於被警告的使用者,你可以通過 [這個群組](https://t.me/" + Temp.CourtGroupName + ") 以請求解除。";
                    }
                }
                else
                {
                    return(new CallbackMessage());
                }

                new Thread(delegate()
                {
                    SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.GetMessageChatInfo().id,
                        resultmsg,
                        RawMessage.message_id,
                        TgApi.PARSEMODE_MARKDOWN
                        );
                    Thread.Sleep(60000);
                    TgApi.getDefaultApiConnection().deleteMessage(
                        autodeletespammessagesendresult.result.chat.id,
                        autodeletespammessagesendresult.result.message_id
                        );
                }).Start();

                return(new CallbackMessage {
                    StopProcess = true
                });
            }

            return(new CallbackMessage());
        }
示例#4
0
        private void ProcessMessage(SpamMessage smsg, int MsgID, long ChatID, UserInfo SendUserInfo, int point)
        {
            long banUtilTime;

            if (smsg.BanDays == 0 && smsg.BanHours == 0 && smsg.BanMinutes == 0)
            {
                banUtilTime = 0;
            }
            else
            {
                banUtilTime = GetTime.GetUnixTime() + smsg.BanDays * 86400 + smsg.BanHours * 3600 +
                              smsg.BanMinutes * 60;
            }

            if (smsg.AutoKick)
            {
                new Thread(delegate()
                {
                    //TgApi.getDefaultApiConnection().restrictChatMember(
                    //    ChatID,
                    //    SendUserInfo.id,
                    //    GetTime.GetUnixTime() + 60,
                    //    false);
                    Thread.Sleep(5500);
                    TgApi.getDefaultApiConnection()
                    .kickChatMember(ChatID, SendUserInfo.id, GetTime.GetUnixTime() + 1800);
                }).Start();
            }
            if (smsg.AutoBlackList)
            {
                new Thread(delegate()
                {
                    if (Temp.GetDatabaseManager().GetUserBanStatus(SendUserInfo.id).Ban == 0)
                    {
                        return;
                    }
                    new Task(() =>
                    {
                        Temp.GetDatabaseManager().BanUser(
                            0,
                            SendUserInfo.id,
                            smsg.BanLevel,
                            banUtilTime,
                            smsg.FriendlyName + "\n分數 : " + point,
                            ChatID,
                            MsgID,
                            SendUserInfo
                            );
                    }).Start();
                }).Start();
            }
            else
            {
                if (smsg.AutoMute)
                {
                    TgApi.getDefaultApiConnection().restrictChatMember(
                        ChatID,
                        SendUserInfo.id,
                        banUtilTime,
                        true,
                        false
                        );
                }
            }

            if (smsg.AutoDelete)
            {
                new Thread(delegate()
                {
                    Thread.Sleep(10000);
                    TgApi.getDefaultApiConnection().deleteMessage(ChatID, MsgID);
                }).Start();
            }
        }
示例#5
0
        public CallbackMessage ReceiveAllNormalMessage(TgMessage BaseMessage, string JsonMessage)
        {
            if (RAPI.getIsBlockGroup(BaseMessage.GetMessageChatInfo().id))
            {
                new Thread(delegate()
                {
                    TgApi.getDefaultApiConnection().sendMessage(BaseMessage.GetMessageChatInfo().id, "此群組禁止使用本服務。");
                    Thread.Sleep(2000);
                    TgApi.getDefaultApiConnection().leaveChat(BaseMessage.GetMessageChatInfo().id);
                }).Start();
                return(new CallbackMessage());
            }

            if (BaseMessage.GetMessageChatInfo().type == "group")
            {
                TgApi.getDefaultApiConnection().sendMessage(BaseMessage.GetMessageChatInfo().id,
                                                            "一般群組無法使用本服務,如有疑問請至 @ChineseBlackList ");
                Thread.Sleep(2000);
                TgApi.getDefaultApiConnection().leaveChat(BaseMessage.GetMessageChatInfo().id);
                return(new CallbackMessage());
            }

            if (!new CheckHelper().CheckAdminInReportGroup(BaseMessage.GetMessageChatInfo().id))
            {
                new Thread(delegate()
                {
                    TgApi.getDefaultApiConnection().sendMessage(BaseMessage.GetMessageChatInfo().id,
                                                                "群管理必須加入[項目群組](https://t.me/" + Temp.ReportGroupName + ")才可使用本服務。", ParseMode: TgApi.PARSEMODE_MARKDOWN);
                    Thread.Sleep(2000);
                    TgApi.getDefaultApiConnection().leaveChat(BaseMessage.GetMessageChatInfo().id);
                }).Start();
                return(new CallbackMessage());
            }

            string forward_from_id = null;

            if (BaseMessage.forward_from_chat != null)
            {
                forward_from_id = BaseMessage.forward_from_chat.id.ToString();
                if (RAPI.getIsInWhitelist(BaseMessage.forward_from_chat.id))
                {
                    return(new CallbackMessage());
                }
            }

            if (BaseMessage.chat.type != "group" && BaseMessage.chat.type != "supergroup")
            {
                return(new CallbackMessage());
            }
            string chatText = null;

            if (BaseMessage.text != null)
            {
                chatText = BaseMessage.text.ToLower();
            }
            else if (BaseMessage.caption != null)
            {
                chatText = BaseMessage.caption.ToLower();
            }
            else
            {
                return(new CallbackMessage());
            }
            // Call Admin START
            int atAdminPath = chatText.IndexOf("@admin");

            if (atAdminPath == -1)
            {
                atAdminPath = chatText.IndexOf("!admin");
            }
            if (atAdminPath == -1)
            {
                atAdminPath = chatText.IndexOf("/admin");
            }
            if (atAdminPath != -1)
            {
                int textLen = chatText.Length;
                if (textLen == 6)
                {
                    CallAdmin(BaseMessage);
                }
                else if (textLen >= 8)
                {
                    if (atAdminPath == 0)
                    {
                        if (chatText[7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                    else if (atAdminPath == textLen - 6)
                    {
                        if (chatText[textLen - 7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                    else
                    {
                        if (chatText[atAdminPath - 1] == ' ' && chatText[atAdminPath + 7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                }

                if (Temp.InternGroupID != 0)
                {
                    TgApi.getDefaultApiConnection().forwardMessage(
                        Temp.InternGroupID,
                        BaseMessage.GetMessageChatInfo().id,
                        BaseMessage.GetReplyMessage().message_id
                        );
                    TgApi.getDefaultApiConnection().sendMessage(
                        Temp.InternGroupID,
                        BaseMessage.GetMessageChatInfo().GetChatTextInfo() + "\n\nReport By" + BaseMessage.GetSendUser().GetUserTextInfo()
                        );
                }
            }
            // Call Admin END

            if (Temp.ReportGroupID != 0 && BaseMessage.GetMessageChatInfo().id == Temp.ReportGroupID)
            {
                if (BaseMessage.forward_from != null)
                {
                    BanUser banUser = Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.forward_from.id);
                    if (banUser.Ban == 0)
                    {
                        string resultmsg = "使用者被封鎖了\n" + banUser.GetBanMessage_ESCMD();
                        TgApi.getDefaultApiConnection().sendMessage(
                            BaseMessage.GetMessageChatInfo().id,
                            resultmsg,
                            BaseMessage.message_id,
                            TgApi.PARSEMODE_MARKDOWN
                            );
                    }
                    else
                    {
                        int                max_point      = 0;
                        SpamMessage        max_point_spam = new SpamMessage();
                        List <SpamMessage> spamMsgList    = Temp.GetDatabaseManager().GetSpamMessageList();
                        foreach (SpamMessage smsg in spamMsgList)
                        {
                            int points = 0;
                            switch (smsg.Type)
                            {
                            case 0:
                                points = +new SpamMessageChecker().GetEqualsPoints(smsg.Messages, chatText);
                                break;

                            case 1:
                                points = +new SpamMessageChecker().GetRegexPoints(smsg.Messages, chatText);
                                break;

                            case 2:
                                points = +new SpamMessageChecker().GetSpamPoints(smsg.Messages, chatText);
                                break;

                            case 3:
                                points = +new SpamMessageChecker().GetIndexOfPoints(smsg.Messages, chatText);
                                break;

                            case 4:
                                points = +new SpamMessageChecker().GetHalalPoints(chatText + BaseMessage.forward_from.full_name());
                                break;

                            case 5:
                                points = +new SpamMessageChecker().GetIndiaPoints(chatText + BaseMessage.forward_from.full_name());
                                break;

                            case 6:
                                points = new SpamMessageChecker().GetContainsPoints(smsg.Messages,
                                                                                    chatText + " " + forward_from_id);
                                break;

                            case 7:
                                points = new SpamMessageChecker().GetRussiaPoints(chatText + BaseMessage.forward_from.full_name());
                                break;

                            case 8:
                                points = new SpamMessageChecker().GetNamePoints(smsg.Messages,
                                                                                BaseMessage.forward_from.full_name());
                                break;
                            }

                            if (points >= smsg.MinPoints)
                            {
                                if (points > max_point)
                                {
                                    max_point      = points;
                                    max_point_spam = smsg;
                                }
                            }
                        }

                        if (max_point > 0)
                        {
                            new Thread(delegate()
                            {
                                TgApi.getDefaultApiConnection().sendMessage(
                                    BaseMessage.GetMessageChatInfo().id,
                                    "使用者未被封鎖,由於符合`" + max_point_spam.FriendlyName + "`規則,現已自動封鎖",
                                    BaseMessage.message_id,
                                    TgApi.PARSEMODE_MARKDOWN
                                    );
                                long banUtilTime = 0;
                                if (max_point_spam.BanDays == 0 && max_point_spam.BanHours == 0 && max_point_spam.BanMinutes == 0)
                                {
                                    banUtilTime = 0;
                                }
                                else
                                {
                                    banUtilTime = GetTime.GetUnixTime() + max_point_spam.BanDays * 86400 + max_point_spam.BanHours * 3600 +
                                                  max_point_spam.BanMinutes * 60;
                                }
                                new Task(() =>
                                {
                                    Temp.GetDatabaseManager().BanUser(
                                        0,
                                        BaseMessage.forward_from.id,
                                        max_point_spam.BanLevel,
                                        banUtilTime,
                                        max_point_spam.FriendlyName + "\n分數 : " + max_point,
                                        BaseMessage.GetMessageChatInfo().id,
                                        BaseMessage.message_id,
                                        BaseMessage.forward_from
                                        );
                                }).Start();
                            }).Start();
                        }
                        else
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                BaseMessage.GetMessageChatInfo().id,
                                "使用者未被封鎖,如要舉報請附上截圖",
                                BaseMessage.message_id,
                                TgApi.PARSEMODE_MARKDOWN
                                );
                        }
                    }
                    return(new CallbackMessage());
                }
            }

            if (RAPI.getIsInWhitelist(BaseMessage.from.id))
            {
                return(new CallbackMessage());
            }

            if (TgApi.getDefaultApiConnection().checkIsAdmin(BaseMessage.chat.id, BaseMessage.from.id))
            {
                return(new CallbackMessage());
            }

            // ALTI HALAL Start
            GroupCfg cfg = Temp.GetDatabaseManager().GetGroupConfig(BaseMessage.chat.id);

            if (cfg.AntiHalal == 0)
            {
                int                max_point      = 0;
                SpamMessage        max_point_spam = new SpamMessage();
                List <SpamMessage> spamMsgList    = Temp.GetDatabaseManager().GetSpamMessageList();
                foreach (SpamMessage smsg in spamMsgList)
                {
                    int points = 0;
                    switch (smsg.Type)
                    {
                    case 4:
                        points = +new SpamMessageChecker().GetHalalPoints(chatText + BaseMessage.from.full_name());
                        break;

                    case 5:
                        points = +new SpamMessageChecker().GetIndiaPoints(chatText + BaseMessage.from.full_name());
                        break;

                    case 7:
                        points = new SpamMessageChecker().GetRussiaPoints(chatText + BaseMessage.from.full_name());
                        break;
                    }

                    if (points >= smsg.MinPoints)
                    {
                        if (points > max_point)
                        {
                            max_point      = points;
                            max_point_spam = smsg;
                        }
                    }
                }

                if (max_point > 0)
                {
                    //Send alert and delete alert after 60 second
                    new Thread(delegate()
                    {
                        string msg = "";
                        if (Temp.ReportGroupName == Temp.CourtGroupName)
                        {
                            msg = "偵測到 " + max_point_spam.FriendlyName +
                                  " ,已自動回報,如有誤報請加入 @" + Temp.ReportGroupName + " 以報告誤報。";
                        }
                        else
                        {
                            msg = "偵測到 " + max_point_spam.FriendlyName +
                                  " ,已自動回報,如有誤報請加入 @" + Temp.ReportGroupName + " 以報告誤報" +
                                  " ,如有疑慮請加入 @" + Temp.CourtGroupName + " 提出申訴。";
                        }

                        SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection()
                                                                            .sendMessage(
                            BaseMessage.GetMessageChatInfo().id,
                            msg
                            );
                        ProcessMessage(max_point_spam, BaseMessage.message_id, BaseMessage.GetMessageChatInfo().id,
                                       BaseMessage.GetSendUser(), max_point);
                        Thread.Sleep(30000);
                        TgApi.getDefaultApiConnection().deleteMessage(
                            autodeletespammessagesendresult.result.chat.id,
                            autodeletespammessagesendresult.result.message_id
                            );
                    }).Start();
                    return(new CallbackMessage {
                        StopProcess = true
                    });
                }
                //{
                //    List<SpamMessage> spamMsgList = Temp.GetDatabaseManager().GetSpamMessageList();
                //    int halalPoints = new SpamMessageChecker().GetHalalPoints(chatText);
                //    int indiaPoints = new SpamMessageChecker().GetIndiaPoints(chatText);
                //    int russiaPoints = new SpamMessageChecker().GetRussiaPoints(chatText);
                //    if (halalPoints >= 8 || indiaPoints >= 16)
                //    {
                //        //If not in ban status , ban user.
                //        if (Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.from.id).Ban != 0)
                //            new Task(() =>
                //            {
                //                Temp.GetDatabaseManager().BanUser(
                //                    0,
                //                    BaseMessage.from.id,
                //                    0,
                //                    0,
                //                    "\n自動封鎖 : 無法理解的語言",
                //                    BaseMessage.GetMessageChatInfo().id,
                //                    BaseMessage.message_id,
                //                    BaseMessage.from
                //                );
                //            }).Start();

                //new Task(() =>
                //{
                //    TgApi.getDefaultApiConnection().forwardMessage(
                //        Temp.ReasonChannelID,
                //        BaseMessage.GetMessageChatInfo().id,
                //        BaseMessage.message_id);
                //}).Start();

                //Kick user and delete spam message
                //        new Task(() =>
                //        {
                //            TgApi.getDefaultApiConnection().kickChatMember(BaseMessage.chat.id, BaseMessage.from.id, GetTime.GetUnixTime() + 300);
                //            TgApi.getDefaultApiConnection().deleteMessage(BaseMessage.chat.id, BaseMessage.message_id);
                //        }).Start();

                //        BanUser banstat = Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.GetSendUser().id);

                //        if (banstat.Ban == 0)
                //            TgApi.getDefaultApiConnection().kickChatMember(
                //                BaseMessage.GetMessageChatInfo().id,
                //                BaseMessage.GetSendUser().id,
                //                GetTime.GetUnixTime() + 300
                //            );

                //Send alert and delete alert after 60 second
                //        new Thread(delegate()
                //        {
                //            SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection().sendMessage(
                //                BaseMessage.GetMessageChatInfo().id,
                //                "偵測到無法理解的語言,已自動回報,如有誤報請加入 @" + Temp.ReportGroupName + " 以報告誤報。"
                //            );
                //            Thread.Sleep(60000);
                //            TgApi.getDefaultApiConnection().deleteMessage(
                //                autodeletespammessagesendresult.result.chat.id,
                //                autodeletespammessagesendresult.result.message_id
                //            );
                //        }).Start();
                //        return new CallbackMessage {StopProcess = true};
                //    }
            }
            // ALTI HALAL AND INDIA END

            // AUTO DELETE SPAM MESSAGE START
            if (Temp.DisableBanList == false && cfg.AutoDeleteSpamMessage == 0)
            {
                int                max_point      = 0;
                SpamMessage        max_point_spam = new SpamMessage();
                List <SpamMessage> spamMsgList    = Temp.GetDatabaseManager().GetSpamMessageList();
                foreach (SpamMessage smsg in spamMsgList)
                {
                    int points = 0;
                    switch (smsg.Type)
                    {
                    case 0:
                        points = +new SpamMessageChecker().GetEqualsPoints(smsg.Messages, chatText);
                        break;

                    case 1:
                        points = +new SpamMessageChecker().GetRegexPoints(smsg.Messages, chatText);
                        break;

                    case 2:
                        points = +new SpamMessageChecker().GetSpamPoints(smsg.Messages, chatText);
                        break;

                    case 3:
                        points = +new SpamMessageChecker().GetIndexOfPoints(smsg.Messages, chatText);
                        break;

                    case 6:
                        points = new SpamMessageChecker().GetContainsPoints(smsg.Messages,
                                                                            chatText + " " + forward_from_id);
                        break;

                    case 8:
                        points = new SpamMessageChecker().GetNamePoints(smsg.Messages,
                                                                        BaseMessage.from.full_name());
                        break;
                    }

                    if (points >= smsg.MinPoints)
                    {
                        if (points > max_point)
                        {
                            max_point      = points;
                            max_point_spam = smsg;
                        }
                    }
                }

                if (max_point > 0)
                {
                    //Send alert and delete alert after 60 second
                    new Thread(delegate()
                    {
                        string msg = "";
                        if (Temp.ReportGroupName == Temp.CourtGroupName)
                        {
                            msg = "偵測到 " + max_point_spam.FriendlyName +
                                  " ,已自動回報,如有誤報請加入 @" + Temp.ReportGroupName + " 以報告誤報。";
                        }
                        else
                        {
                            msg = "偵測到 " + max_point_spam.FriendlyName +
                                  " ,已自動回報,如有誤報請加入 @" + Temp.ReportGroupName + " 以報告誤報。" +
                                  " ,如有疑慮請加入 @" + Temp.CourtGroupName + " 提出申訴。";
                        }
                        SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection()
                                                                            .sendMessage(
                            BaseMessage.GetMessageChatInfo().id,
                            msg
                            );

                        ProcessMessage(max_point_spam, BaseMessage.message_id, BaseMessage.GetMessageChatInfo().id,
                                       BaseMessage.GetSendUser(), max_point);
                        Thread.Sleep(30000);
                        TgApi.getDefaultApiConnection().deleteMessage(
                            autodeletespammessagesendresult.result.chat.id,
                            autodeletespammessagesendresult.result.message_id
                            );
                    }).Start();
                    return(new CallbackMessage {
                        StopProcess = true
                    });
                }
            }


            // AUTO DELETE SPAM MESSAGE END

            // Auto DELETE Command START
            if (cfg.AutoDeleteCommand == 0)
            {
                if (BaseMessage.entities != null)
                {
                    ContentEntities tmpEntities = BaseMessage.entities[0];
                    Log.i(tmpEntities.type + "" + tmpEntities.offset);
                    if (tmpEntities.type == "bot_command" && tmpEntities.offset == 0)
                    {
                        new Thread(delegate()
                        {
                            SendMessageResult autodeletecommandsendresult = TgApi.getDefaultApiConnection().sendMessage(
                                BaseMessage.GetMessageChatInfo().id,
                                "請您不要亂玩機器人的指令,有問題請聯絡群組管理員。"
                                );
                            Thread.Sleep(60000);
                            TgApi.getDefaultApiConnection().deleteMessage(
                                autodeletecommandsendresult.result.chat.id,
                                autodeletecommandsendresult.result.message_id
                                );
                        }).Start();
                        TgApi.getDefaultApiConnection().deleteMessage(BaseMessage.chat.id, BaseMessage.message_id);
                    }
                }
            }
            // Auto DELETE Command END

            // Admin ONLY START
            if (cfg.AdminOnly == 0)
            {
                throw new StopProcessException();
            }
            // Admin ONLY END
            return(new CallbackMessage());
        }
        public CallbackMessage ReceiveAllNormalMessage(TgMessage BaseMessage, string JsonMessage)
        {
            if (BaseMessage.chat.type != "group" && BaseMessage.chat.type != "supergroup")
            {
                return(new CallbackMessage());
            }
            string chatText = null;

            if (BaseMessage.text != null)
            {
                chatText = BaseMessage.text.ToLower();
            }
            else if (BaseMessage.caption != null)
            {
                chatText = BaseMessage.caption.ToLower();
            }
            else
            {
                return(new CallbackMessage());
            }
            // Call Admin START
            int atAdminPath = chatText.IndexOf("@admin");

            if (atAdminPath != -1)
            {
                int textLen = chatText.Length;
                if (textLen == 6)
                {
                    CallAdmin(BaseMessage);
                }
                else if (textLen >= 8)
                {
                    if (atAdminPath == 0)
                    {
                        if (chatText[7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                    else if (atAdminPath == textLen - 6)
                    {
                        if (chatText[textLen - 7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                    else
                    {
                        if (chatText[atAdminPath - 1] == ' ' && chatText[atAdminPath + 7] == ' ')
                        {
                            CallAdmin(BaseMessage);
                        }
                    }
                }
            }
            // Call Admin END

            if (TgApi.getDefaultApiConnection().checkIsAdmin(BaseMessage.chat.id, BaseMessage.from.id))
            {
                return(new CallbackMessage());
            }

            // ALTI HALAL AND INDIA START
            GroupCfg cfg = Temp.GetDatabaseManager().GetGroupConfig(BaseMessage.chat.id);

            if (cfg.AntiHalal == 0)
            {
                List <SpamMessage> spamMsgList = Temp.GetDatabaseManager().GetSpamMessageList();
                int halalPoints = new SpamMessageChecker().GetHalalPoints(chatText);
                int indiaPoints = new SpamMessageChecker().GetIndiaPoints(chatText);
                if (halalPoints >= 8 || indiaPoints >= 16)
                {
                    SendMessageResult result = TgApi.getDefaultApiConnection().forwardMessage(
                        Temp.AdminGroupID,
                        BaseMessage.GetMessageChatInfo().id,
                        BaseMessage.message_id
                        );
                    if (Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.from.id).Ban != 0)
                    {
                        new Task(() =>
                        {
                            Temp.GetDatabaseManager().BanUser(
                                0,
                                BaseMessage.from.id,
                                1,
                                0,
                                "System AUTO BAN: \n清真或印度消息",
                                BaseMessage.GetMessageChatInfo().id,
                                BaseMessage.message_id,
                                BaseMessage.from
                                );
                        }).Start();
                    }
                    new Task(() =>
                    {
                        TgApi.getDefaultApiConnection().kickChatMember(BaseMessage.chat.id, BaseMessage.from.id, 0);
                        TgApi.getDefaultApiConnection().deleteMessage(BaseMessage.chat.id, BaseMessage.message_id);
                    }).Start();
                    BanUser banstat = Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.GetSendUser().id);
                    if (banstat.Ban == 0)
                    {
                        TgApi.getDefaultApiConnection().kickChatMember(
                            BaseMessage.GetMessageChatInfo().id,
                            BaseMessage.GetSendUser().id,
                            GetTime.GetUnixTime() + 86400
                            );
                    }
                    if (result.ok)
                    {
                        new Thread(delegate() {
                            TgApi.getDefaultApiConnection().sendMessage(
                                Temp.AdminGroupID,
                                BaseMessage.GetSendUser().GetUserTextInfo() + "\n\n" + banstat.GetBanMessage() + "\n\n" +
                                BaseMessage.GetMessageChatInfo().GetChatTextInfo() + "\n\n" +
                                "匹配到的规则: 清真或印度消息\n" +
                                "清真得分: " + halalPoints + "\n" +
                                "印度得分: " + indiaPoints,
                                result.result.message_id
                                );
                        }).Start();
                    }
                    new Thread(delegate() {
                        SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection().sendMessage(
                            BaseMessage.GetMessageChatInfo().id,
                            "检查到清真或印度消息,已尝试上报用户行为,如有误报请加入 @" + Temp.MainChannelName + " 提供的群组以报告误报。"
                            );
                        Thread.Sleep(60000);
                        TgApi.getDefaultApiConnection().deleteMessage(
                            autodeletespammessagesendresult.result.chat.id,
                            autodeletespammessagesendresult.result.message_id
                            );
                    }).Start();
                    return(new CallbackMessage()
                    {
                        StopProcess = true
                    });
                }
            }
            // ALTI HALAL AND INDIA END

            // AUTO DELETE SPAM MESSAGE START
            if (Temp.DisableBanList == false && cfg.AutoDeleteSpamMessage == 0)
            {
                List <SpamMessage> spamMsgList = Temp.GetDatabaseManager().GetSpamMessageList();
                foreach (SpamMessage smsg in spamMsgList)
                {
                    int points = 0;
                    switch (smsg.Type)
                    {
                    case 0:
                        points = new SpamMessageChecker().GetEqualsPoints(smsg.Messages, chatText);
                        break;

                    case 1:
                        points = new SpamMessageChecker().GetRegexPoints(smsg.Messages, chatText);
                        break;

                    case 2:
                        points = new SpamMessageChecker().GetSpamPoints(smsg.Messages, chatText);
                        break;

                    case 3:
                        points = new SpamMessageChecker().GetIndexOfPoints(smsg.Messages, chatText);
                        break;

                    case 4:
                        points = new SpamMessageChecker().GetHalalPoints(chatText);
                        break;

                    case 5:
                        points = new SpamMessageChecker().GetIndiaPoints(chatText);
                        break;
                    }
                    if (points >= smsg.MinPoints)
                    {
                        SendMessageResult result = TgApi.getDefaultApiConnection().forwardMessage(
                            Temp.AdminGroupID,
                            BaseMessage.GetMessageChatInfo().id,
                            BaseMessage.message_id
                            );
                        ProcessMessage(smsg, BaseMessage.message_id, BaseMessage.GetMessageChatInfo().id, BaseMessage.GetSendUser());
                        BanUser banstat = Temp.GetDatabaseManager().GetUserBanStatus(BaseMessage.GetSendUser().id);
                        if (banstat.Ban == 0)
                        {
                            TgApi.getDefaultApiConnection().kickChatMember(
                                BaseMessage.GetMessageChatInfo().id,
                                BaseMessage.GetSendUser().id,
                                GetTime.GetUnixTime() + 86400
                                );
                        }
                        if (result.ok)
                        {
                            new Thread(delegate() {
                                TgApi.getDefaultApiConnection().sendMessage(
                                    Temp.AdminGroupID,
                                    BaseMessage.GetSendUser().GetUserTextInfo() + "\n\n" + banstat.GetBanMessage() + "\n\n" +
                                    BaseMessage.GetMessageChatInfo().GetChatTextInfo() + "\n\n" +
                                    "匹配到的规则: " + smsg.FriendlyName + "\n" +
                                    "得分: " + points,
                                    result.result.message_id
                                    );
                            }).Start();
                        }
                        new Thread(delegate() {
                            SendMessageResult autodeletespammessagesendresult = TgApi.getDefaultApiConnection().sendMessage(
                                BaseMessage.GetMessageChatInfo().id,
                                "检查到 " + smsg.FriendlyName +
                                " ,已尝试上报用户行为,如有误报请加入 @" + Temp.MainChannelName + " 提供的群组以报告误报。"
                                );
                            Thread.Sleep(60000);
                            TgApi.getDefaultApiConnection().deleteMessage(
                                autodeletespammessagesendresult.result.chat.id,
                                autodeletespammessagesendresult.result.message_id
                                );
                        }).Start();
                        return(new CallbackMessage()
                        {
                            StopProcess = true
                        });
                    }
                }
            }
            // AUTO DELETE SPAM MESSAGE END

            // Auto DELETE Command START
            if (cfg.AutoDeleteCommand == 0)
            {
                if (BaseMessage.entities != null)
                {
                    ContentEntities tmpEntities = BaseMessage.entities[0];
                    Log.i(tmpEntities.type + "" + tmpEntities.offset);
                    if (tmpEntities.type == "bot_command" && tmpEntities.offset == 0)
                    {
                        new Thread(delegate() {
                            SendMessageResult autodeletecommandsendresult = TgApi.getDefaultApiConnection().sendMessage(
                                BaseMessage.GetMessageChatInfo().id,
                                "请您不要乱玩机器人命令,如有疑问请您联系群组的管理员。"
                                );
                            Thread.Sleep(60000);
                            TgApi.getDefaultApiConnection().deleteMessage(
                                autodeletecommandsendresult.result.chat.id,
                                autodeletecommandsendresult.result.message_id
                                );
                        }).Start();
                        TgApi.getDefaultApiConnection().deleteMessage(BaseMessage.chat.id, BaseMessage.message_id);
                    }
                }
            }
            // Auto DELETE Command END

            // Admin ONLY START
            if (cfg.AdminOnly == 0)
            {
                throw new StopProcessException();
            }
            // Admin ONLY END
            return(new CallbackMessage());
        }
        internal void CallGroups(BanUser user)
        {
            if (Temp.DisableAdminTools)
            {
                return;
            }
            if (user.Level == 1)
            {
                return;
            }
            using (var db = new BlacklistDatabaseContext())
            {
                List <GroupCfg> groupCfg = null;
                try
                {
                    groupCfg = db.GroupConfig
                               .Where(cfg => cfg.SubscribeBanList == 0)
                               .ToList();
                }
                catch (InvalidOperationException)
                {
                    return;
                }

                if (groupCfg == null)
                {
                    return;
                }

                var random = new Random();
                groupCfg = groupCfg.OrderBy(x => random.Next()).ToList();

                foreach (GroupCfg cfg in groupCfg)
                {
                    var userInChatInfo = TgApi.getDefaultApiConnection().getChatMember(cfg.GroupID, user.UserID);
                    if (userInChatInfo.ok)
                    {
                        if (userInChatInfo.result.status == "member")
                        {
                            new Thread(delegate()
                            {
                                Console.WriteLine("[SubscribeBanList] Ban " + user.UserID +
                                                  " in " + cfg.GroupID);
                                //TgApi.getDefaultApiConnection().restrictChatMember(
                                //    cfg.GroupID,
                                //    user.UserID,
                                //    GetTime.GetUnixTime() + 10,
                                //    false);
                                SendMessageResult result = TgApi.getDefaultApiConnection().sendMessage(
                                    cfg.GroupID,
                                    "使用者 : " + user.UserID + "\n" + user.GetBanMessage() +
                                    "\n\n由於開啟了 SubscribeBanList ,已嘗試自動移除。"
                                    );
                                Thread.Sleep(5000);
                                TgApi.getDefaultApiConnection()
                                .kickChatMember(cfg.GroupID, user.UserID, GetTime.GetUnixTime() + 1800);
                            }).Start();
                        }
                    }

                    Thread.Sleep(500);
                }
            }
        }
示例#8
0
        public CallbackMessage OnSupergroupCommandReceive(TgMessage RawMessage, string JsonMessage, string Command)
        {
            try
            {
                GroupCfg cfg = Temp.GetDatabaseManager().GetGroupConfig(RawMessage.chat.id);
                if (cfg.AdminOnly == 0 && TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) == false)
                {
                    return(new CallbackMessage()
                    {
                    });
                }
                if (SharedCommand(RawMessage, JsonMessage, Command))
                {
                    return(new CallbackMessage());
                }
                switch (Command)
                {
                case "/soamenable":
                    if (cfg.AdminOnly == 0 && TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) == false)
                    {
                        return new CallbackMessage()
                               {
                                   StopProcess = true
                               }
                    }
                    ;
                    new SoamManager().SoamEnable(RawMessage);
                    break;

                case "/soamdisable":
                    if (cfg.AdminOnly == 0 && TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) == false)
                    {
                        return new CallbackMessage()
                               {
                                   StopProcess = true
                               }
                    }
                    ;
                    new SoamManager().SoamDisable(RawMessage);
                    break;

                case "/__get_exception":
                    throw new Exception();

                case "/soamstat":
                case "/soamstatus":
                    if (cfg.AdminOnly == 0 && TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) == false)
                    {
                        return new CallbackMessage()
                               {
                                   StopProcess = true
                               }
                    }
                    ;
                    new SoamManager().SoamStatus(RawMessage);
                    break;

                case "/bkick":
                    if (Temp.DisableBanList)
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.chat.id,
                            "非常抱歉,当前的编译已经禁用了封禁用户的功能,请您重新下载源码并编译以启用此功能。",
                            RawMessage.message_id
                            );

                        break;
                    }
                    if (RawMessage.reply_to_message == null)
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "请回复一条消息", RawMessage.message_id);
                        return(new CallbackMessage());
                    }
                    BanUser ban = Temp.GetDatabaseManager().GetUserBanStatus(RawMessage.reply_to_message.from.id);
                    if (ban.Ban == 0)
                    {
                        if (ban.Level == 0)
                        {
                            SetActionResult bkick_result = TgApi.getDefaultApiConnection().kickChatMember(
                                RawMessage.chat.id,
                                RawMessage.reply_to_message.from.id,
                                GetTime.GetUnixTime() + 86400
                                );
                            if (bkick_result.ok)
                            {
                                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已移除", RawMessage.message_id);
                                return(new CallbackMessage());
                            }
                            else
                            {
                                TgApi.getDefaultApiConnection().sendMessage(
                                    RawMessage.chat.id,
                                    "无法移除,可能是机器人没有适当的管理员权限。",
                                    RawMessage.message_id
                                    );
                                return(new CallbackMessage());
                            }
                        }
                        else
                        {
                            TgApi.getDefaultApiConnection().sendMessage(
                                RawMessage.chat.id,
                                "无法移除,因为此用户的封禁级别没有达到要求,请您联系群组的管理员来处理。" +
                                "如果您认为这位用户将会影响大量群组,您亦可联系 @" + Temp.MainChannelName + " 提供的群组。",
                                RawMessage.message_id
                                );
                            return(new CallbackMessage());
                        }
                    }
                    else
                    {
                        TgApi.getDefaultApiConnection().sendMessage(
                            RawMessage.chat.id,
                            "无法移除,因为此用户没有被机器人列入全局封禁列表中,请您联系群组的管理员来处理。" +
                            "如果您认为这位用户将会影响大量群组,您亦可联系 @" + Temp.MainChannelName + " 提供的群组。",
                            RawMessage.message_id
                            );
                        return(new CallbackMessage());
                    }
                }
                return(new CallbackMessage());
            }
            catch (StopProcessException) { return(new CallbackMessage()
                {
                    StopProcess = true
                }); }
            catch (Exception e)
            {
                RAPI.GetExceptionListener().OnException(e, JsonMessage);
                throw e;
            }
        }
示例#9
0
 internal void CallGroups(BanUser user)
 {
     if (Temp.DisableAdminTools)
     {
         return;
     }
     if (user.Level == 1)
     {
         return;
     }
     using (var db = new BlacklistDatabaseContext())
     {
         List <GroupCfg> groupCfg = null;
         try
         {
             groupCfg = db.GroupConfig
                        .Where(cfg => cfg.SubscribeBanList == 0)
                        .ToList();
         }
         catch (InvalidOperationException)
         {
             return;
         }
         if (groupCfg == null)
         {
             return;
         }
         foreach (GroupCfg cfg in groupCfg)
         {
             var userInChatInfo = TgApi.getDefaultApiConnection().getChatMember(cfg.GroupID, user.UserID);
             if (userInChatInfo.ok)
             {
                 if (userInChatInfo.result.status == "member")
                 {
                     TgApi.getDefaultApiConnection().kickChatMember(cfg.GroupID, user.UserID, GetTime.GetUnixTime() + 86400);
                     TgApi.getDefaultApiConnection().sendMessage(
                         cfg.GroupID,
                         "新的被封禁用户:\n\n" + user.GetBanMessage() + "\n\n由于您订阅了封禁列表,已根据您的设定自动移除。"
                         );
                 }
             }
             Thread.Sleep(3000);
         }
     }
 }