Esempio n. 1
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public static async Task <GroupConfigurationObject> loadObject(long groupID, bool force = false)
        {
            if (!force)
            {
                GroupConfigurationObject gco;
                var w = configCache.TryGetValue(groupID, out gco);
                if (w)
                {
                    if (!gco.invalidated)
                    {
                        return(gco);
                    }
                }
            }
            var dr = await SQL.QueryAsync("SELECT * FROM xenf_groupconfigs WHERE `group`=" + groupID);

            if (dr == null)
            {
                Console.WriteLine(SQL.getLastError());
            }
            if (dr.Count > 0)
            {
                var my = new GroupConfigurationObject(groupID, dr[0]);
                configCache[groupID] = my;
                return(my);
            }
            else
            {
                return(null);
            }
        }
        public static GroupConfigurationObject getConfig(long group)
        {
            GroupConfigurationObject ret = null;
            var ok = cache.TryGetValue(group, out ret);

            if (ok)
            {
                if (ret.invalidated)
                {
                    ret          = queryObject(group);
                    cache[group] = ret;
                    return(ret);
                }

                return(ret);
            }

            ret = queryObject(group);
            if (ret != null)
            {
                cache[group] = ret;
                return(ret);
            }

            var ra = 0;

            ok = SQL.NonQuery($"INSERT INTO `configs` (groupid,language) VALUES({group},'en')", out ra);

            return(new GroupConfigurationObject(group));
        }
Esempio n. 4
0
        public static void doVerify(long user, long mid, long groupID, GroupConfigurationObject GCO)
        {
            int ra = 0;

            SQL.NonQuery($"UPDATE `verify` SET `verified`=TRUE, `tverified`={Helpers.getUnixTime()} WHERE `user`={user} AND `group`={groupID}", out ra);
            root.callHook.Call("verUserVerified", user, mid, groupID, GCO);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public static GroupConfigurationObject initializeObject(long groupID)
        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            SQL.NonQueryAsync(string.Format("INSERT INTO xenf_groupconfigs(`group`) VALUES ({0})", groupID)).Wait();

#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            Helpers.writeOut(tag, "Pushing new group configuration index {0}", groupID);
            var w = new GroupConfigurationObject();
            w.groupID = groupID;
            return(w);
        }
Esempio n. 7
0
        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);
            }
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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());
            }
        }