Esempio n. 1
0
        internal string getHelpContent(TgMessage RawMessage, string MessageType)
        {
            if (helpObjects == null)
            {
                return("");
            }
            string helpmsg = "";

            foreach (CallablePlugin plugin in helpObjects)
            {
                try
                {
                    if (RAPI.getIsDebugEnv())
                    {
                        Console.WriteLine("Message Caller : GetHelpMessage");
                    }
                    object helpobj = plugin.callPlugin("GetHelpMessage", new object[] { RawMessage, MessageType });
                    if (helpobj != null)
                    {
                        helpmsg += (string)helpobj;
                    }
                }
                catch (NotImplementedException)
                {
                }
            }

            return(helpmsg);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
        }
Esempio n. 4
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
                );
        }
        internal long GetGroupID(Dictionary <string, string> banValues, TgMessage RawMessage)
        {
            string GroupID = "";

            GroupID = banValues.GetValueOrDefault("g", "__invalid__");
            if (GroupID == "__invalid__")
            {
                GroupID = banValues.GetValueOrDefault("group", "__invalid__");
            }
            if (GroupID == "__invalid__")
            {
                GroupID = banValues.GetValueOrDefault("groupid", "__invalid__");
            }
            if (GroupID == "__invalid__")
            {
                return(0);
            }
            long id = 0;

            if (long.TryParse(GroupID, out id))
            {
                return(id);
            }
            return(0);
        }
Esempio n. 6
0
        internal static string getHelpMessage(List<PluginObject> plugins, TgMessage RawMessage, string MessageType)
        {
            if (RAPI.getIsDebugEnv()) Console.WriteLine("Message Caller : PluginsCaller -> getHelpMessage");
            string msg = "";
            foreach (PluginObject pl in plugins)
            {
                string pluginhelpmsg = null;
                try
                {
                    pluginhelpmsg = pl.getHelpContent(RawMessage, MessageType);
                }
                catch (NotImplementedException)
                {
                }
                catch (Exception e)
                {
                    RAPI.GetExceptionListener().OnException(e);
                }

                if (pluginhelpmsg != null || pluginhelpmsg != "")
                    msg += "Plugin: " + pl.PluginName + "\n" + pluginhelpmsg + "\n\n";
            }

            return msg;
        }
        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
                );
        }
Esempio n. 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);
        }
Esempio n. 9
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
                );
        }
        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);
        }
        public string GetHelpMessage(TgMessage RawMessage, string MessageType)
        {
            string finalHelpMsg;
            string groupHelp = "/soamenable - 启用一个功能\n" +
                               "/soamdisable - 禁用一个功能\n" +
                               "/soamstatus - 查看当前群组开启了的功能\n" +
                               "/bkick - 将一个已在封禁列表中的用户从群组中移除出去";
            string privateHelp = "";
            string sharedHelp  = "/banstat - 看看自己有没有被 Ban";

            switch (MessageType)
            {
            case "group":
            case "supergroup":
                finalHelpMsg = groupHelp + "\n" + sharedHelp;
                break;

            case "private":
                finalHelpMsg = privateHelp + "\n" + sharedHelp;
                break;

            default:
                finalHelpMsg = sharedHelp;
                break;
            }
            if (RAPI.getIsBotAdmin(RawMessage.from.id))
            {
                finalHelpMsg += "\n管理员指令: /ban /unban /getspamstr /addspamstr /delspamstr /getspampoints";
            }
            return(finalHelpMsg);
        }
        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);
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
        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);
        }
Esempio n. 16
0
 public CallbackMessage OnGroupCommandReceive(TgMessage RawMessage, string JsonMessage, string Command)
 {
     if (SharedCommands(RawMessage, JsonMessage, Command))
     {
         return(new CallbackMessage());
     }
     return(new CallbackMessage());
 }
        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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public void reloadSpamList(TgMessage RawMessage)
 {
     Config.spamMessageList = null;
     TgApi.getDefaultApiConnection().sendMessage(
         RawMessage.GetMessageChatInfo().id,
         "已將暫存 SpamStr 清單清空",
         RawMessage.message_id
         );
 }
Esempio n. 20
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);
 }
Esempio n. 21
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 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);
        }
        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 int[] GetUserIDs(Dictionary <string, string> banValues, TgMessage RawMessage)
        {
            string tmpString = "";

            tmpString = banValues.GetValueOrDefault("i", "__invalid__");
            if (tmpString == "__invalid__")
            {
                tmpString = banValues.GetValueOrDefault("id", "__invalid__");
            }
            int[] users = Array.ConvertAll(tmpString.Split(","), int.Parse);

            return(users);
        }
Esempio n. 25
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 string GetText(Dictionary <string, string> banValues, TgMessage RawMessage)
        {
            string Text = "";

            Text = banValues.GetValueOrDefault("t", "__invalid__");
            if (Text == "__invalid__")
            {
                Text = banValues.GetValueOrDefault("text", "__invalid__");
            }
            if (Text == "__invalid__")
            {
                return(null);
            }
            return(Text);
        }
        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);
        }
Esempio n. 28
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 UserInfo GetUserInfo(TgMessage RawMessage, string from)
 {
     if (RawMessage.reply_to_message == null)
     {
         return(null);
     }
     if (from == "r" || from == "reply")
     {
         return(RawMessage.GetReplyMessage().GetSendUser());
     }
     if (from == "f" || from == "fwd")
     {
         return(RawMessage.GetReplyMessage().GetForwardedFromUser());
     }
     return(null);
 }
        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);
        }