public async Task AddReminder(IUserMessage message, ulong userId, DateTime reminderTime) { var reminder = new Reminder(message.GetGuild().Id, message.Channel.Id, message.Id, reminderTime); reminder.Users.Add(userId); reminders.Add(message.Id, reminder); SaveData(); var emoji = new Emoji(emojiId); await message.AddReactionAsync(emoji); }
private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { // Try get reaction role ReactionRole reactionRole = await this.GetReactionRoleIfValid(message, channel, reaction); // Reaction Role not found or no Reactions - skip if (reactionRole == null || !reactionRole.Reactions.Any()) { return; } // If Item matching added Reaction doesn't exist for reaction role - skip ReactionRoleItem item = reactionRole.Reactions.FirstOrDefault(x => x.ReactionEmote.Name == reaction.Emote.Name && x.Role != null); if (item == null) { return; } // Need to fetch message and guild to get user and role IUserMessage userMessage = await message.DownloadAsync(); IGuild guild = userMessage.GetGuild(); IGuildUser user = await guild.GetUserAsync(reaction.UserId); IRole role = guild.GetRole(item.Role.GetValueOrDefault()); if (role != null) { if (!user.RoleIds.Contains(role.Id)) { await user.AddRoleAsync(role); } } } catch (Exception ex) { await Utils.Logger.LogExceptionToDiscordChannel( ex, $"Role Reaction Added - MessageId: {message.Id}", (channel as IGuildChannel)?.GuildId.ToString(), (reaction.User.GetValueOrDefault() as IGuildUser)?.GetName()); } }
private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> messageCache, ISocketMessageChannel channel, SocketReaction reaction) { try { if (reaction.Emote.Name != "💬") { return; } if (channel is SocketGuildChannel guildChannel) { IUserMessage message = await messageCache.DownloadAsync(); await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); if (string.IsNullOrEmpty(message.Content)) { return; } Quote quote = await this.quoteDb.LoadOrCreate(message.Author.Id + "_" + message.Id); quote.Content = message.Content; quote.UserId = message.Author.Id; quote.GuildId = guildChannel.Guild.Id; quote.MessageLink = this.GetMessageLink(message); quote.UserName = message.Author.Username; quote.QuoteId = await this.GetNextQuoteId(message.GetGuild(), message.GetAuthor()); quote.SetDateTime(message.CreatedAt); await this.quoteDb.Save(quote); Log.Write("Got quote: " + message.Content, "Bot"); } } catch (Exception ex) { Log.Write(ex); } }
private async Task ReactionRemoved(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { // Try get reaction role ReactionRole reactionRole = await this.GetReactionRoleIfValid(message, channel, reaction); // Reaction Role not found or no Reactions - skip if (reactionRole == null || !reactionRole.Reactions.Any()) { return; } // If Item matching added Reaction doesn't exist for reaction role - skip ReactionRoleItem item = reactionRole.Reactions.FirstOrDefault(x => x.ReactionEmote.Name == reaction.Emote.Name && x.Role != null); if (item == null) { return; } IUserMessage userMessage = await message.DownloadAsync(); IGuild guild = userMessage.GetGuild(); IGuildUser user = await guild.GetUserAsync(reaction.UserId); IRole role = guild.GetRole(item.Role.GetValueOrDefault()); if (role != null) { if (user.RoleIds.Contains(role.Id)) { await user.RemoveRoleAsync(role); } } } catch (Exception ex) { Log.Write(ex); } }
private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> incomingMessage, ISocketMessageChannel channel, SocketReaction reaction) { try { // Don't react to your own reacts! if (reaction.UserId == Program.DiscordClient.CurrentUser.Id) { return; } // Only handle reacts to help embed if (!activeHelpEmbeds.ContainsKey(incomingMessage.Id)) { return; } ActiveHelp helpWindow = activeHelpEmbeds[incomingMessage.Id]; helpWindow.LastInteractedWith = DateTime.Now; // Only handle reacts from the original user, remove the reaction if (helpWindow.UserId != reaction.UserId) { IUserMessage message = await incomingMessage.DownloadAsync(); await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); return; } // Only handle relevant reacts if (!HelpEmotes.Contains(reaction.Emote)) { IUserMessage message = await incomingMessage.DownloadAsync(); await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); return; } if (channel is SocketGuildChannel guildChannel) { IUserMessage message = await incomingMessage.DownloadAsync(); await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value); // Adjust current page if (reaction.Emote.Equals(First)) { helpWindow.CurrentPage = 0; } else if (reaction.Emote.Equals(Previous)) { helpWindow.CurrentPage -= 1; } else if (reaction.Emote.Equals(Next)) { helpWindow.CurrentPage += 1; } else if (reaction.Emote.Equals(Last)) { helpWindow.CurrentPage = -1; } Permissions permissions = CommandsService.GetPermissions(message.GetAuthor()); int currentPage = helpWindow.CurrentPage; Embed embed = GetHelp(message.GetGuild(), permissions, helpWindow.CurrentPage, out currentPage); // Update current page helpWindow.CurrentPage = currentPage; await message.ModifyAsync(x => x.Embed = embed); } } catch (Exception ex) { Log.Write(ex); } }
private string GetMessageLink(IUserMessage message) => $"https://discord.com/channels/{message.GetGuild().Id}/{message.Channel.Id}/{message.Id}";