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 async Task runCommand(TGMessage message, GroupConfigurationObject gco, string langcode) { var varg_1 = message.text.Split((char)0x20); if (varg_1.Length > 0) { if (varg_1[0] == "/xen") { if (varg_1.Length > 1) { var VARGUMENTS = new string[varg_1.Length - 2]; for (int ix = 2; ix < varg_1.Length; ix++) { VARGUMENTS[ix - 2] = varg_1[ix]; // Move only string argument into argument table. } var cmdText = varg_1[1]; BaseCommand cmd; var ok = AllCommands.TryGetValue(cmdText, out cmd); if (!ok) { var nokText = Localization.getStringLocalized(langcode, "basic/commands/notFound"); Helpers.quickFormat(ref nokText, "%s", cmdText); await message.replySendMessage(nokText); } else { await cmd.Execute(message, VARGUMENTS, gco, langcode); } } } } }
public bool modify(string col, TGMessage msg, int start) { var data = msg.text.Substring(start); invalidated = true; var qry = $"UPDATE `configs` SET `{SQL.escape(col)}`='{SQL.escape(data)}' WHERE `groupid`={groupID}"; // spooky ' int ra = 0; return(SQL.NonQuery(qry, out ra)); }
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 void addMessage(TGMessage msg, int lifetime = 30) { if (msg == null) { Helpers.writeOut(tag, "Cleanup.addMessage was NULL!!"); return; } var qry = $"INSERT INTO `cleanup`(`group`,`mid`,`when`,`life`) VALUES({msg.chat.id},{msg.message_id},{Helpers.getUnixTime()},{lifetime})"; int ra = 0; SQL.NonQuery(qry, out ra); }
public static bool deleteMessage(TGChat chat, TGMessage message) { var b = new NameValueCollection(); b["chat_id"] = chat.id.ToString(); b["message_id"] = message.message_id.ToString(); TGResponse resp = apiGetRequest("deleteMessage", b); if (resp.ok == true) { return(true); } return(false); }
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 + 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) addInstance(user, chat, actMessage, GCO, challengeData, delayDelay, msg); }