Пример #1
0
        internal bool deleteWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/delwl", "").Replace(" ", "");

            ;
            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /delwl UID",
                                                            RawMessage.message_id);

                return(false);
            }

            if (UID_Value.Length == 10 && Convert.ToInt64(UID_Value) > 0)
            {
                UID_Value = "-100" + UID_Value;
            }

            if (Config.WhiteList.RemoveFromList(Convert.ToInt64(UID_Value)))
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "刪除成功 !", RawMessage.message_id);
            }
            else
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "找不到 ChatID !", RawMessage.message_id);
                return(false);
            }

            return(true);
        }
Пример #2
0
        private bool SharedCommand(TgMessage RawMessage, string JsonMessage, string Command)
        {
            if (Command == "/" + Config.CustomPrefix + "banstat")
            {
                if (Config.EnableCustomBanStat)
                {
                    return(new BanStatus().banstatus(RawMessage));
                }
            }
            switch (Command)
            {
            case "/user":
                if (Config.EnableUser)
                {
                    new UserCommand().User(RawMessage);
                }
                return(true);

            case "/lsop":
                if (Config.EnableListOP)
                {
                    new OP().lsOP(RawMessage);
                }
                return(true);

            case "/help":
                if (Config.EnableHelp)
                {
                    new Help().HelpStatus(RawMessage);
                }
                return(true);

            case "/banstat":
            case "/banstatus":
                if (Config.DisableBanList)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.chat.id,
                        "非常抱歉,目前版本已禁用封鎖用戶的功能,請聯絡管理員開啟此功能。",
                        RawMessage.message_id
                        );
                    break;
                }

                if (Config.EnableBanStat)
                {
                    new BanStatus().banstatus(RawMessage);
                }
                return(true);
                //case "/clickmetobesb"://垃圾功能,之後拔掉,希望不要爆炸!
                //    TgApi.getDefaultApiConnection().sendMessage(
                //        RawMessage.chat.id,
                //        "Success, now you are SB.",
                //        RawMessage.message_id
                //        );
                //    break;
            }

            return(new AdminCommand().AdminCommands(RawMessage, JsonMessage, Command));
        }
Пример #3
0
        private bool SharedCommands(TgMessage RawMessage, string JsonMessage, string Command)
        {
            switch (Command)
            {
            case "/getid":
                string info = "Send from:\n" + RawMessage.GetSendUser().GetUserTextInfo();
                if (RawMessage.GetForwardedFromUser() != null)
                {
                    info += "\n\nForwarded from (User):\n" + RawMessage.GetForwardedFromUser().GetUserTextInfo();
                }
                if (RawMessage.GetForwardedFromChat() != null)
                {
                    info += "\n\nForwarded from (Channel):\n" + RawMessage.GetForwardedFromChat().GetChatTextInfo();
                }
                if (RawMessage.GetReplyMessage() != null)
                {
                    info += "\n\nReply to: \n" + RawMessage.GetReplyMessage().GetSendUser().GetUserTextInfo();
                }
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, info, RawMessage.message_id);
                return(true);

            case "/help":
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    RAPI.getHelpContent(RawMessage),
                    RawMessage.message_id
                    );
                return(true);

            default:
                break;
            }
            return(false);
        }
Пример #4
0
        internal bool addWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/addwl", "").Replace(" ", "");

            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /addwl UID",
                                                            RawMessage.message_id);
                return(false);
            }

            if (UID_Value.Length == 10 && Convert.ToInt64(UID_Value) > 0)
            {
                UID_Value = "-100" + UID_Value;
            }

            if (Config.WhiteList.AddToList(Convert.ToInt64(UID_Value)))
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);
            }
            else
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已經在名單內了!", RawMessage.message_id);
                return(false);
            }

            return(true);
        }
Пример #5
0
        public void Get(TgMessage RawMessage)
        {
            int spacePath = RawMessage.text.IndexOf(" ");

            if (spacePath == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "您的输入有误,请在最后面加上规则的 ID,您可以用 /getallspamstr 查看。",
                    RawMessage.message_id,
                    ParseMode: TgApi.PARSEMODE_MARKDOWN
                    );
                return;
            }
            string             jsonText    = RawMessage.text.Substring(spacePath + 1);
            string             spamstrings = "";
            List <SpamMessage> msgs        = Temp.GetDatabaseManager().GetSpamMessageList();

            foreach (SpamMessage msg in msgs)
            {
                spamstrings += "- " + msg.FriendlyName + "\n";
            }
            if (spamstrings == "")
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "null", RawMessage.message_id);
                return;
            }
            TgApi.getDefaultApiConnection().sendMessage(
                RawMessage.GetMessageChatInfo().id,
                spamstrings,
                RawMessage.message_id
                );
        }
Пример #6
0
        internal bool deleteBlockGroup(TgMessage RawMessage)
        {
            string ChatID_Value = RawMessage.text.Replace("/unblock", "").Replace(" ", "");

            if (ChatID_Value.Length < 10)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /block ChatID",
                                                            RawMessage.message_id);
                return(false);
            }

            if (ChatID_Value.Length == 10 && Convert.ToInt64(ChatID_Value) > 0)
            {
                ChatID_Value = "-100" + ChatID_Value;
            }

            if (Config.BlockGroups.RemoveFromList(Convert.ToInt64(ChatID_Value)))
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "刪除成功 !", RawMessage.message_id);
            }
            else
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "找不到 ChatID !", RawMessage.message_id);
                return(false);
            }

            return(true);
        }
        private void CallAdmin(TgMessage msg)
        {
            GroupUserInfo[] admins = TgApi.getDefaultApiConnection().getChatAdministrators(msg.chat.id);
            string          retmsg = "";

            foreach (GroupUserInfo i in admins)
            {
                if (i.user.username != null)
                {
                    retmsg += "@" + i.user.username;
                }
                else
                {
                    string userRealName = "[NO_NAME]";
                    if (i.user.first_name != null)
                    {
                        userRealName = i.user.first_name;
                    }
                    if (i.user.last_name != null)
                    {
                        userRealName = " " + i.user.last_name;
                    }
                    retmsg += "<a href=\"tg://user?id=" + i.user.id + "\">" + userRealName + "</a>";
                }
                retmsg += " , ";
            }
            TgApi.getDefaultApiConnection().sendMessage(
                msg.chat.id,
                retmsg,
                msg.message_id
                );
        }
Пример #8
0
        internal bool addOP(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/addop", "").Replace(" ", "");

            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /addop UID",
                                                            RawMessage.message_id);

                return(false);
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            jsonObj["op_list"].Add(Convert.ToInt32(UID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);

            RAPI.reloadConfig();

            return(true);
        }
Пример #9
0
        public void SoamStatus(TgMessage message)
        {
            GroupCfg gc = Temp.GetDatabaseManager().GetGroupConfig(message.chat.id);

            TgApi.getDefaultApiConnection().sendMessage(
                message.chat.id,
                "BlackList (By @" + TgApi.getDefaultApiConnection().getMe().username + ") : " + (gc.BlackList == 0) +
                "\n" +
                "AutoKick : " + (gc.AutoKick == 0) + "\n" +
                "AntiBot : " + (gc.AntiBot == 0) + "\n" +
                "AntiHalal : " + (gc.AntiHalal == 0) + "\n" +
                "AutoDeleteSpamMessage : " + (gc.AutoDeleteSpamMessage == 0) + "\n" +
                "AutoDeleteCommand : " + (gc.AutoDeleteCommand == 0) + "\n" +
                "AdminOnly : " + (gc.AdminOnly == 0) + "\n" +
                "SubscribeBanList : " + (gc.SubscribeBanList == 0) + "\n\n" +
                "功能說明\n" +
                "1. BlackList : 黑名單使用者進群會有提示\n" +
                "2. AntiHalal : 自動封鎖無法理解的語言\n" +
                "3. Antibot : 自動踢出非管理加入的 bot 並把拉入者封鎖 1 日\n" +
                "4. AutoKick : 黑名單(封鎖)的使用者進群會自動踢出\n" +
                "5. AutoDeleteSpamMessage : 使用本服務的自動偵測規則\n" +
                "6. AdminOnly : 機器人只回應 Admin 的指令\n" +
                "7. AutoDeleteCommand : 自動刪除非 Admin 發出的指令訊息並顯示提示\n" +
                "8. SubscribeBanList : 黑名單(封鎖)中於此群組的現存使用者會被踢出\n",
                message.message_id
                );
        }
Пример #10
0
        private bool SharedCommand(TgMessage RawMessage, string JsonMessage, string Command)
        {
            switch (Command)
            {
            case "/banstat":
            case "/banstatus":
                if (Temp.DisableBanList)
                {
                    TgApi.getDefaultApiConnection().sendMessage(
                        RawMessage.chat.id,
                        "非常抱歉,当前的编译已经禁用了封禁用户的功能,请您重新下载源码并编译以启用此功能。",
                        RawMessage.message_id
                        );
                    break;
                }
                return(new BanStatus().banstatus(RawMessage));

            case "/clickmetobesb":
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.chat.id,
                    "Success, now you are SB.",
                    RawMessage.message_id
                    );
                break;
            }
            return(new AdminCommand().AdminCommands(RawMessage, JsonMessage, Command));
        }
Пример #11
0
        internal bool getHistoryStatus(TgMessage RawMessage)
        {
            if (Config.ReasonChannelID == 0)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "沒有證據頻道。");
                return(true);
            }

            int banstatSpace = RawMessage.text.IndexOf(" ");

            if (banstatSpace == -1)
            {
                if (RawMessage.reply_to_message.forward_from != null)
                {
                    BanUser ban = Config.GetDatabaseManager().GetUserBanStatus(RawMessage.reply_to_message.forward_from.id);
                    if (ban.ReasonMessageID != 0)
                    {
                        TgApi.getDefaultApiConnection().forwardMessage(RawMessage.GetMessageChatInfo().id, Config.ReasonChannelID, ban.ReasonMessageID);
                    }
                    else
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "沒有證據紀錄。");
                    }
                    return(true);
                }

                if (RawMessage.reply_to_message != null)
                {
                    BanUser ban = Config.GetDatabaseManager().GetUserBanStatus(RawMessage.reply_to_message.GetSendUser().id);
                    if (ban.ReasonMessageID != 0)
                    {
                        TgApi.getDefaultApiConnection().forwardMessage(RawMessage.GetMessageChatInfo().id, Config.ReasonChannelID, ban.ReasonMessageID);
                    }
                    else
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "沒有證據紀錄。");
                    }
                    return(true);
                }
            }

            if (int.TryParse(RawMessage.text.Substring(banstatSpace + 1), out int userid))
            {
                BanUser ban = Config.GetDatabaseManager().GetUserBanStatus(userid);
                if (ban.ReasonMessageID != 0)
                {
                    TgApi.getDefaultApiConnection().forwardMessage(RawMessage.GetMessageChatInfo().id, Config.ReasonChannelID, ban.ReasonMessageID);
                }
                else
                {
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "沒有證據紀錄。");
                }
                return(true);
            }

            TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請回覆或是輸入 UserID",
                                                        RawMessage.message_id);
            return(true);
        }
        internal bool addBlockGroup(TgMessage RawMessage)
        {
            string ChatID_Value = RawMessage.text.Replace("/block", "").Replace(" ", "");

            if (ChatID_Value.Length < 10)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /block ChatID",
                                                            RawMessage.message_id);
                return(false);
            }

            if (ChatID_Value.Length == 10 && Convert.ToInt64(ChatID_Value) > 0)
            {
                ChatID_Value = "-100" + ChatID_Value;
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["blockgroup_list"])
            {
                if (jsonObj["blockgroup_list"][i] == ChatID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已經在名單內了!", RawMessage.message_id);
                return(false);
            }

            jsonObj["blockgroup_list"].Add(Convert.ToInt64(ChatID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);
            try
            {
                TgApi.getDefaultApiConnection().sendMessage(Convert.ToInt64(ChatID_Value), "此群組禁止使用本服務。");
                TgApi.getDefaultApiConnection().leaveChat(Convert.ToInt64(ChatID_Value));
            }
            catch
            {
            }

            RAPI.reloadConfig();

            return(true);
        }
Пример #13
0
 public void reloadSpamList(TgMessage RawMessage)
 {
     Config.spamMessageList = null;
     TgApi.getDefaultApiConnection().sendMessage(
         RawMessage.GetMessageChatInfo().id,
         "已將暫存 SpamStr 清單清空",
         RawMessage.message_id
         );
 }
        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
                    );
            }
        }
Пример #15
0
        internal bool listWhitelist(TgMessage RawMessage)
        {
            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id,
                                                        "Whitelist : \n" + string.Join("\n", jsonObj["whitelist"]), RawMessage.message_id);
            return(true);
        }
Пример #16
0
 internal bool DeleteMessageCommand(TgMessage RawMessage)
 {
     if (TgApi.getDefaultApiConnection().checkIsAdmin(RawMessage.chat.id, RawMessage.from.id) ||
         RAPI.getIsBotOP(RawMessage.GetSendUser().id) || RAPI.getIsBotAdmin(RawMessage.GetSendUser().id))
     {
         TgApi.getDefaultApiConnection().deleteMessage(RawMessage.GetReplyMessage().chat.id, RawMessage.GetReplyMessage().message_id);
         return(true);
     }
     return(true);
 }
Пример #17
0
        public bool UnbanUser(
            int AdminID,
            int UserID,
            string Reason     = null,
            UserInfo userinfo = null
            )
        {
            int ChannelReasonID = 0;

            if (Temp.MainChannelID != 0)
            {
                string banmsg = "";
                if (userinfo == null)
                {
                    UserInfoRequest userinforeq = TgApi.getDefaultApiConnection().getChat(UserID);
                    if (userinforeq.ok)
                    {
                        userinfo = userinforeq.result;
                        banmsg   = userinfo.GetUserTextInfo();
                    }
                    else
                    {
                        banmsg = "User ID : " + UserID;
                    }
                }
                else
                {
                    banmsg = userinfo.GetUserTextInfo();
                }

                banmsg += "\n\n已被解除封鎖";

                if (Reason != null)
                {
                    banmsg += ",原因 : \n" + Reason;
                }

                banmsg += "\n原封鎖原因 : \n" + Temp.GetDatabaseManager().GetUserBanStatus(UserID).Reason + "\n";

                banmsg += "\nOID : " + AdminID + "\n";

                BanUser ban = Temp.GetDatabaseManager().GetUserBanStatus(UserID);
                if (ban.Ban == 1)
                {
                    return(false);
                }

                ChannelReasonID = TgApi.getDefaultApiConnection().sendMessage(Temp.MainChannelID, banmsg).result
                                  .message_id;
            }

            ChangeDbUnban(AdminID, UserID, Reason, ChannelReasonID);
            CNBlacklistApi.PostToAPI(UserID, false, 1, 0, Reason);
            return(true);
        }
Пример #18
0
        public void GetByID(TgMessage RawMessage)
        {
            int spacePath = RawMessage.text.IndexOf(" ");

            if (spacePath == -1)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "您的输入有误,请在最后面加上规则的 ID,您可以用 /getallspamstr 查看。",
                    RawMessage.message_id,
                    ParseMode: TgApi.PARSEMODE_MARKDOWN
                    );
                return;
            }
            string             name        = RawMessage.text.Substring(spacePath + 1);
            string             spamstrings = "";
            List <SpamMessage> msgs        = Temp.GetDatabaseManager().GetSpamMessageList();

            foreach (SpamMessage msg in msgs)
            {
                if (name != msg.FriendlyName)
                {
                    continue;
                }
                spamstrings += "- " + msg.FriendlyName + ":" +
                               "\n    Enabled: " + msg.Enabled +
                               "\n    Type: " + msg.Type +
                               "\n    AutoGlobalBlock: " + msg.AutoBlackList +
                               "\n    AutoDelete: " + msg.AutoDelete +
                               "\n    AutoKick: " + msg.AutoKick +
                               "\n    AutoMute: " + msg.AutoMute +
                               "\n    BanDays: " + msg.BanDays +
                               "\n    BanHours: " + msg.BanHours +
                               "\n    BanMinutes: " + msg.BanMinutes +
                               "\n    MinPoints: " + msg.MinPoints +
                               "\n    Messages: ";
                foreach (SpamMessageObj i in msg.Messages)
                {
                    spamstrings += "\n    - Message: " + TgApi.getDefaultApiConnection().jsonEncode(i.Message) +
                                   "\n      Point: " + i.Point;
                }
                spamstrings += "\n\n";
            }
            if (spamstrings == "")
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "null", RawMessage.message_id);
                return;
            }
            TgApi.getDefaultApiConnection().sendMessage(
                RawMessage.GetMessageChatInfo().id,
                spamstrings,
                RawMessage.message_id
                );
        }
        internal bool deleteWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/delwl", "").Replace(" ", "");

            ;
            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /delwl UID",
                                                            RawMessage.message_id);

                return(false);
            }

            if (UID_Value.Length == 10 && Convert.ToInt64(UID_Value) > 0)
            {
                UID_Value = "-100" + UID_Value;
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["whitelist"])
            {
                if (jsonObj["whitelist"][i] == UID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                jsonObj["whitelist"].Remove(jsonObj["whitelist"][i]);
                string output =
                    JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                File.WriteAllText("config.json", output);
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "刪除成功!", RawMessage.message_id);

                RAPI.reloadConfig();
            }
            else
            {
                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.chat.id, "找不到User!", RawMessage.message_id);
            }

            return(true);
        }
        internal bool Groups(TgMessage RawMessage)
        {
            using (var db = new BlacklistDatabaseContext())
            {
                string          groups   = "";
                List <GroupCfg> groupCfg = null;
                try
                {
                    groupCfg = db.GroupConfig.ToList();
                }
                catch (InvalidOperationException)
                {
                    return(false);
                }

                if (groupCfg == null)
                {
                    return(false);
                }
                foreach (GroupCfg cfg in groupCfg)
                {
                    string groupInfo = "無法取得";
                    try
                    {
                        groupInfo = TgApi.getDefaultApiConnection().getChatInfo(cfg.GroupID).result.GetChatTextInfo();
                    }
                    catch
                    {
                    }

                    groups = groups + cfg.GroupID + " : \n" + RAPI.escapeMarkdown(groupInfo) + "\n\n";

                    if (groups.Length > 3072)
                    {
                        TgApi.getDefaultApiConnection()
                        .sendMessage(RawMessage.chat.id, groups, ParseMode: TgApi.PARSEMODE_MARKDOWN);
                        groups = "";
                        Thread.Sleep(3000);
                    }
                }

                if (groups.Length > 0)
                {
                    TgApi.getDefaultApiConnection()
                    .sendMessage(RawMessage.chat.id, groups, ParseMode: TgApi.PARSEMODE_MARKDOWN);
                }

                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.chat.id, "Groups 輸出完畢!", RawMessage.message_id);
            }

            return(true);
        }
Пример #21
0
        public void GetAllInfo(TgMessage RawMessage)
        {
            string             spamstrings = "";
            List <SpamMessage> msgs        = Config.GetDatabaseManager().GetSpamMessageList();

            foreach (SpamMessage msg in msgs)
            {
                spamstrings += "- " + msg.FriendlyName + ":" +
                               "\n    Enabled: " + msg.Enabled +
                               "\n    Type: " + msg.Type +
                               "\n    AutoGlobalBlock: " + msg.AutoBlackList +
                               "\n    AutoDelete: " + msg.AutoDelete +
                               "\n    AutoKick: " + msg.AutoKick +
                               "\n    AutoMute: " + msg.AutoMute +
                               "\n    BanDays: " + msg.BanDays +
                               "\n    BanHours: " + msg.BanHours +
                               "\n    BanMinutes: " + msg.BanMinutes +
                               "\n    MinPoints: " + msg.MinPoints +
                               "\n    Messages: ";
                foreach (SpamMessageObj i in msg.Messages)
                {
                    spamstrings += "\n    - Message: " + TgApi.getDefaultApiConnection().jsonEncode(i.Message) +
                                   "\n      Point: " + i.Point;
                }
                spamstrings += "\n\n";
            }

            if (spamstrings == "")
            {
                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.GetMessageChatInfo().id, "null", RawMessage.message_id);
                return;
            }

            var spamlist = new List <string>();

            for (var i = 0; i < spamstrings.Length; i += 4000)
            {
                spamlist.Add(spamstrings.Substring(i, Math.Min(4000, spamstrings.Length - i)));
            }

            foreach (string msg in spamlist)
            {
                TgApi.getDefaultApiConnection().sendMessage(
                    RawMessage.GetMessageChatInfo().id,
                    "<code>" + msg + "</code>",
                    RawMessage.message_id,
                    TgApi.PARSEMODE_HTML
                    );
            }
        }
        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);
        }
Пример #23
0
        public void SoamStatus(TgMessage message)
        {
            GroupCfg gc = Temp.GetDatabaseManager().GetGroupConfig(message.chat.id);

            TgApi.getDefaultApiConnection().sendMessage(
                message.chat.id,
                "BlackList (by @CNBlackListR ): " + (gc.BlackList == 0) + "\n" +
                "AutoKick: " + (gc.AutoKick == 0) + "\n" +
                "AutoDeleteSpamMessage: " + (gc.AutoDeleteSpamMessage == 0) + "\n" +
                "AutoDeleteCommand: " + (gc.AutoDeleteCommand == 0) + "\n" +
                "AdminOnly: " + (gc.AdminOnly == 0) + "\n" +
                "SubscribeBanList: " + (gc.SubscribeBanList == 0),
                message.message_id
                );
            return;
        }
        internal bool BC(TgMessage RawMessage, string Msg)
        {
            TgApi.getDefaultApiConnection()
            .sendMessage(RawMessage.chat.id, "傳送中.........!", RawMessage.message_id);
            Console.WriteLine("Broadcasting " + Msg + " ......");
            using (var db = new BlacklistDatabaseContext())
            {
                string          groups   = "";
                List <GroupCfg> groupCfg = null;
                try
                {
                    groupCfg = db.GroupConfig.ToList();
                }
                catch (InvalidOperationException)
                {
                    return(false);
                }

                if (groupCfg == null)
                {
                    return(false);
                }
                foreach (GroupCfg cfg in groupCfg)
                {
                    Console.WriteLine("Broadcasting " + Msg + " to group ChatID : " + cfg.GroupID);

                    SendMessageResult result = TgApi.getDefaultApiConnection()
                                               .sendMessage(cfg.GroupID, Msg, ParseMode: TgApi.PARSEMODE_MARKDOWN);

                    if (result.ok)
                    {
                        groups = groups + "\n" + cfg.GroupID + " : 成功";
                    }
                    else
                    {
                        groups = groups + "\n" + cfg.GroupID + " : 失敗";
                    }

                    Thread.Sleep(500);
                }

                TgApi.getDefaultApiConnection()
                .sendMessage(RawMessage.chat.id, "有夠Highㄉ,傳送完畢!" + groups, RawMessage.message_id);
            }

            return(true);
        }
        internal bool User(TgMessage RawMessage)
        {
            if (RawMessage.text.ToLower().Contains("username"))
            {
                if (RawMessage.reply_to_message != null)
                {
                    if (RawMessage.reply_to_message.forward_from != null)
                    {
                        TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                    "`" + RawMessage.reply_to_message.forward_from.username + "`", RawMessage.message_id,
                                                                    ParseMode: TgApi.PARSEMODE_MARKDOWN);
                        return(true);
                    }

                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                "`" + RawMessage.reply_to_message.GetSendUser().username + "`", RawMessage.message_id,
                                                                ParseMode: TgApi.PARSEMODE_MARKDOWN);
                    return(true);
                }

                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                            "`" + RawMessage.GetSendUser().username + "`", RawMessage.message_id,
                                                            ParseMode: TgApi.PARSEMODE_MARKDOWN);
                return(true);
            }

            if (RawMessage.reply_to_message != null)
            {
                if (RawMessage.reply_to_message.forward_from != null)
                {
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                                "`" + RawMessage.reply_to_message.forward_from.id.ToString() + "`", RawMessage.message_id,
                                                                ParseMode: TgApi.PARSEMODE_MARKDOWN);
                    return(true);
                }

                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                            "`" + RawMessage.reply_to_message.GetSendUser().id.ToString() + "`", RawMessage.message_id,
                                                            ParseMode: TgApi.PARSEMODE_MARKDOWN);
                return(true);
            }

            TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id,
                                                        "`" + RawMessage.GetSendUser().id.ToString() + "`", RawMessage.message_id,
                                                        ParseMode: TgApi.PARSEMODE_MARKDOWN);
            return(true);
        }
Пример #26
0
        internal bool banstatus(TgMessage RawMessage)
        {
            int banstatSpace = RawMessage.text.IndexOf(" ");

            if (banstatSpace == -1)
            {
                string  banmsg = "";
                BanUser ban;
                ban    = Temp.GetDatabaseManager().GetUserBanStatus(RawMessage.GetSendUser().id);
                banmsg = "发送者:\n" + RawMessage.GetSendUser().GetUserTextInfo() + "\n\n" + ban.GetBanMessage();
                if (ban.Ban == 0)
                {
                    banmsg += "\n\n对于被封禁的用户,您可以通过 [点击这里](https://t.me/CNBlackListBot?start=soam_req_unban) 以请求解封。";
                }
                if (RawMessage.reply_to_message != null)
                {
                    ban     = Temp.GetDatabaseManager().GetUserBanStatus(RawMessage.reply_to_message.GetSendUser().id);
                    banmsg += "\n\n------\n\n被回复的消息的原发送用户:\n" +
                              RawMessage.reply_to_message.GetSendUser().GetUserTextInfo() + "\n\n" +
                              ban.GetBanMessage();
                    if (RawMessage.reply_to_message.forward_from != null)
                    {
                        ban     = Temp.GetDatabaseManager().GetUserBanStatus(RawMessage.reply_to_message.forward_from.id);
                        banmsg += "\n\n------\n\n被回复的消息转发自用户:\n" +
                                  RawMessage.reply_to_message.forward_from.GetUserTextInfo() + "\n\n" +
                                  ban.GetBanMessage();
                    }
                }
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, banmsg, RawMessage.message_id);
                return(true);
            }
            else
            {
                if (int.TryParse(RawMessage.text.Substring(banstatSpace + 1), out int userid))
                {
                    BanUser ban = Temp.GetDatabaseManager().GetUserBanStatus(userid);
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "这位用户" + ban.GetBanMessage(), RawMessage.message_id);
                    return(true);
                }
                else
                {
                    TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "您的输入有误,请输入正确的 UID", RawMessage.message_id);
                    return(true);
                }
            }
        }
Пример #27
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);
         }
     }
 }
        internal bool addHKWhitelist(TgMessage RawMessage)
        {
            string UID_Value = RawMessage.text.Replace("/addhk", "").Replace(" ", "");

            if (UID_Value.Length < 5)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "使用方法 : /addhk UID",
                                                            RawMessage.message_id);
                return(false);
            }

            string  json    = File.ReadAllText("config.json");
            dynamic jsonObj = JsonConvert.DeserializeObject(json);

            int  i     = 0;
            bool found = false;

            foreach (var item in jsonObj["hk_whitelist"])
            {
                if (jsonObj["hk_whitelist"][i] == UID_Value)
                {
                    found = true;
                    break;
                }

                i = i + 1;
            }

            if (found)
            {
                TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "已經在名單內了!", RawMessage.message_id);
                return(false);
            }

            jsonObj["hk_whitelist"].Add(Convert.ToInt64(UID_Value));
            string output =
                JsonConvert.SerializeObject(jsonObj, Formatting.Indented);

            File.WriteAllText("config.json", output);
            TgApi.getDefaultApiConnection().sendMessage(RawMessage.chat.id, "新增成功!", RawMessage.message_id);

            RAPI.reloadConfig();

            return(true);
        }
        public bool UnbanUser(
            int AdminID,
            int UserID,
            string Reason     = null,
            UserInfo userinfo = null
            )
        {
            bool finalResult     = true;
            int  ChannelReasonID = 0;

            if (Temp.MainChannelID != 0)
            {
                string banmsg = "";
                if (userinfo == null)
                {
                    UserInfoRequest userinforeq = TgApi.getDefaultApiConnection().getChat(UserID);
                    if (userinforeq.ok)
                    {
                        userinfo = userinforeq.result;
                        banmsg   = userinfo.GetUserTextInfo();
                    }
                    else
                    {
                        finalResult = false;
                        banmsg      = "User ID: " + UserID;
                    }
                }
                else
                {
                    banmsg = userinfo.GetUserTextInfo();
                }
                banmsg += "\n\n已被解封";
                if (Reason != null)
                {
                    banmsg += ",原因是:\n" + Reason;
                }
                ChannelReasonID = TgApi.getDefaultApiConnection().sendMessage(
                    Temp.MainChannelID,
                    banmsg
                    ).result.message_id;
            }
            ChangeDbUnban(AdminID, UserID, Reason, ChannelReasonID);
            CNBlacklistApi.PostToAPI(UserID, false, 1, 0, Reason);
            return(finalResult);
        }
Пример #30
0
        internal bool Leave(TgMessage RawMessage)
        {
            int saySpace = RawMessage.text.IndexOf(" ");

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

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

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

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

                return(true);
            }

            TgApi.getDefaultApiConnection().sendMessage(RawMessage.GetMessageChatInfo().id, "您並不是群組管理或是 Bot 管理員",
                                                        RawMessage.message_id);
            return(true);
        }