internal async Task ReactionAddedAsync(Cacheable <IUserMessage, ulong> Cache, ISocketMessageChannel Channel, SocketReaction Reaction) { if (Reaction.Emote.Name != "⭐") { return; } var Guild = (Reaction.Channel as SocketGuildChannel).Guild; var Message = await Cache.GetOrDownloadAsync(); var Config = GuildHandler.GetGuild(Guild.Id); var StarboardChannel = Guild.GetTextChannel(Config.Starboard.TextChannel) as IMessageChannel; if (Message == null || StarboardChannel == null || Reaction.Channel.Id == Config.Starboard.TextChannel) { return; } var Embed = GetEmbed(Paint.Yellow) .WithAuthor(Message.Author.Username, Message.Author.GetAvatarUrl()) .WithFooter(Message.Timestamp.ToString("F")); var ReactionCount = Message.Reactions.Count(x => x.Key.Name == "⭐"); if (!string.IsNullOrWhiteSpace(Message.Content)) { Embed.WithDescription(Message.Content); } if (Message.Attachments.FirstOrDefault() != null) { Embed.WithImageUrl(Message.Attachments.FirstOrDefault().Url); } var Exists = Config.Starboard.StarboardMessages.FirstOrDefault(x => x.MessageId == Message.Id); if (Config.Starboard.StarboardMessages.Contains(Exists)) { Exists.Stars++; var SMsg = await StarboardChannel.GetMessageAsync(Exists.StarboardMessageId, CacheMode.AllowDownload) as IUserMessage; await SMsg.ModifyAsync(x => { x.Content = $"{StringHelper.Star(Exists.Stars)}{Exists.Stars} {(Reaction.Channel as ITextChannel).Mention} ID: {Exists.StarboardMessageId}"; x.Embed = Embed.Build(); }); } else { var Msg = await StarboardChannel.SendMessageAsync( $"{StringHelper.Star(ReactionCount)}{ReactionCount} {(Reaction.Channel as ITextChannel).Mention} ID: {Reaction.MessageId}", embed : Embed.Build()); Config.Starboard.StarboardMessages.Add(new StarboardMessage { Stars = 1, MessageId = Message.Id, StarboardMessageId = Msg.Id, AuthorId = Message.Author.Id, ChannelId = Message.Channel.Id }); } GuildHandler.Save(Config); }
internal async Task UserLeftAsync(SocketGuildUser User) { var Config = GuildHandler.GetGuild(User.Guild.Id); await WebhookService.SendMessageAsync(new WebhookOptions { Name = Client.CurrentUser.Username, Webhook = Config.LeaveWebhook, Message = !Config.LeaveMessages.Any() ? $"**{User.Username}** abandoned us! {Emotes.Squint}" : StringHelper.Replace(Config.LeaveMessages[Random.Next(0, Config.LeaveMessages.Count)], User.Guild.Name, User.Username) }); }
internal async Task UserJoinedAsync(SocketGuildUser User) { var Config = GuildHandler.GetGuild(User.Guild.Id); await WebhookService.SendMessageAsync(new WebhookOptions { Name = Client.CurrentUser.Username, Webhook = Config.JoinWebhook, Message = !Config.JoinMessages.Any() ? $"**{User.Username}** is here to rock our world! Yeah, baby!" : StringHelper.Replace(Config.JoinMessages[Random.Next(0, Config.JoinMessages.Count)], User.Guild.Name, User.Mention) }); var Role = User.Guild.GetRole(Config.Mod.JoinRole); if (Role != null) { await User.AddRoleAsync(Role).ConfigureAwait(false); } }
internal async Task MessageDeletedAsync(Cacheable <IMessage, ulong> Cache, ISocketMessageChannel Channel) { var Config = GuildHandler.GetGuild((Channel as SocketGuildChannel).Guild.Id); var Message = await Cache.GetOrDownloadAsync(); if (Message == null || Config == null || !Config.Mod.LogDeletedMessages || Message.Author.IsBot) { return; } Config.DeletedMessages.Add(new MessageWrapper { ChannelId = Channel.Id, MessageId = Message.Id, AuthorId = Message.Author.Id, DateTime = Message.Timestamp.DateTime, Content = Message.Content ?? Message.Attachments.FirstOrDefault()?.Url }); GuildHandler.Save(Config); }