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()); }
public async Task <Message> GetGameHistory(ulong userId) { var history = await _gameHistoryConnector.GetGameHistories(userId); var text = string.Join("\n", history .TakeLast(10).Select(x => $"{x.GameName} | {(x.HasWon ? "Won" : "Lost")} | {x.CoinsDifference}") .ToArray()); return(_messagesHelper.Information(text, "GameHistory")); }
public async Task <Message> GetGlobalTop(Func <ulong, Task <string> > getUserUsername) { var listUsers = await _usersConnector.CommandGetGlobalTop(); var desc = ""; foreach (var user in listUsers) { try { desc += await getUserUsername(user.Id) + ": " + user.Credits + "\n"; } catch (Exception ex) { _logger.LogError($"Couldn't find {user.Id} username via getUserUsername method!", ex); } } return(_messagesHelper.Information(desc, "GlobalTop")); }
public Message GetAboutInfo(int guildsCount) { return(_messagesHelper.Information($"Bot is currently available on {guildsCount} servers!", "About")); }
public async Task <Message> GetCurrentCreditStatus(ulong userId) { var credits = await _usersConnector.GetCredits(userId); return(_messagesHelper.AddCoinsBalanceInformation(_messagesHelper.Information(""), credits)); }