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); }
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); }
internal bool UnbanMulti(TgMessage RawMessage) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/suunban [i|id=1,2,3] [f|from=f|fwd|r|reply]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "from 選項僅在 id 未被定義時起作用\n" + "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" + "選項優先度: 簡寫 > 全名\n" + "Example:\n" + "/suunban id=1 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/suunban", RawMessage.message_id ); return(true); } int[] UsersArray = { }; bool status = false; int BanUserId = 0; string Reason; try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1)); // 获取使用者信息 UsersArray = new GetValues().GetUserIDs(banValues, RawMessage); Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 則代表出现了异常 } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /suunban 取得幫助 err10", RawMessage.message_id ); return(true); } new Thread(delegate() { foreach (int userid in UsersArray) { BanUserId = userid; try { status = Temp.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, Reason ); } catch (InvalidOperationException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作失敗,這位使用者(" + BanUserId + ")目前可能没有被封鎖。", RawMessage.message_id ); } Thread.Sleep(3500); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} }).Start(); return(true); }
internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.BAN_HELP_MESSAGE, RawMessage.message_id ); return(true); } int BanUserId = 0; long ExpiresTime = 0; int Level = 0; string Reason = ""; UserInfo BanUserInfo = null; string value = RawMessage.text.Substring(banSpace + 1); int valLen = value.Length; bool notCommonBan = true; int commandBanLength = 0; int banDay = 0; if (valLen > 3) { if (valLen == 4) { if (value.Substring(0, 4) == "spam") { commandBanLength = 4; Reason = Strings.SPAM; banDay = Config.DefaultSpamBanDay; notCommonBan = false; } //if (value.Substring(0, 4) == "coin") //{ // commandBanLength = 4; // Reason = Strings.COIN; // banDay = Config.DefaultCoinBanDay; // notCommonBan = false; //} } if (valLen == 5) { if (value.Substring(0, 5) == "halal") { commandBanLength = 5; Reason = Strings.HALAL; banDay = Config.DefaultHalalBanDay; notCommonBan = false; } } //if(valLen == 6) // if (value.Substring(0, 6) == "innsfw") // { // commandBanLength = 6; // Reason = Strings.INNSFW; // banDay = Config.DefaultInNsfwBanDay; // notCommonBan = false; // } //if (valLen == 7) //{ // if (value.Substring(0, 7) == "spammer") // { // commandBanLength = 7; // Reason = Strings.SPAMMER; // banDay = Config.DefaultSpammerBanDay; // notCommonBan = false; // } // if (value.Substring(0, 7) == "outnsfw") // { // commandBanLength = 7; // Reason = Strings.OUTNSFW; // banDay = Config.DefaultOutNsfwBanDay; // notCommonBan = false; // } // if (value.Substring(0, 7) == "crawler") // { // commandBanLength = 7; // Reason = Strings.CRAWLER; // banDay = Config.DefaultCrawlerBanDay; // notCommonBan = false; // } //} if (banDay > 0) { ExpiresTime = GetTime.GetUnixTime() + (banDay * 86400); } } if (!notCommonBan) { if (valLen > (commandBanLength + 1)) { if (value[commandBanLength] != ' ') { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.BAN_ERROR_MESSAGE + " err_a1", RawMessage.message_id ); return(true); } UserInfo tmpUinfo = new GetValues().GetByTgMessage( new Dictionary <string, string> { { "from", value.Substring(6) } }, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null && tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string>(), RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } } } if (notCommonBan) { try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value); string tmpString = ""; // 获取使用者信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } // 获取 ExpiresTime long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage); if (tmpExpiresTime == -1) { return(true); // 如果过期时间是 -1 则代表出现了异常 } ExpiresTime = tmpExpiresTime; // 获取 Level tmpString = banValues.GetValueOrDefault("l", "__invalid__"); if (tmpString == "__invalid__") { tmpString = banValues.GetValueOrDefault("level", "0"); } if (!int.TryParse(tmpString, out Level)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.BAN_ERROR_MESSAGE + " err8", RawMessage.message_id ); return(true); } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } if (Reason.ToLower() == "halal") { Reason = Strings.HALAL; } if (Reason.ToLower() == "spam") { Reason = Strings.SPAM; } // if (Reason.ToLower() == "spammer") Reason = Strings.SPAMMER; // if (Reason.ToLower() == "innsfw") Reason = Strings.INNSFW; // if (Reason.ToLower() == "outnsfw") Reason = Strings.OUTNSFW; // if (Reason.ToLower() == "coin") Reason = Strings.COIN; // if (Reason.ToLower() == "crawler") Reason = Strings.CRAWLER; } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.BAN_ERROR_MESSAGE + " err10", RawMessage.message_id ); return(true); } } if (Config.GetIsInWhiteList(BanUserId)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_FAIL + Strings.BAN_ERROR_USER_IN_WHITELIST, RawMessage.message_id ); return(false); } int AdminID = RawMessage.GetSendUser().id; if (RawMessage.GetMessageChatInfo().id == Config.InternGroupID) { AdminID = 1; } bool status; if (BanUserInfo == null) { status = Config.GetDatabaseManager().BanUser( AdminID, BanUserId, Level, ExpiresTime, RAPI.escapeMarkdown(Reason) ); } else if (RawMessage.GetReplyMessage().new_chat_member != null) { status = Config.GetDatabaseManager().BanUser( AdminID, BanUserId, Level, ExpiresTime, RAPI.escapeMarkdown(Reason), 0, 0, BanUserInfo ); } else { status = Config.GetDatabaseManager().BanUser( AdminID, BanUserId, Level, ExpiresTime, RAPI.escapeMarkdown(Reason), RawMessage.GetMessageChatInfo().id, RawMessage.GetReplyMessage().message_id, BanUserInfo ); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_OK, RawMessage.message_id ); return(true); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Config.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} //return false; }
internal bool Unban(TgMessage RawMessage) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/unban [i|id=1] [f|from=f|fwd|r|reply]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "from 选项仅在 id 未被定义时起作用\n" + "ID 选择优先级: 手动输入的 ID > 回复的被转发消息 > 回复的消息\n" + "选项优先级: 简写 > 全名\n" + "Example:\n" + "/unban id=1 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/unban", RawMessage.message_id ); return(true); } int BanUserId = 0; string Reason; UserInfo BanUserInfo = null; try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1)); // 获取用户信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到用户信息则代表出现了异常 } else { BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的输入有误,请检查您的输入,请使用 /ban 来查看帮助 err10", RawMessage.message_id ); return(true); } bool status; try { if (BanUserInfo == null) { status = Temp.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, Reason ); } else { status = Temp.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, Reason, BanUserInfo ); } } catch (System.InvalidOperationException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作失败,这位用户目前可能没有被 Ban。", RawMessage.message_id ); return(true); } if (status) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); return(true); } else { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。\n\n请注意:转发用户消息到频道或发送用户信息到频道失败,请您手动发送至 @" + Temp.MainChannelName + " 。 err11", RawMessage.message_id ); return(true); } //return false; }
internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/cnban [i|id=1] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "m: 分鐘, h: 小時, d: 天\n" + "from 選項僅在 id 未被定義時起作用\n" + "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" + "選項優先度: 簡寫 > 全名\n" + "halal 選項只能單獨使用,不能與其他選項共同使用,並且需要回覆一則訊息,否則將觸發異常。\n\n" + "Example:\n" + "/cnban id=1 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/cnban halal\n" + "/cnban halal=reply", RawMessage.message_id ); return(true); } int BanUserId = 0; long ExpiresTime = 0; int Level = 0; string Reason = ""; UserInfo BanUserInfo = null; string value = RawMessage.text.Substring(banSpace + 1); int valLen = value.Length; bool NotHalal = true; if (valLen >= 5) { if (value.Substring(0, 5) == "halal") { NotHalal = false; Reason = "無法理解的語言"; if (valLen > 6) { if (value[5] != ' ') { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助。 err_a1", RawMessage.message_id ); return(true); } UserInfo tmpUinfo = new GetValues().GetByTgMessage( new Dictionary <string, string> { { "from", value.Substring(6) } }, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null && tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string>(), RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } } } } if (NotHalal) { try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value); string tmpString = ""; // 获取使用者信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息则代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } // 获取 ExpiresTime long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage); if (tmpExpiresTime == -1) { return(true); // 如果过期时间是 -1 则代表出现了异常 } ExpiresTime = tmpExpiresTime; // 获取 Level tmpString = banValues.GetValueOrDefault("l", "__invalid__"); if (tmpString == "__invalid__") { tmpString = banValues.GetValueOrDefault("level", "0"); } if (!int.TryParse(tmpString, out Level)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助。 err8", RawMessage.message_id ); return(true); } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } if (Reason.ToLower() == "halal") { Reason = "無法理解的語言"; } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /cnban 查詢幫助 err10", RawMessage.message_id ); return(true); } } if (RAPI.getIsInWhitelist(BanUserId)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作失敗 : 使用者在白名單", RawMessage.message_id ); return(false); } bool status; if (RawMessage.GetMessageChatInfo().id == Temp.InternGroupID && RawMessage.GetReplyMessage().GetSendUser().id == TgApi.getDefaultApiConnection().getMe().id) { status = Temp.GetDatabaseManager().BanUser( 1, BanUserId, Level, ExpiresTime, Reason, RawMessage.GetMessageChatInfo().id, RawMessage.GetReplyMessage().message_id, BanUserInfo ); } else if (BanUserInfo == null) { status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason ); } else if (RawMessage.GetReplyMessage().new_chat_member != null) { status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason, 0, 0, BanUserInfo ); } else { status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason, RawMessage.GetMessageChatInfo().id, RawMessage.GetReplyMessage().message_id, BanUserInfo ); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); return(true); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} //return false; }
internal bool Ban(TgMessage RawMessage, string JsonMessage, string Command) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/ban [i|id=1] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "m: 分钟, h: 小时, d: 天\n" + "from 选项仅在 id 未被定义时起作用\n" + "ID 选择优先级: 手动输入的 ID > 回复的被转发消息 > 回复的消息\n" + "选项优先级: 简写 > 全名\n" + "halal 选项只能单独使用,不能与其他选项共同使用,并且需要回复一条消息,否则将会触发异常。\n\n" + "Example:\n" + "/ban id=1 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/ban halal\n" + "/ban halal=reply", RawMessage.message_id ); return(true); } int BanUserId = 0; long ExpiresTime = 0; int Level = 0; string Reason = ""; UserInfo BanUserInfo = null; string value = RawMessage.text.Substring(banSpace + 1); int valLen = value.Length; bool NotHalal = true; if (valLen >= 5) { if (value.Substring(0, 5) == "halal") { NotHalal = false; Reason = "Halal (中国人无法识别的语言)"; if (valLen > 6) { if (value[5] != ' ') { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的输入有误,请检查您的输入,或使用 /ban 查看帮助。 err_a1", RawMessage.message_id ); return(true); } UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string> { { "from", value.Substring(6) } }, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到用户信息则代表出现了异常 } else { BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null && tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } } else { UserInfo tmpUinfo = new GetValues().GetByTgMessage(new Dictionary <string, string> { }, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到用户信息则代表出现了异常 } else { BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } } } } } if (NotHalal) { try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value); string tmpString = ""; // 获取用户信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到用户信息则代表出现了异常 } else { BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } } // 获取 ExpiresTime long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage); if (tmpExpiresTime == -1) { return(true); // 如果过期时间是 -1 则代表出现了异常 } else { ExpiresTime = tmpExpiresTime; } // 获取 Level tmpString = banValues.GetValueOrDefault("l", "__invalid__"); if (tmpString == "__invalid__") { tmpString = banValues.GetValueOrDefault("level", "0"); } if (!int.TryParse(tmpString, out Level)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的输入有误,请检查您的输入,或使用 /ban 查看帮助。 err8", RawMessage.message_id ); return(true); } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } if (Reason.ToLower() == "halal") { Reason = "Halal (中国人无法识别的语言)"; } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的输入有误,请检查您的输入,请使用 /ban 来查看帮助 err10", RawMessage.message_id ); return(true); } } bool status; if (BanUserInfo == null) { status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason ); } else { status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason, RawMessage.GetMessageChatInfo().id, RawMessage.GetReplyMessage().message_id, BanUserInfo ); } if (status) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); return(true); } else { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。\n\n请注意:转发用户消息到频道或发送用户信息到频道失败,请您手动发送至 @" + Temp.MainChannelName + " 。 err11", RawMessage.message_id ); return(true); } //return false; }
internal bool BanMulti(TgMessage RawMessage, string JsonMessage, string Command) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/suban [i|id=1,2,3] [l|level=0] [m|minutes=0] [h|hours=0] [d|days=15] [f|from=f|fwd|r|reply] [halal [f|fwd|r|reply]]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "m: 分鐘, h: 小時, d: 天\n" + "from 選項僅在 id 未被定義時起作用\n" + "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" + "選項優先度: 簡寫 > 全名\n" + "halal 選項只能單獨使用,不能與其他選項共同使用,並且需要回覆一則訊息,否則將觸發異常。\n\n" + "Example:\n" + "/suban id=1,2,3 m=0 h=0 d=15 level=0 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/suban halal\n" + "/suban halal=reply", RawMessage.message_id ); return(true); } int BanUserId = 0; int[] UsersArray = { }; long ExpiresTime = 0; int Level = 0; string Reason = ""; string value = RawMessage.text.Substring(banSpace + 1); int valLen = value.Length; bool NotHalal = true; bool status = false; if (valLen >= 5) { if (value.Substring(0, 5) == "halal") { NotHalal = false; Reason = "無法理解的語言"; if (valLen > 6) { if (value[5] != ' ') { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助。 err_a1", RawMessage.message_id ); return(true); } UsersArray = new GetValues().GetUserIDs(new Dictionary <string, string> { { "from", value.Substring(6) } }, RawMessage); } else { UsersArray = new GetValues().GetUserIDs(new Dictionary <string, string>(), RawMessage); } } } if (NotHalal) { try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value); string tmpString = ""; // 获取使用者 UsersArray = new GetValues().GetUserIDs(banValues, RawMessage); // 获取 ExpiresTime long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage); if (tmpExpiresTime == -1) { return(true); // 如果过期时间是 -1 则代表出现了异常 } ExpiresTime = tmpExpiresTime; // 获取 Level tmpString = banValues.GetValueOrDefault("l", "__invalid__"); if (tmpString == "__invalid__") { tmpString = banValues.GetValueOrDefault("level", "0"); } if (!int.TryParse(tmpString, out Level)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助。 err8", RawMessage.message_id ); return(true); } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } if (Reason.ToLower() == "halal") { Reason = "無法理解的語言"; } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /suban 查詢幫助 err10", RawMessage.message_id ); return(true); } } new Thread(delegate() { foreach (int userid in UsersArray) { BanUserId = userid; status = Temp.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, Reason ); if (RAPI.getIsInWhitelist(BanUserId)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetSendUser().id, "操作失敗 : 使用者在白名單 UID" + BanUserId, RawMessage.message_id ); } Thread.Sleep(3500); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} //return false; }).Start(); return(true); }
internal bool Unban(TgMessage RawMessage) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/cnunban [i|id=1] [f|from=f|fwd|r|reply]" + " r|reason=\"asdfsadf asdfadsf\"\n\n" + "from 選項僅在 id 未被定義時起作用\n" + "ID 選擇優先度: 手動輸入 ID > 回覆的被轉發訊息 > 回覆的訊息\n" + "選項優先度: 簡寫 > 全名\n" + "Example:\n" + "/cnunban id=1 reason=\"aaa bbb\\n\\\"ccc\\\" ddd\"\n" + "/cnunban", RawMessage.message_id ); return(true); } int BanUserId = 0; string Reason; UserInfo BanUserInfo = null; try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1)); // 获取使用者信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息則代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 則代表出现了异常 } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的輸入有錯誤,請檢查您的輸入,或使用 /ban 取得幫助 err10", RawMessage.message_id ); return(true); } new UnBanCaller().UnBanCallerThread(BanUserId); bool status; try { if (BanUserInfo == null) { status = Temp.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, Reason ); } else { status = Temp.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, Reason, BanUserInfo ); } } catch (InvalidOperationException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作失敗,這位使用者目前可能没有被封鎖。", RawMessage.message_id ); return(true); } if (status) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作成功。", RawMessage.message_id ); if (RawMessage.GetMessageChatInfo().id == Temp.CourtGroupID) { TgApi.getDefaultApiConnection() .kickChatMember(RawMessage.GetMessageChatInfo().id, BanUserId, GetTime.GetUnixTime() + 1); } return(true); } TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "操作失敗,或許使用者未被封鎖。", RawMessage.message_id ); return(false); // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Temp.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //return false; }
public void GetSpamPoints(TgMessage RawMessage) { int spacePath = RawMessage.text.IndexOf(" "); if (spacePath == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "/getspampoints text=\"被检测消息,如果包含英文和数字以外的字符需要加引号\"" + " rule=\"规则的友好名称,如果包含英文和数字以外的字符需要加引号\"", RawMessage.message_id ); return; } Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(spacePath + 1)); string text = banValues.GetValueOrDefault("text", null); string rule = banValues.GetValueOrDefault("rule", null); if (text == null || rule == null) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "您的输入有误", RawMessage.message_id ); return; } SpamMessage smsg = Temp.GetDatabaseManager().GetSpamRule(rule); if (smsg == null) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "没有找到您指定的规则,请重新指定。您亦可使用 /getspamstr 获取所有规则。", RawMessage.message_id ); return; } int points = 0; switch (smsg.Type) { case 0: points = new SpamMessageChecker().GetEqualsPoints(smsg.Messages, text); break; case 1: points = new SpamMessageChecker().GetRegexPoints(smsg.Messages, text); break; case 2: points = new SpamMessageChecker().GetSpamPoints(smsg.Messages, text); break; case 3: points = new SpamMessageChecker().GetIndexOfPoints(smsg.Messages, text); break; case 4: points = new SpamMessageChecker().GetHalalPoints(text); break; case 5: points = new SpamMessageChecker().GetIndiaPoints(text); break; } TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, "得分: " + points, RawMessage.message_id ); }
internal bool UnbanMulti(TgMessage RawMessage) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERUNBAN_HELP_MESSAGE, RawMessage.message_id ); return(true); } int[] UsersArray = { }; bool status = false; int BanUserId = 0; string Reason; try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1)); // 获取使用者信息 UsersArray = new GetValues().GetUserIDs(banValues, RawMessage); Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 則代表出现了异常 } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERUNBAN_ERROR_MESSAGE + " err10", RawMessage.message_id ); return(true); } new Thread(delegate() { foreach (int userid in UsersArray) { BanUserId = userid; try { status = Config.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, RAPI.escapeMarkdown(Reason) ); } catch (InvalidOperationException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.UNBAN_ERROR_USER_NOT_BANNED + " UID : " + BanUserId, RawMessage.message_id ); } Thread.Sleep(3500); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_OK, RawMessage.message_id ); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Config.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} }).Start(); return(true); }
internal bool BanMulti(TgMessage RawMessage, string JsonMessage, string Command) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERBAN_HELP_MESSAGE, RawMessage.message_id ); return(true); } int BanUserId = 0; int[] UsersArray = { }; long ExpiresTime = 0; int Level = 0; string Reason = ""; string value = RawMessage.text.Substring(banSpace + 1); int valLen = value.Length; bool NotHalal = true; bool status = false; if (valLen >= 5) { if (value.Substring(0, 5) == "halal") { NotHalal = false; Reason = Strings.HALAL; if (valLen > 6) { if (value[5] != ' ') { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERBAN_ERROR_MESSAGE + " err_a1", RawMessage.message_id ); return(true); } UsersArray = new GetValues().GetUserIDs(new Dictionary <string, string> { { "from", value.Substring(6) } }, RawMessage); } else { UsersArray = new GetValues().GetUserIDs(new Dictionary <string, string>(), RawMessage); } } } if (NotHalal) { try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(value); string tmpString = ""; // 获取使用者 UsersArray = new GetValues().GetUserIDs(banValues, RawMessage); // 获取 ExpiresTime long tmpExpiresTime = new GetValues().GetBanUnixTime(banValues, RawMessage); if (tmpExpiresTime == -1) { return(true); // 如果过期时间是 -1 则代表出现了异常 } ExpiresTime = tmpExpiresTime; // 获取 Level tmpString = banValues.GetValueOrDefault("l", "__invalid__"); if (tmpString == "__invalid__") { tmpString = banValues.GetValueOrDefault("level", "0"); } if (!int.TryParse(tmpString, out Level)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERBAN_ERROR_MESSAGE + " err8", RawMessage.message_id ); return(true); } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 则代表出现了异常 } if (Reason.ToLower() == "halal") { Reason = Strings.HALAL; } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.SUPERBAN_ERROR_MESSAGE + " err10", RawMessage.message_id ); return(true); } } new Thread(delegate() { foreach (int userid in UsersArray) { BanUserId = userid; status = Config.GetDatabaseManager().BanUser( RawMessage.GetSendUser().id, BanUserId, Level, ExpiresTime, RAPI.escapeMarkdown(Reason) ); if (Config.GetIsInWhiteList(BanUserId)) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetSendUser().id, Strings.EXEC_FAIL + Strings.BAN_ERROR_USER_IN_WHITELIST + " UID " + BanUserId, RawMessage.message_id ); } Thread.Sleep(3500); } //if (status) //{ TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_OK, RawMessage.message_id ); //} //else //{ // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Config.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //} //return false; }).Start(); return(true); }
internal bool Unban(TgMessage RawMessage) { int banSpace = RawMessage.text.IndexOf(" "); if (banSpace == -1) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.UNBAN_HELP_MESSAGE, RawMessage.message_id ); return(true); } int BanUserId = 0; string Reason; UserInfo BanUserInfo = null; try { Dictionary <string, string> banValues = CommandDecoder.cutKeyIsValue(RawMessage.text.Substring(banSpace + 1)); // 获取使用者信息 UserInfo tmpUinfo = new GetValues().GetByTgMessage(banValues, RawMessage); if (tmpUinfo == null) { return(true); // 如果没拿到使用者信息則代表出现了异常 } BanUserId = tmpUinfo.id; if (tmpUinfo.language_code != null) { if (tmpUinfo.language_code != "__CAN_NOT_GET_USERINFO__") { BanUserInfo = tmpUinfo; } } else { BanUserInfo = tmpUinfo; } // 获取 Reason Reason = new GetValues().GetReason(banValues, RawMessage); if (Reason == null) { return(true); // 如果 Reason 是 null 則代表出现了异常 } } catch (DecodeException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.UNBAN_ERROR_MESSAGE + " err10", RawMessage.message_id ); return(true); } new UnBanCaller().UnBanCallerThread(BanUserId); bool status; try { if (BanUserInfo == null) { status = Config.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, RAPI.escapeMarkdown(Reason) ); } else { status = Config.GetDatabaseManager().UnbanUser( RawMessage.GetSendUser().id, BanUserId, RAPI.escapeMarkdown(Reason), BanUserInfo ); } } catch (InvalidOperationException) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_FAIL + Strings.UNBAN_ERROR_USER_NOT_BANNED, RawMessage.message_id ); return(true); } if (status) { TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_OK, RawMessage.message_id ); if (RawMessage.GetMessageChatInfo().id == Config.CourtGroupID) { TgApi.getDefaultApiConnection() .kickChatMember(RawMessage.GetMessageChatInfo().id, BanUserId, GetTime.GetUnixTime() + 1); } return(true); } TgApi.getDefaultApiConnection().sendMessage( RawMessage.GetMessageChatInfo().id, Strings.EXEC_FAIL + Strings.UNBAN_ERROR_USER_NOT_BANNED, RawMessage.message_id ); return(false); // TgApi.getDefaultApiConnection().sendMessage( // RawMessage.GetMessageChatInfo().id, // "操作成功。\n\n請注意 : 轉發使用者訊息到頻道或是發送使用者訊息到頻道失敗,請您手動發送至 @" + Config.MainChannelName + " 。 err11", // RawMessage.message_id // ); // return true; //return false; }