public async Task StarAddedNew(Cacheable <IUserMessage, ulong> msgCacheable, ISocketMessageChannel msgChannel, SocketReaction reaction) { try { var msg = await msgCacheable.GetOrDownloadAsync(); //MSG BLACKLIST if (msgStarBlackDict.ContainsKey(msg.Id)) { short count; msgStarBlackDict.TryGetValue(msg.Id, out count); if (count >= 2) { return; } } ulong channelID; IUserMessage sentMessage = null; //IMessage dmsg = null; //bool specified = true; ulong guildID = (reaction.Channel as IGuildChannel).GuildId; if (starChannelDict.TryGetValue(guildID, out channelID)) { if (reaction.Emote.Name.Equals("⭐") || reaction.Emote.Name.Equals("🌟")) { var chan = (((reaction.Channel as IGuildChannel).Guild as SocketGuild) .GetChannel(channelID) as IMessageChannel); if (chan == null) { return; } /* * if (!msg.IsSpecified) //!String.IsNullOrEmpty(tag) * { * dmsg = await reaction.Channel.GetMessageAsync(msgID, CacheMode.AllowDownload, null); * specified = false; * }*/ if (reaction.UserId == msg.Author.Id) { return; } if (client.CurrentUser.Id == msg.Author.Id) { return; } Random rand = new Random(DateTime.Now.Millisecond); await Task.Delay(rand.Next(50)); if (msgIdDictionary.ContainsKey(msg.Id)) { //USER BLACKLIST if (await CheckBlacklist(msg.Id, reaction.UserId)) { return; } starMsg msgStruct = new starMsg(); msgIdDictionary.TryGetValue(msg.Id, out msgStruct); msgStruct.counter += 1; /*var guild = ((reaction.Channel as IGuildChannel)?.Guild as SocketGuild); * var channel = guild?.GetChannel(channelID) as IMessageChannel; * var msgToEdit = * (IUserMessage) * await channel.GetMessageAsync(msgStruct.starMSGID, CacheMode.AllowDownload, null);*/ msgIdDictionary.TryUpdate(msg.Id, msgStruct); /*await msgToEdit.ModifyAsync(x => { x.Content = $"{msgStruct.counter} {msgToEdit.Content}"; });*/ SaveDatabase(); return; } else { //USER BLACKLIST if (await CheckBlacklist(msg.Id, reaction.UserId)) { return; } if (msg.Attachments.Count < 1) { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Timestamp = DateTimeOffset.UtcNow, Author = new EmbedAuthorBuilder() { IconUrl = (msg.Author.GetAvatarUrl()), Name = $"{msg.Author.Username}#{msg.Author.Discriminator}" }, Description = (msg.Content.Contains("http") ? "Link detected. Copied outside to embed link/picture" : msg.Content) }; sentMessage = await chan.SendMessageAsync( $"{reaction.Emote.Name} in #{msg.Channel.Name}{(msg.Content.Contains("http") ? $" by {msg.Author.Username}#{msg.Author.Discriminator}\n{msg.Content}" : "")}", false, (msg.Content.Contains("http") ? null : eb)); } else { var eb = new EmbedBuilder() { Color = new Color(4, 97, 247), Timestamp = DateTimeOffset.UtcNow, ImageUrl = (msg.Attachments.FirstOrDefault().Url), Author = new EmbedAuthorBuilder() { IconUrl = (msg.Author.GetAvatarUrl()), Name = $"{msg.Author.Username}#{msg.Author.Discriminator}" }, Description = msg.Content }; sentMessage = await chan.SendMessageAsync( $"{reaction.Emote.Name} in #{msg.Channel.Name}\n", false, eb); } starMsg msgStruct = new starMsg { starMSGID = sentMessage.Id, counter = 1 }; msgIdDictionary.TryAdd(msg.Id, msgStruct); SaveDatabase(); } } } } catch (Exception e) { await SentryService.SendError(e); } }
public async Task StarRemovedNew(Cacheable <IUserMessage, ulong> msgCacheable, ISocketMessageChannel msgChannel, SocketReaction reaction) { try { var msg = await msgCacheable.GetOrDownloadAsync(); ulong channelID; ulong guildID = (reaction.Channel as IGuildChannel).GuildId; if (starChannelDict.TryGetValue(guildID, out channelID)) { starMsg msgStruct = new starMsg(); if (msgIdDictionary.TryGetValue(msg.Id, out msgStruct)) { msgStruct.counter -= 1; var guild = ((reaction.Channel as IGuildChannel)?.Guild as SocketGuild); var channel = guild?.GetChannel(channelID) as IMessageChannel; if (channel == null) { return; } var msgToEdit = (IUserMessage) await channel.GetMessageAsync(msgStruct.starMSGID, CacheMode.AllowDownload, null); if (msgToEdit == null) { return; } if (msgStruct.counter < 1) { await msgToEdit.DeleteAsync(); msgIdDictionary.TryRemove(msg.Id, out msgStruct); if (msgStarBlackDict.ContainsKey(msg.Id)) { short count; msgStarBlackDict.TryGetValue(msg.Id, out count); count++; msgStarBlackDict.TryUpdate(msg.Id, count); } else { msgStarBlackDict.TryAdd(msg.Id, 1); } } else { /* * if (msgToEdit.Content.Contains("â")) * { * string subString = msgToEdit.Content.Substring(msgToEdit.Content.IndexOf("â")); * await msgToEdit.ModifyAsync(x => { x.Content = $"{msgStruct.counter} {subString}"; }); * } * else if(msgToEdit.Content.Contains("🌟")) * { * string subString = msgToEdit.Content.Substring(msgToEdit.Content.IndexOf("🌟")); * await msgToEdit.ModifyAsync(x => { x.Content = $"{msgStruct.counter} {subString}"; }); * }*/ msgIdDictionary.TryUpdate(msg.Id, msgStruct); } SaveDatabase(); } } } catch (Exception e) { await SentryService.SendError(e); } }