public async Task <Message> GetWorkReward(ulong userId) { var user = await _usersConnector.GetUser(userId); var currentJob = Work.GetCurrentJob(user.Level); if (user.LastWorkReward.HasValue) { var timeSpan = DateTime.Now - user.LastWorkReward; if (timeSpan >= TimeSpan.FromHours(currentJob.Cooldown)) { user.Credits += currentJob.Reward; user.LastWorkReward = DateTime.Now; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(currentJob.Reward, "WorkReward")); } return(_messagesHelper.CommandCalledTooEarly(TimeSpan.FromHours(currentJob.Cooldown) - timeSpan, "!work", "WorkReward")); } user.Credits += currentJob.Reward; user.LastWorkReward = DateTime.Now; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(currentJob.Reward, "WorkReward")); }
public async Task <Message> GetHourlyReward(ulong userId) { var user = await _usersConnector.GetUser(userId); if (user.LastHourlyReward.HasValue) { var timeSpan = DateTime.Now - user.LastHourlyReward.Value; if (timeSpan >= TimeSpan.FromDays(1)) { user.LastHourlyReward = DateTime.Now; user.Credits += Reward; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(Reward, "HourlyReward")); } return(_messagesHelper.CommandCalledTooEarly(TimeSpan.FromDays(1) - timeSpan, "!hourly", "HourlyReward")); } user.Credits += Reward; user.LastHourlyReward = DateTime.Now; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(Reward, "HourlyReward")); }
public async Task <Message> Vote(ulong userId) { if (_config.BotSettings.TopGgToken == null) { return(_messagesHelper.Information( "Top GG Token functionality is disabled on this server :disappointed:. Contact bots admin to turn it on :slight_smile:.", "TopGGVote")); } var user = await _usersConnector.GetUser(userId); var httpRequestMessage = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri($"https://top.gg/api/bots/688160933574475800/check?userId={userId}"), Headers = { { HttpRequestHeader.Authorization.ToString(), _config.BotSettings.TopGgToken } } }; var response = await _client.SendAsync(httpRequestMessage); if (!response.IsSuccessStatusCode) { _logger.LogWarning("Error during http request! Verify the top gg token!!!", response); return(_messagesHelper.Error( "Invalid Top GG Token Provided by the bot administrator! Please contact him!")); } var didUserVote = JsonConvert.DeserializeObject <Vote>(await response.Content.ReadAsStringAsync()); if (didUserVote.Voted) { if (user.LastVoteReward.HasValue) { var timeSpan = DateTime.Now - user.LastVoteReward.Value; if (timeSpan >= TimeSpan.FromHours(12)) { user.Credits += Reward; user.LastVoteReward = DateTime.Now; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(Reward, "TopGGVote")); } return(_messagesHelper.CommandCalledTooEarly(TimeSpan.FromHours(12) - timeSpan, "!vote", "TopGGVote")); } user.Credits += Reward; user.LastVoteReward = DateTime.Now; await _usersConnector.UpdateUser(user); return(_messagesHelper.CreditsGain(Reward, "TopGGVote")); } return(_messagesHelper.NotVotedYet()); }