public static void doCaptcha(TGUser user, TGChat chat, GroupConfigurationObject GCO, TGMessage msg) { var CustomText = GCO.getString("verifyask"); var delayDelay = GCO.getInt("verifydelay"); var apiEndpoint = Config.getValue("APIEndpoint"); //-- NOTE: Capital config, gets the member from the C# state for config. var challengeData = Helpers.Base64Encode(user.id.ToString() + chat.id.ToString()); var actURL = Helpers.quickFormat(ref apiEndpoint, "%s", challengeData); var UserName = Helpers.getMentionName(user); var regularLocalization = Localization.getStringLocalized(GCO.getString("language"), "captcha/userWelcome", UserName, delayDelay, actURL); if (CustomText != null) { if (CustomText.Length > 10) { CustomText = Helpers.quickFormat(ref CustomText, "%NAME", UserName); CustomText = Helpers.quickFormat(ref CustomText, "%ACTURL", actURL); CustomText = Helpers.quickFormat(ref CustomText, "%DURATION", delayDelay.ToString()); regularLocalization = CustomText; } } var actMessage = Telegram.sendMessage(chat, regularLocalization, "HTML"); if (actMessage == null) { Console.WriteLine("Parse error sending message. Re-sending without parsemode"); actMessage = Telegram.sendMessage(chat, regularLocalization); } //(user, chat, actMessage, config, challengeData, delay, message) Verify.addInstance(user, chat, actMessage, GCO, challengeData, delayDelay, msg); }
public static bool restrictChatMember(TGChat chat, TGUser who, int secondsDuration, bool canSendmessages, bool canSendMedia, bool canSendMisc, bool generateLinkPreviews) { if (secondsDuration < 30 && secondsDuration != 0) { secondsDuration = 35; // Prevent accidental permaban. } var b = new NameValueCollection(); b["chat_id"] = chat.id.ToString(); b["user_id"] = who.id.ToString(); b["until_date"] = (Helpers.getUnixTime() + secondsDuration).ToString(); b["can_send_messages"] = canSendmessages.ToString(); b["can_send_media_messages"] = canSendMedia.ToString(); b["can_send_other_messages"] = canSendMisc.ToString(); b["can_add_web_page_previews"] = generateLinkPreviews.ToString(); TGResponse resp = apiGetRequest("restrictChatMember", b); if (resp.ok == true) { return(true); } else { return(false); } }
public static void addInstance(TGUser user, TGChat chat, TGMessage assoc_message, GroupConfigurationObject GCO, string challenge_data, int minutes, TGMessage joinM) { try { var ra = 0; long messageID = 0; long joinMessageID = 0; if (assoc_message != null) { messageID = assoc_message.message_id; } if (joinM != null) { joinMessageID = joinM.message_id; } SQL.NonQuery($"DELETE FROM `verify` WHERE `user`={user.id} AND `group`={chat.id}", out ra); SQL.NonQuery( $"INSERT INTO `verify` (`user`,`group`,`challenge`,`tcreated`,`texpire`,`joinmessage`,`message`) VALUES({user.id},{chat.id},'{SQL.escape(challenge_data)}',{Helpers.getUnixTime()}, {Helpers.getUnixTime() + minutes * 60},{joinMessageID},{messageID})", out ra); } catch (Exception E) { Console.WriteLine(E.ToString()); } }
public static bool doTrustUser(TGUser user, TGChat chat) { int ra = 0; SQL.NonQuery($"UPDATE `verify` SET `trusted`=TRUE `tverified`={Helpers.getUnixTime()} WHERE `user`={user.id} AND `group`={chat.id}", out ra); return(ra > 0); }
public static bool checkDoubt(TGUser user, TGChat chat) { var dr0 = SQL.Query($"SELECT * FROM `verify_doubt` WHERE `user`={user.id} AND `group`={chat.id}"); if (dr0.Count == 0) { return(false); } return(true); }
public static void addIncident(TGUser user, TGChat chat, string reason) { int ra = 0; //Console.WriteLine("$"INSERT INTO `removals`(`user`,`group`,`cause`,`when`) VALUES({ user.id},{ chat.id},'{SQL.escape(reason)}',{ Helpers.getUnixTime()")) SQL.NonQuery($"INSERT INTO `removals`(`user`,`group`,`cause`,`when`) VALUES({user.id},{chat.id},'{SQL.escape(reason)}',{Helpers.getUnixTime()})", out ra); if (ra == 0) { Console.WriteLine(SQL.getLastError()); } }
public static VerifyData getVerifyData(TGUser user, TGChat chat, TGMessage assoc_message) { int ra = 0; int messageID = 0; var dr0 = SQL.Query($"SELECT * FROM `verify` WHERE `user`={user.id} AND `group`={chat.id} ORDER BY `uid` DESC"); if (dr0.Count == 0) { return(null); } return(new VerifyData(dr0[0])); }
public static int getNumProfilePhotos(TGUser user) { var b = new NameValueCollection(); b["user_id"] = user.id.ToString(); TGResponse resp = apiGetRequest("getUserProfilePhotos", b); if (resp.ok == true) { var rede = resp.result.CreateReader(); var ret = serializer.Deserialize <TGProfilePhotos>(rede); rede.Close(); return(ret.total_count); } return(-1); }
public static void doNotify(long user, long mid, long groupID, GroupConfigurationObject GCO, long jmid) { var ra = 0; SQL.NonQuery($"UPDATE `verify` SET notified=TRUE WHERE `user`={user} AND `group`={groupID}", out ra); var thc = new TGChat { id = groupID }; var thu = new TGUser { id = user }; var thm = Telegram.getChatMember(thc, thu); var deleteJMID = GCO.getBool("dontdeletejoinmessage"); if (mid != 0) { Telegram.deleteMessage(thc, mid); } if (jmid != 0 && deleteJMID == false) { Telegram.deleteMessage(thc, jmid); } root.callHook.Call("verUserVerifiedNotify", thc, thu, groupID, GCO); if (GCO.getBool("verifyannounce")) { var name = Helpers.getMentionName(thm); var sendMsg = Localization.getStringLocalized(GCO.getString("language"), "verify/userVerified", name); var vermsg = GCO.getString("verifymessage"); if ((vermsg != null) & (vermsg.Length > 2)) { sendMsg = vermsg; sendMsg = sendMsg.Replace("%NAME", name); } var msg = Telegram.sendMessage(new TGChat { id = groupID }, sendMsg, "HTML"); Cleanup.addMessage(msg); } }
public static TGChatMember getChatMember(TGChat chat, TGUser user) { var b = new NameValueCollection(); b["chat_id"] = chat.id.ToString(); b["user_id"] = user.id.ToString(); TGResponse resp = apiGetRequest("getChatMember", b); if (resp.ok == true) { var rede = resp.result.CreateReader(); var ret = serializer.Deserialize <TGChatMember>(rede); rede.Close(); return(ret); } return(null); }
public static string getMentionName(TGUser usr) { var name = usr.username; if (name == null) { name = usr.first_name; if (usr.last_name != null) { name += " " + usr.last_name; } } else { name = "@" + name; } return(name); }
public static void doRemovalDoubt(long user, long mid, long groupID, GroupConfigurationObject GCO, long jmid) { int ra = 0; SQL.NonQuery($"DELETE FROM `verify` WHERE `user`={user} AND `group`={groupID}", out ra); SQL.NonQuery($"INSERT INTO `verify_doubt` (`user`,`group`) VALUES({user},{groupID})", out ra); Removals.addIncident(new TGUser() { id = user }, new TGChat { id = groupID }, "VERIFYEXPIRE"); root.callHook.Call("verUserRemoved", user, mid, groupID, GCO, true); var thc = new TGChat() { id = groupID }; var thu = new TGUser() { id = user }; var thm = Telegram.getChatMember(thc, thu); if (mid != 0) { Telegram.deleteMessage(thc, mid); } if (jmid != 0) { Telegram.deleteMessage(thc, jmid); } Telegram.kickChatMember(thc, thu, 120); if (GCO.getBool("verifyannounce")) { var name = Helpers.getMentionName(thm); var sendMsg = Localization.getStringLocalized(GCO.getString("language"), "verify/userKickedDoubt", name); var msg = Telegram.sendMessage(new TGChat() { id = groupID }, sendMsg); Cleanup.addMessage(msg); } }
public static void doRemoval(long user, long mid, long groupID, GroupConfigurationObject GCO, long jmid) { int ra = 0; Removals.addIncident(new TGUser() { id = user }, new TGChat { id = groupID }, "VERIFYEXPIRE"); SQL.NonQuery($"DELETE FROM `verify` WHERE `user`={user} AND `group`={groupID}", out ra); root.callHook.Call("verUserRemoved", user, mid, groupID, GCO, false); var thc = new TGChat() { id = groupID }; var thu = new TGUser() { id = user }; var thm = Telegram.getChatMember(thc, thu); if (mid != 0) { Telegram.deleteMessage(thc, mid); } if (jmid != 0) { Telegram.deleteMessage(thc, jmid); } Telegram.kickChatMember(thc, thu, 0); //Telegram.sendMessage(thc, "welcome to kicked, nobody will ever know you existed."); if (GCO.getBool("verifyannounce")) { var name = Helpers.getMentionName(thm); var sendMsg = Localization.getStringLocalized(GCO.getString("language"), "verify/userKicked", name); var msg = Telegram.sendMessage(new TGChat() { id = groupID }, sendMsg); Cleanup.addMessage(msg); } }
public static bool unbanChatMember(TGChat chat, TGUser who, int secondsDuration) { if (secondsDuration < 30 && secondsDuration != 0) { secondsDuration = 35; // Prevent accidental permaban. } var b = new NameValueCollection(); b["chat_id"] = chat.id.ToString(); b["user_id"] = who.id.ToString(); var resp = apiGetRequest("unbanChatMember", b); if (resp.ok) { return(true); } return(false); }
public static bool kickChatMember(TGChat chat, TGUser who, int secondsDuration) { if (secondsDuration < 30 && secondsDuration != 0) { secondsDuration = 35; // Prevent accidental permaban. } var b = new NameValueCollection(); b["chat_id"] = chat.id.ToString(); b["user_id"] = who.id.ToString(); b["until_date"] = (Helpers.getUnixTime() + secondsDuration).ToString(); TGResponse resp = apiGetRequest("kickChatMember", b); if (resp.ok == true) { return(true); } else { return(false); } }