public void MergeEmotes(SocketGuild guild, EmoteMergeListItem item) { var guildID = guild.Id.ToString(); var destination = Context.EmoteStats.FirstOrDefault(o => o.GuildID == guildID && o.EmoteID == item.MergeTo); bool isNew = false; if (destination == null) { destination = new EmoteStat() { Count = 0, EmoteID = item.MergeTo, IsUnicode = false, GuildID = guildID, LastOccuredAt = DateTime.MinValue }; isNew = true; } foreach (var source in item.Emotes) { destination.Count += source.Value; var oldEmote = Context.EmoteStats.FirstOrDefault(o => o.GuildID == guildID && o.EmoteID == source.Key); if (oldEmote == null) { continue; } Context.EmoteStats.Remove(oldEmote); } if (isNew) { Context.EmoteStats.Add(destination); } SaveChanges(); }
public void AddOrIncrementEmoteNoCommit(SocketGuild guild, string emote, bool isUnicode) { var guildID = guild.Id.ToString(); var stat = Context.EmoteStats.FirstOrDefault(o => o.GuildID == guildID && o.EmoteID == emote); if (stat == null) { stat = new EmoteStat() { Count = 1, EmoteID = emote, GuildID = guildID, IsUnicode = isUnicode, LastOccuredAt = DateTime.Now }; Context.EmoteStats.Add(stat); } else { stat.Count++; stat.LastOccuredAt = DateTime.Now; } }