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(2000);
                        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, true, 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, true, 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());
        }
Beispiel #2
0
        public CallbackMessage OnSupergroupCommandReceive(TgMessage RawMessage, string JsonMessage, string Command)
        {
            try
            {
                GroupCfg cfg = Temp.GetDatabaseManager().GetGroupConfig(RawMessage.chat.id);
                if (cfg.AdminOnly == 0)
                {
                    if (TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) ||
                        RAPI.getIsBotAdmin(RawMessage.from.id) || RAPI.getIsBotOP(RawMessage.from.id))
                    {
                    }
                    else
                    {
                        if (cfg.AutoDeleteCommand == 0)
                        {
                            new Thread(delegate()
                            {
                                SendMessageResult autodeletecommandsendresult = TgApi.getDefaultApiConnection()
                                                                                .sendMessage(
                                    RawMessage.GetMessageChatInfo().id,
                                    "請您不要亂玩機器人的指令,有問題請聯絡群組管理員。"
                                    );
                                Thread.Sleep(60000);
                                TgApi.getDefaultApiConnection().deleteMessage(
                                    autodeletecommandsendresult.result.chat.id,
                                    autodeletecommandsendresult.result.message_id
                                    );
                            }).Start();
                            TgApi.getDefaultApiConnection().deleteMessage(RawMessage.chat.id, RawMessage.message_id);
                        }

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

                if (SharedCommand(RawMessage, JsonMessage, Command))
                {
                    return(new CallbackMessage());
                }
                switch (Command)
                {
                case "/leave":
                    new LeaveCommand().Leave(RawMessage);
                    break;

                case "/soamenable":
                    new SoamManager().SoamEnable(RawMessage);
                    break;

                case "/soamdisable":
                    new SoamManager().SoamDisable(RawMessage);
                    break;

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

                case "/soamstat":
                case "/soamstatus":
                    new SoamManager().SoamStatus(RawMessage);
                    break;
                    //case "/cnkick":
                    //    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;
            }
        }