public Globals(IDiscordClient client, IGuild guild, IMongoDatabase database, SendingService sender, RulesService rulesService, ReputationService reputationService) { Client = client; Guild = guild; Database = database; Sender = sender; RulesService = rulesService; ReputationService = reputationService; }
public void TestDownVoteAsUser() { // Test downvoting a high-rep user comment var userRep = 500000; var voterRep = 0; var amount = -10; var scoreAdj = ReputationService.GetReputationAdjustedAmount( amount: amount, targetRep: userRep, actorRep: voterRep); Assert.IsTrue(scoreAdj < 0); }
public void TestRepB() { Int64 InitialScore = 1000; Int64 authorRep = 500000; Int64 userRep = 500000; Int64 vote; // Voted up vote = +100000; var adj = ReputationService.GetReputationAdjustedAmount(vote, authorRep, userRep); var newScore = InitialScore + adj; Assert.IsTrue(newScore > InitialScore); // Voted down vote = -100000; adj = ReputationService.GetReputationAdjustedAmount(vote, authorRep, userRep); newScore = InitialScore + adj; Assert.IsTrue(newScore < InitialScore); }
public async Task <ActionResult> Post(Vote v) { if (!ModelState.IsValid) { return(Json(new { success = false, message = "Invalid" })); } // Bad parameters check if (v == null || v.a < 1) { return(Json(new { success = false, message = "Invalid" })); } // Do checks using (var db = new ZapContext()) { var postInfo = await db.Posts .Where(p => p.PostId == v.Id) .Select(p => new { p.Score, p.UserId.Reputation }) .FirstOrDefaultAsync().ConfigureAwait(true); var userAppId = User.Identity.GetUserId(); double scoreAdj = 0.0; if (userAppId == null) // Anonymous vote { // Check if vote tx has been claimed var txIsValid = await db.LightningTransactions .Where(tx => tx.Id == v.tx) .Select(tx => tx.IsSettled && !tx.IsSpent && tx.Amount >= v.a) .FirstOrDefaultAsync().ConfigureAwait(true); // bool default is false if (!txIsValid) { return(Json(new { success = false, message = "No transaction to vote with" })); } scoreAdj = ReputationService.GetReputationAdjustedAmount( amount: v.a * (v.d == 1 ? 1 : -1), targetRep: v.d == 1 ? 0 : postInfo.Reputation, actorRep: 0); } else { var userInfo = await db.Users .Where(u => u.AppId == userAppId) .Select(u => new { hasFunds = u.Funds.Balance > v.a, u.Reputation }) .FirstOrDefaultAsync().ConfigureAwait(true); // bool default is false if (!userInfo.hasFunds) { return(Json(new { success = false, message = "Error with requesting user." })); } scoreAdj = ReputationService.GetReputationAdjustedAmount( amount: v.a * (v.d == 1 ? 1 : -1), targetRep: v.d == 1 ? 0 : postInfo.Reputation, actorRep: userInfo.Reputation); } if (postInfo == null) { return(Json(new { success = false, message = "Invalid Post" })); } // All good - queue processing - this part is slower, so it will be done in a background job // Return the optimistic result to the user to improve UI response BackgroundJob.Enqueue <VoteService>(x => x.PostVote( userAppId, v.Id, // postId v.a, // amount v.d == 1, // isUpvote v.tx // txid )); // Note that this is actually going to be saved in the background job // we are only sending the optimistic estimate here var newScore = postInfo.Score + scoreAdj; // Return quick results return(Json(new { success = true, delta = v.d == 1 ? 1 : -1, scoreStr = newScore.ToAbbrString(), deltaCommunity = Convert.ToInt32(v.a * 0.1 * (v.d == 1 ? 1.0 : -1.0)) })); } }
public Reputation(ReputationService repService, LeaderboardService lbService, IMongoCollection <User> dbUsers) { _repService = repService; _lbService = lbService; _dbUsers = dbUsers; }
public SelectProcessor(MapManager mapManager, CharacterRepository characterRepository, ReputationService reputationService) { this.mapManager = mapManager; this.characterRepository = characterRepository; this.reputationService = reputationService; }