Faucet Collector
  • Documentation
  • Example
  • Empty template
  • Full reference
  • Scripts

This is an example of the moonliteco.in script.

using System;
using FaucetCollector.Script;

public class MoonLitecoinScript : FaucetScript
{
    /// <summary>
    /// List of Settings that will be shown in the bot when selecting this Faucet in the bot.
    /// You can get the value the user entered with the methods: GetSetting("[Name of the FaucetSetting]"), GetBoolSetting and GetDateTimeSetting
    /// You can also create a new setting value using SetSetting("[Name you want to use]", "value")
    /// </summary>
    public override FaucetSettings Settings
    {
        get
        {
            return new FaucetSettings("http://moonliteco.in/")
            {
                //We have a setting to get the email address used for the coinpot account
                new FaucetSetting() { Name = "Email", Display = "Coinpot email addres", Type = EditorType.TextBox, Required = true },
                //Option to use SolveMedia or reCAPTCHA
                new FaucetSetting() { Name = "UseSolveMedia", Display = "Use SolveMedia", Type = EditorType.CheckBox, Default = true }
            };
        }
    }

    /// <summary>
    /// This method gets called when the faucet is enabled and the GO button is clicked
    /// </summary>
    public override void Start()
    {
        //Title that shows in the browser. Is used to close popups
        Title = "moon litecoin";

        //After we did try to claim on the faucet we search for these elements to determine if it was a success or a fail
        SuccessXPath = "//div[@class='success-message']";
        FailXPath = "//*[@id='BodyPlaceholder_FailedClaimPanel']";

        //The moon faucet its counter is going up
        TimerIsCountingUp = true;

        //Let Faucet Collector start up everything
        base.Start();
    }

    /// <summary>
    /// This method gets called after the Start method, here you need to return if we are logged in or not.
    /// If you return false then it will call the BeforeLogin, Login and AfterLogin methods so you can login.
    /// After those Login methods are called it will call this IsLoggedIn method again to see if the login did succeed.
    /// If you return true Faucet Collector will store all cookies so it will probably be already logged in on the next attempt.
    /// </summary>
    public override bool IsLoggedIn()
    {
        //If there is an element that has the class "SignedInPaymentAddress" then we are logged in - that element is only present when you are logged in.
        return ElementById("SignedInPaymentAddress") != null;
    }

    /// <summary>
    /// This method gets called if IsLoggedIn returned false, right before the DoLogin method is called.
    /// </summary>
    public override int BeforeLogin()
    {
        //This faucet has nothing to do here. We will let Faucet Collector handle it.
        return base.BeforeLogin();
    }

    /// <summary>
    /// This method gets called after BeforeLogin if IsLoggedIn returned false.
    /// It can be used to actually login the user/enter wallet details in the faucet
    /// </summary>
    public override int DoLogin()
    {
        //Find the input field that holds the email address
        var signInEmail = ElementByClass("payment-address");
        if (!IsVisible(signInEmail))
        {
            //We couldn't find it. Register it as a fail so it can reload the page and try again in 10-15 seconds.
            return Fail("Signin email not found.");
        }

        //Email input found, update the value of the input with the email address the user entered in Faucet Collector
        SetText(signInEmail, GetSetting("Email"));

        //Now we search for the login submit button
        var loginButton = ElementById("SignInButton");
        if (!IsVisible(loginButton))
        {
            //We couldn't find it. Register it as a fail so it can reload the page and try again in 10-15 seconds.
            return Fail("Login button not found.");
        }

        //We are ready to click the login button.
        Click(loginButton);

        //Wait a sec for the popup to load
        Wait();

        //Check if the faucet opened popups
        var sleep = CheckForPopups();
        if (sleep > 0)
        {
            return sleep;
        }

        var submitButton = ElementById("SignInSubmitButton");
        if (!IsVisible(submitButton))
        {
            //We couldn't find it. Register it as a fail so it can reload the page and try again in 10-15 seconds.
            return Fail("Login button not found.");
        }

        //There is a captcha on the login popup, so we need to solve that before clicking the submit button.
        //We use the SolveCaptcha method for this. SolveCaptcha will call BeforeSolveCaptcha, DoSolveCaptcha and AfterSolveCaptcha
        //The DoSolveCaptcha method does the actual solving - it checks if there is a SolveMedia Captcha or a reCAPTCHA present on the page 
        //and will solves that one using the selected method entered in Faucet Collector on the Captcha tab.
        //In this script we only override BeforeSolveCaptcha (see below) to enable SolveMedia or reCAPTCHA based on the user settings.
        var result = SolveCaptcha();
        if (result > 0)
        {
            //SolveCaptcha returned there was something wrong - we also need to return that .
            return result;
        }

        //Now we can click the submit button.
        Click(submitButton);
        
        //Let Faucet Collector continue
        return base.DoLogin();
    }

    /// <summary>
    /// This method gets called after the DoLogin method.
    /// </summary>
    public override int AfterLogin()
    {
        //Check if the login doesn't show an error message.
        var failedLogin = ElementById("BodyPlaceholder_FailedSignInPanel");
        if (IsVisible(failedLogin))
        {
            if (failedLogin.Text.Contains("is not registered with CoinPot"))
            {
                //Invalid email address entered. Log and disable this faucet.
                Log("Please enter a correct coinpot.co email address.");
                Disable();
            }

            return Fail("Login failed: " + failedLogin.Text);
        }

        //we are good to continue
        return base.AfterLogin();
    }

    /// <summary>
    /// This method gets called after the login methods are successful, so we are logged into the faucet.
    /// If the faucet is not yet ready to claim you should return a TimeStamp value to return how long it takes before the Faucet claim can be done.
    /// This is used to pause the script while the faucet its timer runs out.
    /// </summary>
    public override int GetFaucetWaitTime()
    {
        var hours = Convert.ToString(ExecuteScript("var node = document.evaluate(\"//span[@class='countdown-period' and text()='Hours']/../span[@class='countdown-amount']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (node) { return node.innerText; } else { return ''; }"));
        var minutes = Convert.ToString(ExecuteScript("var node = document.evaluate(\"//span[@class='countdown-period' and text()='Minutes']/../span[@class='countdown-amount']\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; if (node) { return node.innerText; } else { return ''; }"));
        if (string.IsNullOrEmpty(hours) || string.IsNullOrEmpty(minutes))
        {
            return 0;
        }

        var hrs = Convert.ToInt32(hours.Trim());
        var min = Convert.ToInt32(minutes.Trim());
        var timespan = new TimeSpan(hrs, min, 0);
        return (int)timespan.TotalSeconds;
    }

    /// <summary>
    /// This method is called right before a captcha will be solved. 
    /// If you call SolveCaptcha() in other methods it will start this flow and tries to solve the captcha on the page.
    /// </summary>
    public override int BeforeSolveCaptcha()
    {
        //Check if the user wants to do SolveMedia or reCAPTCHA.
        if (GetBoolSetting("UseSolveMedia"))
        {
            //Make sure SolveMedia is active by clicking the link.
            Click(ElementByLinkText("Switch to SolveMedia captcha"));
        }
        else
        {
            //Make sure reCAPTCHA is active by clicking the link.
            Click(ElementByLinkText("Switch to Recaptcha"));
        }

        //Wait a little (1 - 2 seconds) for the captcha to switch.
        Wait();

        //Return we are ready to proceed
        return base.BeforeSolveFaucet();
    }

    /// <summary>
    /// This method gets called after BeforeSolveCaptcha and it does the actual captcha solving
    /// It will automatically try to see if there is a SolveMedia captcha active or a reCAPTCHA active. 
    /// If it finds either one it will then use the selected method on the Captcha tab of FaucetCollector to solve the Captcha.
    /// </summary>
    public override int DoSolveCaptcha()
    {
        //This faucet has nothing to do here. We will let Faucet Collector handle it.
        return base.DoSolveCaptcha();
    }

    /// <summary>
    /// This method will get called after DoSolveCaptcha returned it was a success.
    /// </summary>
    /// <returns></returns>
    public override int AfterSolveCaptcha()
    {
        //This faucet has nothing to do here. We will let Faucet Collector handle it.
        return base.AfterSolveCaptcha();
    }

    /// <summary>
    /// This method is called right before we attempt to claim on the faucet. So we are logged in and good to go.
    /// Next methods that will be called are DoSolveFaucet, AfterSolveFaucet and CheckFaucetResult.
    /// </summary>
    public override int BeforeSolveFaucet()
    {
        //Find the button to open the popup window where we can solve the captcha and claim on the faucet.
        var claimButton = ElementById("SubmitButton");
        if (!IsVisible(claimButton))
        {
            //We couldn't find the button, return we have a failure.
            return Fail("Claim button not found or not visible.");
        }

        //Click the button to opent the popup window
        Click(claimButton);

        //Return we can continue
        return base.BeforeSolveFaucet();
    }

    /// <summary>
    /// This method gets called after the BeforeSolveFaucet. You can do the actual claiming of the faucet in here.
    /// </summary>
    /// <returns></returns>
    public override int DoSolveFaucet()
    {
        //Find the submit button to claim on the faucet
        var submitButton = ElementByXPath("//div[@id='CaptchaPopup']//input[@class='submit-button']");
        if (!IsVisible(submitButton))
        {
            //Unable to find the submit button - return the failure.
            return Fail("Submit button not found or not visible.");
        }

        //We need to solve the captcha on this page before clicking the Login button.
        //We use the SolveCaptcha method for this. SolveCaptcha will call BeforeSolveCaptcha, DoSolveCaptcha and AfterSolveCaptcha
        //The DoSolveCaptcha method does the actual solving - it checks if there is a SolveMedia Captcha or a reCAPTCHA present on the page 
        //and will solves that one using the selected method entered in Faucet Collector on the Captcha tab.
        //In this script we only override BeforeSolveCaptcha (see above) to enable SolveMedia or reCAPTCHA based on the user settings.
        var result = SolveCaptcha();
        if (result > 0)
        {
            //Unable to solve the captcha - return the failure
            return result;
        }

        //The Captcha is solved, click the submit button
        Click(submitButton);

        //We are good to continue
        return base.DoSolveFaucet();
    }

    /// <summary>
    /// This method will get called after the DoSolveFaucet is completed and returned it was a success.
    /// This faucet shows a "Processing" window after you click the claim submit button.
    /// We will have to wait for it to disappear before we can check for the results.
    /// </summary>
    public override int AfterSolveFaucet()
    {
        //This faucet has nothing to do here. We will let Faucet Collector handle it.
        return base.AfterSolveFaucet();
    }

    /// <summary>
    /// This method gets called in the end after the BeforeSolveFaucet/DoSolveFaucet and AfterSolveFaucet methods were done.
    /// The base.CheckFaucetResult will try to find a visible element on the page using the XPath from SuccessXPath and FailXPath (see the Start method)
    /// These properties should contain XPath expressions to find certain elements on the page.
    /// For example if it finds one of the elements from the SuccessXPath, and it is visible, then it will flag the claim attempt as a success.
    /// Or if it finds one of the elements from the FailXPath, and it is visible, then it will flag the claim attempt as a failure.
    /// </summary>
    public override int CheckFaucetResult()
    {
        //This faucet has nothing to do here. We will let Faucet Collector handle it.
        return base.CheckFaucetResult();
    }
}
Back to top