void Start() { rb = GetComponent <Rigidbody2D>(); stressSystem = GetComponent <StressSystem>(); anim = GetComponent <Animator>(); trustFactor = GetComponent <TrustFactor>(); flippositive = new Vector2(transform.localScale.x, transform.localScale.y); flipnegative = new Vector2(-transform.localScale.x, transform.localScale.y); healthSystem = GetComponent <HealthSystem>(); }
public TrustFactor Update(TrustFactor trustFactor, int callerId) { using (UBContext ubc = new UBContext()) { TrustFactor exists = ubc.Users_TrustFactor .Where(x => x.TrustFactorId == trustFactor.TrustFactorId) .FirstOrDefault(); if (exists == null) { return(null); } try { exists.Points = trustFactor.Points; ubc.SaveChanges(); return(trustFactor); } catch (Exception ex) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban", Date = DateTime.Now, Function = "Unifiedban.Data.TrustFactorService.Update", Level = SystemLog.Levels.Warn, Message = ex.Message, UserId = callerId }); if (ex.InnerException != null) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban.Data", Date = DateTime.Now, Function = "Unifiedban.Data.TrustFactorService.Update", Level = SystemLog.Levels.Warn, Message = ex.InnerException.Message, UserId = callerId }); } } return(null); } }
public TrustFactor Add(TrustFactor trustFactor, int callerId) { using (UBContext ubc = new UBContext()) { try { ubc.Add(trustFactor); ubc.SaveChanges(); return(trustFactor); } catch (Exception ex) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban", Date = DateTime.Now, Function = "Unifiedban.Data.TrustFactorService.Add", Level = SystemLog.Levels.Warn, Message = ex.Message, UserId = callerId }); if (ex.InnerException != null) { Utils.Logging.AddLog(new SystemLog() { LoggerName = "Unifiedban.Data", Date = DateTime.Now, Function = "Unifiedban.Data.TrustFactorService.Add", Level = SystemLog.Levels.Warn, Message = ex.InnerException.Message, UserId = callerId }); } } return(null); } }
public static void AddPenalty(long chatId, int telegramUserId, TrustFactorLog.TrustFactorAction action, int actionTakenBy) { int penality = 0; switch (action) { default: case Models.TrustFactorLog.TrustFactorAction.limit: penality = int.Parse(CacheData.Configuration["TFLimitPenalty"]); break; case Models.TrustFactorLog.TrustFactorAction.kick: penality = int.Parse(CacheData.Configuration["TFKickPenalty"]); break; case Models.TrustFactorLog.TrustFactorAction.ban: penality = int.Parse(CacheData.Configuration["TFBanPenalty"]); break; case Models.TrustFactorLog.TrustFactorAction.blacklist: penality = CacheData.TrustFactors[telegramUserId].Points; break; } lock (trustFactorLock) { if (!CacheData.TrustFactors.ContainsKey(telegramUserId)) { TrustFactor newTrustFactor = tfl.Add(telegramUserId, -2); if (newTrustFactor == null) { Manager.BotClient.SendTextMessageAsync( chatId: CacheData.ControlChatId, parseMode: ParseMode.Markdown, text: String.Format( "ERROR: Impossible to record Trust Factor for user id {0} !!.", telegramUserId)); return; } CacheData.TrustFactors.Add(telegramUserId, newTrustFactor); } CacheData.TrustFactors[telegramUserId].Points += penality; } MessageQueueManager.EnqueueLog(new ChatMessage() { ParseMode = ParseMode.Markdown, Text = String.Format( "*[Report]*\n" + "Penalty added to user id {0} with reason: {1}\n" + "New trust factor: {2}" + "\nChatId: `{3}`" + "\n\n*hash_code:* #UB{4}-{5}", telegramUserId, action.ToString(), CacheData.TrustFactors[telegramUserId].Points, chatId, chatId.ToString().Replace("-", ""), Guid.NewGuid()) }); LogTools.AddTrustFactorLog(new TrustFactorLog { Action = action, DateTime = DateTime.UtcNow, TrustFactorId = CacheData.TrustFactors[telegramUserId].TrustFactorId, ActionTakenBy = Manager.MyId }); }