Exemplo n.º 1
0
        public static bool getGroupConfigurationValue(TGChat chat, string value, bool def)
        {
            SQLQueryInstance QueryInst;
            MySqlDataReader  cur;
            var vname = SQL.escape(value);
            var ok    = SQL.Query(string.Format("SELECT `{1}` FROM xenf_groupconfigs WHERE `group`={0}", chat.id, vname), out QueryInst);

            if (!ok)
            {
                Console.WriteLine("[!] Error reading chat information for {0} -- {1}", chat.id, SQL.getLastError());
                Console.WriteLine(Environment.StackTrace);
                if (QueryInst != null)
                {
                    QueryInst.Finish();
                }
                return(def);
            }
            else
            {
                cur = QueryInst.reader;
                if (cur.HasRows)
                {
                    cur.Read();
                    var b = (int)cur[value] > 0;
                    QueryInst.Finish();
                    return(b);
                }
                else
                {
                    QueryInst.Finish();
                    InitializeGroupConfiguration(chat);
                    return(def);
                }
            }
        }
Exemplo n.º 2
0
        public static void DoMessageCleanup()
        {
            var query = "SELECT * FROM xenf_spoken";
            SQLQueryInstance QueryInst;
            MySqlDataReader  data;

            Stack <long> MessageCleanupIndicies = new Stack <long>(32);

            var ok1 = SQL.Query(query, out QueryInst);

            // Console.WriteLine(ok1);
            if (!ok1 || QueryInst == null)
            {
                Console.WriteLine("Failed to clean up messages {0}", SQL.getLastError());
                return;
            }
            data = QueryInst.reader;
            var MessageIndex = 0;

            while (data.Read())
            {
                var idx         = (int)data["index"];
                var grp         = (long)data["group"];
                var mid         = (long)data["messageid"];
                var lifetime    = (int)data["lifetime"];
                var whencreated = (long)data["whencreated"];

                if ((lifetime + whencreated) < Helpers.getUnixTime())
                {
                    var chat = new TGChat();
                    chat.id = grp;
                    Telegram.deleteMessage(chat, mid);
                    MessageCleanupIndicies.Push(idx);
                }


                MessageIndex++;
                if (MessageIndex > 30)
                {
                    break;
                }
            }
            QueryInst.Finish();

            while (MessageCleanupIndicies.Count > 0) // Had to do this,  no concurrent queries.
            {
                Console.WriteLine("CLEANUP?");
                var mid = MessageCleanupIndicies.Pop();
                int ra  = 0;
                var ok  = SQL.NonQuery("DELETE FROM xenf_spoken WHERE `index`=" + mid, out ra);
                if (!ok)
                {
                    Console.WriteLine("Message cannot be cleaned up {0}", SQL.getLastError());
                }
            }
        }
        public static void doURLMediaFilter(TGMessage msg, TGUser usr)
        {
            var chat = msg.chat;                                                                      // grab chat.

            var enabled = XenforceRoot.getGroupConfigurationValue(chat, "kickurlunactivated", false); // Check configuration value.

            if (!enabled)                                                                             // return if not enabled.
            {
                return;
            }

            var qsc = "SELECT * FROM xen_activations WHERE activated=0 AND `group`={0} AND `forwho`={1}"; //

            var rqry = string.Format(qsc, chat.id, usr.id);

            SQLQueryInstance QueryInst;
            var  queryok = SQL.Query(rqry, out QueryInst);
            bool onerow  = false;

            if (QueryInst != null && QueryInst.reader.HasRows) // They've already been kicked before. If we return at least one row, then its valid to assume they havent activated
            {                                                  // There can only be one activation index per user per group.
                onerow = true;
            }

            if (QueryInst != null)
            {
                QueryInst.Finish();
            }

            if (!onerow)
            {
                return; // There was no activation
            }
            var wtf = msg.replySendMessage(usr.first_name + " was removed from the chat for sending URL/Media before activating!");

            XenforceRoot.AddCleanupMessage(msg.chat.id, wtf.message_id, 30);
            Telegram.kickChatMember(msg.chat, msg.from, 30);
            msg.delete();

            var statement =
                string.Format("INSERT INTO xenf_autokick (`group`,`user`,`when`,`why`) VALUES ({0},{1},{2},'{3}')",
                              msg.chat.id,
                              msg.from.id,
                              Helpers.getUnixTime(),
                              "URLMedia_Picture"
                              );
            int ra = 0;

            SQL.NonQuery(statement, out ra);
            if (ra < 1)
            {
                Console.WriteLine("Creating autorem incident failed failed. No SQL rows affected.");
                var cmsg = msg.replySendMessage("AutoremAddIncident() FAILED:\n\n Info:\n\n" + SQL.getLastError());
                XenforceRoot.AddCleanupMessage(chat.id, cmsg.message_id, 120);
            }
        }
Exemplo n.º 4
0
        public static XenforceGroupConfiguration getGroupConfiguration(TGChat chat)
        {
            SQLQueryInstance QueryInst;
            MySqlDataReader  cur;
            var ok = SQL.Query(string.Format("SELECT * FROM xenf_groupconfigs WHERE `group`={0}", chat.id), out QueryInst);

            if (!ok)
            {
                Console.WriteLine("[!] Error reading chat information for {0} -- {1}", chat.id, SQL.getLastError());
                Console.WriteLine(Environment.StackTrace);
                return(null);
            }
            else
            {
                cur = QueryInst.reader;
                if (cur.HasRows)
                {
                    cur.Read();
                    XenforceGroupConfiguration b = new XenforceGroupConfiguration()
                    {
                        group             = (long)cur["group"],
                        kicktime          = (int)cur["kicktime"],
                        message           = (string)cur["message"],
                        autoban           = (int)cur["autoban"],
                        muteuntilverified = (int)cur["muteuntilverified"],
                        announcekicks     = (int)cur["announcekicks"],
                        activationmode    = ((int)cur["activationmode"])
                    };

                    QueryInst.Finish();
                    return(b);
                }
                else
                {
                    QueryInst.Finish();
                    InitializeGroupConfiguration(chat);
                    return(new XenforceGroupConfiguration());
                }
            }
        }
Exemplo n.º 5
0
        public static bool namefilter(TGMessage msg, TGUser usr)
        {
            var chat   = msg.chat;
            var enable = XenforceRoot.getGroupConfigurationValue(chat, "autobannames", true);

            if (!enable)
            {
                return(false);
            }                              // Not enabled.
            var qsc  = "SELECT * FROM xenf_autokick WHERE `group`={0} AND `user`={1}";
            var rqry = string.Format(qsc, chat.id, usr.id);

            MySql.Data.MySqlClient.MySqlDataReader datar;
            SQLQueryInstance QueryInst;
            var queryok = SQL.Query(rqry, out QueryInst);

            if (QueryInst != null && QueryInst.reader.HasRows) // They've already been kicked before.
            {
                QueryInst.Finish();
                return(false);
            }
            if (QueryInst != null)
            {
                QueryInst.Finish();;
            }

            var UserID         = usr.id;
            var GroupID        = msg.chat.id;
            var user_name_full = usr.first_name + " " + usr.last_name;

            var userscore = 0;

            for (int i = 0; i < ShitNames.Length; i++)
            {
                var q = user_name_full.Contains(ShitNames[i]);
                if (q)
                {
                    userscore++;
                }
            }
            if (userscore > 0)
            {
                Telegram.kickChatMember(chat, usr, 120);
                if (XenforceRoot.getGroupConfigurationValue(chat, "announcekicks", 1) > 0)
                {
                    msg.delete();
                    var msgr = msg.replySendMessage(user_name_full + " removed -- name matches common bot.");
                    XenforceRoot.AddCleanupMessage(chat.id, msgr.message_id, 30);
                    var statement =
                        string.Format("INSERT INTO xenf_autokick (`group`,`user`,`when`,`why`) VALUES ({0},{1},{2},'{3}')",
                                      GroupID,
                                      UserID,
                                      Helpers.getUnixTime(),
                                      "Name is in blacklist"
                                      );
                    int ra = 0;
                    SQL.NonQuery(statement, out ra);
                    if (ra < 1)
                    {
                        Console.WriteLine("Creating autorem incident failed failed. No SQL rows affected.");
                        var cmsg = msg.replySendMessage("AutoremAddIncident() FAILED:\n\n Info:\n\n" + SQL.getLastError());
                        XenforceRoot.AddCleanupMessage(chat.id, cmsg.message_id, 120);
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public static bool autorem(TGMessage msg, TGUser usr)
        {
            var chat   = msg.chat;
            var enable = XenforceRoot.getGroupConfigurationValue(chat, "autoban", true);

            if (!enable)
            {
                return(false);
            }                              // Not enabled.
            var qsc  = "SELECT * FROM xenf_autokick WHERE `group`={0} AND `user`={1}";
            var rqry = string.Format(qsc, chat.id, usr.id);

            MySql.Data.MySqlClient.MySqlDataReader datar;
            SQLQueryInstance QueryInst;
            var queryok = SQL.Query(rqry, out QueryInst);

            if (QueryInst != null && QueryInst.reader.HasRows) // They've already been kicked before.
            {
                QueryInst.Finish();
                return(false);
            }
            if (QueryInst != null)
            {
                QueryInst.Finish();
            }

            var UserID         = usr.id;
            var GroupID        = msg.chat.id;
            var user_name_full = usr.first_name + " " + usr.last_name;
            var userscore      = 500;

            for (int i = 0; i < user_name_full.Length; i++)
            {
                var wtf = user_name_full[i];
                if (wtf > 0xAF)
                {
                    userscore += 5;
                }
                else if (wtf < 0x80)
                {
                    userscore -= 3;
                }
            }
            var picons = Telegram.getNumProfilePhotos(usr);

            userscore -= picons * 45;
            if (picons == 0)
            {
                userscore += 30;
            }
            if (userscore > 488)
            {
                Telegram.kickChatMember(chat, usr, 120);
                if (XenforceRoot.getGroupConfigurationValue(chat, "announcekicks", 1) > 0)
                {
                    msg.delete();
                    var msgr = msg.replySendMessage(user_name_full + " was automatically removed from the chat -- I think they're a bot.");
                    XenforceRoot.AddCleanupMessage(chat.id, msgr.message_id, 30);
                    var statement =
                        string.Format("INSERT INTO xenf_autokick (`group`,`user`,`when`,`why`) VALUES ({0},{1},{2},'{3}')",
                                      GroupID,
                                      UserID,
                                      Helpers.getUnixTime(),
                                      "Bot Score too high"
                                      );
                    int ra = 0;
                    SQL.NonQuery(statement, out ra);
                    if (ra < 1)
                    {
                        Console.WriteLine("Creating autorem incident failed failed. No SQL rows affected.");
                        var cmsg = msg.replySendMessage("AutoremAddIncident() FAILED:\n\n Info:\n\n" + SQL.getLastError());
                        XenforceRoot.AddCleanupMessage(chat.id, cmsg.message_id, 120);
                    }
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        public static bool captcha_CheckExpired()
        {
            MySql.Data.MySqlClient.MySqlDataReader cur;
            SQLQueryInstance QueryInst;

            var ss = SQL.Query("SELECT * FROM xen_activations WHERE activated=0 OR activation_checked=0", out QueryInst);

            if (!ss)
            {
                Console.WriteLine("Query for activation checks failed {0}", SQL.getLastError());
                if (QueryInst != null)
                {
                    QueryInst.Finish();
                }
                return(false);
            }
            Stack <CaptchaActivationIndex> captchaActivationIndices = new Stack <CaptchaActivationIndex>(1024); // hax?

            // totally hax, I have to pull group configuration to check and see if the group has specific features enabled.
            // But I can't do that if I already have an SQL cursor open. So i'll have to read all of the results of it

            cur = QueryInst.reader;
            // before I can make a call to get group configuration.

            var ib = 0;

            while (cur.Read())
            {
                ib++;
                // Console.WriteLine(ib);
                var b = new CaptchaActivationIndex
                {
                    index              = (long)cur["index"],
                    activation_id      = (string)cur["activation_id"],
                    activated          = (int)cur["activated"],
                    forwho             = (long)cur["forwho"],
                    group              = (long)cur["group"],
                    whencreated        = (long)cur["whencreated"],
                    activation_checked = (int)cur["activation_checked"],
                    username           = (string)cur["username"],
                    actmessage         = (long)cur["actmessage"]
                };

                captchaActivationIndices.Push(b);
            }
            QueryInst.Finish();  // close it up.

            for (int i = 0; i < captchaActivationIndices.Count; i++)
            {
                var CurrentActivation = captchaActivationIndices.Pop();
                var chat = new TGChat();
                var user = new TGUser();
                user.id = CurrentActivation.forwho;
                chat.id = CurrentActivation.group;
                var kicktime = XenforceRoot.getGroupConfigurationValue(chat, "kicktime", 30);
                var announce = XenforceRoot.getGroupConfigurationValue(chat, "announcekicks", 1);
                var unmute   = XenforceRoot.getGroupConfigurationValue(chat, "muteuntilverified", false);
                //Console.WriteLine("Wtf {0} {1}",CurrentActivation.activated,CurrentActivation.activation_checked);
                if (CurrentActivation.activated == 0)
                {
                    if (CurrentActivation.whencreated < Helpers.getUnixTime() - (kicktime * 60))
                    {
                        Telegram.deleteMessage(chat, CurrentActivation.actmessage);
                        Telegram.kickChatMember(chat, user, 0); // kick them from the chat.
                        Console.WriteLine("Remove user?");
                        var rar = 0;
                        var ok  = SQL.NonQuery(string.Format("DELETE FROM xen_activations WHERE activation_id='{0}'", CurrentActivation.activation_id), out rar);
                        if (announce > 0)
                        {
                            var mymessage = Telegram.sendMessage(chat, CurrentActivation.username + " was removed from the chat for not completing the CAPTCHA.");
                            if (mymessage != null)
                            {
                                XenforceRoot.AddCleanupMessage(chat.id, mymessage.message_id, 30); // Clean up after 30 seconds.
                            }
                        }
                    }
                }
                else if (CurrentActivation.activated == 1 && CurrentActivation.activation_checked == 0)
                {
                    Telegram.deleteMessage(chat, CurrentActivation.actmessage);

                    var Oldmsg  = CurrentActivation.username + ", thanks for verifying you're not a robot.";
                    var actiMsg = XenforceRoot.getGroupConfigurationValue(chat, "activationmessage", "%NAME, thanks for verifying you're not a robot.");
                    if (actiMsg == null || actiMsg.Length < 5)
                    {
                        actiMsg = Oldmsg;
                    }

                    actiMsg = actiMsg.Replace("%NAME", CurrentActivation.username);

                    var mymessage = Telegram.sendMessage(chat, actiMsg);
                    var ra        = 0;
                    var ok        = SQL.NonQuery("UPDATE xen_activations SET activation_checked=1 WHERE activation_id='" + SQL.escape(CurrentActivation.activation_id) + "'", out ra);
                    if (!ok)
                    {
                        Console.WriteLine("Updating activation message failed! Might spam!!!?");
                    }
                    if (mymessage != null)
                    {
                        XenforceRoot.AddCleanupMessage(chat.id, mymessage.message_id, 30); // Clean up after 30 seconds.
                    }

                    if (unmute)
                    {
                        Telegram.restrictChatMember(chat, user, 0, true, true, true, true);
                    }
                }
            }
            return(true);
        }