Example #1
0
        public async Task <TurtleWallet> GetFirstAddress()
        {
            JObject response = await SendRPCRequest("getAddresses");

            string firstAddress = (string)response["result"]["addresses"][0];

            return(await TurtleWallet.FromString(this, firstAddress));
        }
Example #2
0
        private async Task MessageReceived(SocketMessage rawMessage)
        {
            // Ignore system messages and messages from bots and exiled users
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            if (!(message.Channel is SocketDMChannel))
            {
                return;
            }
            var guildUser = _guildUsers.FirstOrDefault(u => u.Id == message.Author.Id);

            if (guildUser == null || guildUser.RoleIds.Contains(_exiledRoleId))
            {
                return;
            }

            var address = message.ToString();

            _logger.LogInformation(message.Author.Username + ": " + address);

            if (State != RainServiceState.AcceptingRegistrations)
            {
                if (State == RainServiceState.BalanceExceeded)
                {
                    //await rawMessage.Author.SendMessageAsync("You are too early, little turtle, please wait for the registration!");
                    return;
                }
                //await rawMessage.Author.SendMessageAsync("Huh, it doesn't look like it is raining soon...");
                return;
            }

            if (_wallets.ContainsKey(message.Author))
            {
                //await rawMessage.Author.SendMessageAsync("You are already registered, little turtle.");
                return;
            }

            var wallet = await TurtleWallet.FromString(_walletService, address);

            if (wallet == null)
            {
                //await rawMessage.Author.SendMessageAsync("Your wallet address is malformed, little turtle.");
                return;
            }

            _wallets[message.Author] = wallet;
            _requiredReactions[message.Author.Id] = _reactionEmotes.RandomElement(_random);

            await message.Author.SendMessageAsync($"React to the announcement message with {_requiredReactions[message.Author.Id]} (and **ONLY** with {_requiredReactions[message.Author.Id]}) to catch some shells!");
        }
Example #3
0
        public async void Start()
        {
            try
            {
                if (State != RainServiceState.Stopped)
                {
                    return;
                }
                _guild        = _discord.GetGuild(_guildId);
                _exiledRoleId = _guild.Roles.First(r => r.Name == "exiled").Id;
                _guildUsers   = await _guild.GetUsersAsync();

                BotWallet = await _walletService.GetFirstAddress();

                _checkCanellationTokenSource = new CancellationTokenSource();
                _checkTask = Task.Run(() => CheckBalanceLoop(_checkInterval.Value, _checkCanellationTokenSource.Token));
            }
            catch (Exception e)
            {
                State = RainServiceState.Stopped;
                _logger.LogCritical(e, "Exception in Start");
            }
        }
Example #4
0
        public async Task <long> GetBalance(TurtleWallet address)
        {
            JObject response = await SendRPCRequest("getBalance", $"{{\"address\":\"{address.Address}\"}}");

            return((long)response["result"]["availableBalance"]);
        }