private async Task Client_ReactionRemoved(Discord.Cacheable <Discord.IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { // get message, check conditions var m = await message.GetOrDownloadAsync(); var textChannel = channel as IGuildChannel; // only message from the bot if (!FromCurrentUser(m)) { return; } // get the role from the first part of the message var role = GetRole(m, textChannel, reaction); if (role == null) { return; } // add the role to the user var user = client.GetGuild(textChannel.Guild.Id).GetUser(reaction.UserId); if (user == null) { return; } // remove role await user.RemoveRoleAsync(role); }
private static async Task Client_MessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> arg1, ISocketMessageChannel arg2) { IMessage baseMessage = await arg1.GetOrDownloadAsync(); IUserMessage userMessage = baseMessage as IUserMessage; SocketTextChannel guildChannel = arg2 as SocketTextChannel; if ((userMessage != null) && guildChannel != null) { if (TryGetLogChannel(guildChannel.Guild, DiscordEventType.MessageDeleted, out SocketTextChannel logChannel, out EmbedBuilder embed)) { embed.Title = "Message deleted. For a copy see below"; embed.Description = $"Location: {guildChannel.Mention}\n" + $"Author: {userMessage.Author} ({userMessage.Author.Mention})\n" + $"Original Timestamp: {userMessage.Timestamp}\n"; await logChannel.SendEmbedAsync(embed); Embed messageEmbed = userMessage.Embeds.FirstOrDefault() as Embed; await logChannel.SendMessageAsync(userMessage.Content.Replace("@everyone", "@-everyone").Replace("<@&", "<Role-").Replace("<@", ",<@User-").MaxLength(EmbedHelper.MESSAGECONTENT_MAX), embed : messageEmbed); } } else if (guildChannel != null) { if (TryGetLogChannel(guildChannel.Guild, DiscordEventType.MessageDeleted, out SocketTextChannel logChannel, out EmbedBuilder embed)) { embed.Title = "Message deleted. Too old to be cached"; embed.Description = $"Location: {guildChannel.Mention}\n" + $"Author: unknown\n" + $"Original Timestamp: unknown\n"; await logChannel.SendEmbedAsync(embed); } } }
private async Task Client_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { foreach (Giveaway giveaway in GiveawayManager.Giveaways) { if (giveaway.MessageID == reaction.MessageId) { if (reaction.Emote.Name == "🎉") { if (!giveaway.UsersID.Contains(reaction.UserId) && giveaway.CreatorID != reaction.UserId) { giveaway.UsersID.Add(reaction.UserId); GiveawayManager.Save(); } //await channel.SendMessageAsync("Successfully entered giveaway!"); } } } if (reaction.MessageId == Global.MessageIdToTrack) { //string[] emojies = new string[Global.emojies.Length]; // string emoji = Global.emojies[Global.selectedEmoji]; //for (int i = 0; i < emojies.Length; i++) { //emojies[i] = Global.emojies[i]; //if (reaction.Emote.Name == emojies[i]) { string message = "__" + reaction.User.Value.Username + "__ reacted with " + reaction.Emote; await channel.SendMessageAsync(message); // break; } } } }
private async Task Client_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { // get the message var m = await message.GetOrDownloadAsync(); var textChannel = channel as IGuildChannel; // only from the bot if (!FromCurrentUser(m)) { return; } var role = GetRole(m, textChannel, reaction); if (role == null) { return; } // add the role to the user var user = client.GetGuild(textChannel.Guild.Id).GetUser(reaction.UserId); if (user == null) { return; } Console.WriteLine($"Added {user} to role {role}"); await user.AddRoleAsync(role); }
static async Task DeletedMessage(Discord.Cacheable <Discord.IMessage, ulong> message, ISocketMessageChannel channel) { if (SentMessages.TryGetValue(message.Id, out var toDelete)) { SentMessages.TryRemove(message.Id, out _); await toDelete.DeleteAsync(); } }
private async Task Client_MessageUpdated(Discord.Cacheable <Discord.IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel) { if (CommandMessageResults.ContainsKey(after.Id)) { // todo consider making the limit on update time-limited as well // re-invoke the command handler. this assumes that the command module is using ReplyOrUpdateAsync await OnCommandRetryHandler?.Invoke(after); } }
private async Task CheckReactRemove(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { if (arg2.Id != Rolecard.ChannelID) { return; } var usr = client.GetGuild(Rolecard.ServerID).GetUser(arg3.UserId); var guild = client.GetGuild(Rolecard.ServerID); var msg = await guild.GetTextChannel(Rolecard.ChannelID).GetMessageAsync(Rolecard.MessageID); if (arg3.MessageId != msg.Id) { return; } if (arg3.User.Value.IsBot) { return; } //doesnt contain "a" tag RoleCard.RoleEmoteDesc redVal = null; var sem = arg3.Emote.ToString(); redVal = Rolecard.RoleEmojiIDs.Any(x => x.Emote == sem) ? Rolecard.RoleEmojiIDs.First(x => x.Emote == sem) : null; if (redVal == null) { await msg.RemoveReactionAsync(arg3.Emote, usr); return; } var role = guild.GetRole(redVal.RoleID); if (!usr.Roles.Contains(role)) { return; } await usr.RemoveRoleAsync(role, new RequestOptions() { AuditLogReason = "Self-Assigned role" }); try { await usr.SendMessageAsync("", false, new EmbedBuilder() { Title = $"**{guild.Name}**", Description = $"You were removed from the role **\"{role.Name}\"**", Color = Color.Green }.Build()); } catch { } }
private async Task _SocketClient_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { if (arg3.UserId == this._Client.CurrentUser.Id || arg3.User.Value.IsBot == true) { return; } ulong MainMsgID = arg3.MessageId; ReactionRoleCommands Rc = new ReactionRoleCommands(this._Client); string SQL = ""; switch (arg3.Emote.GetType().ToString()) { case "Discord.Emoji": SQL = $@"select [role] FROM reaction_roles WHERE rmID = (SELECT rmID FROM reaction_messages WHERE messageID = {MainMsgID}) AND rID = (SELECT rID FROM reactions WHERE reaction_text = '{arg3.Emote.Name}')"; break; case "Discord.Emote": SQL = $@"select [role] FROM reaction_roles WHERE rmID = (SELECT rmID FROM reaction_messages WHERE messageID = {MainMsgID}) AND rID = (SELECT rID FROM reactions WHERE reaction_text = '<:{(arg3.Emote as Emote).Name}:{(arg3.Emote as Emote).Id}>')"; break; } using (SQLiteConnection conn = new SQLiteConnection(Support.DbConnectionString)) { conn.Open(); SQLiteCommand Cmd = new SQLiteCommand(SQL, conn); SQLiteDataReader Reader = Cmd.ExecuteReader(); if (Reader.HasRows) { Reader.Read(); var Chann = arg3.Channel as SocketGuildChannel; var Guild = Chann.Guild; var Role = Guild.Roles.FirstOrDefault(x => x.Name == Reader.GetString(0)); if (Role != default(SocketRole)) { var user = arg3.User.Value; await(user as IGuildUser).AddRoleAsync(Role); } } Reader.Close(); Cmd.Dispose(); conn.Close(); } }
private async Task _SocketClient_ReactionRemoved(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { string MessageID = arg1.Value.Id.ToString(); string Reaction = arg3.Emote.Name; if (this.Reactions.ContainsKey(MessageID) && this.Reactions[MessageID].ContainsKey(Reaction)) { //var Role = arg1.Value.Channel. } }
static async Task UpdatedMessage(Discord.Cacheable <Discord.IMessage, ulong> message, SocketMessage updatedMessage, ISocketMessageChannel channel) { if (SentMessages.TryGetValue(message.Id, out var oldMessage)) { var res = await GetResponse(updatedMessage.Content, updatedMessage.Author.Discriminator); await oldMessage.ModifyAsync((props) => props.Embed = res); } else { await ProcessMessage(updatedMessage); } }
private async Task MessageUpdated(Discord.Cacheable <Discord.IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel) { if (before.Value == null) { return; } if (!_cachedEditedMessages.ContainsKey(channel.Id)) { _cachedEditedMessages.Add(channel.Id, new Stack <Discord.IMessage>()); } _cachedEditedMessages[channel.Id].Push(before.Value); }
private async Task Client_MessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> arg1, ISocketMessageChannel arg2) { // if the original message was successful and is deleted, delete the related messages if (CommandMessageResults.ContainsKey(arg1.Id)) { var messageId = CommandMessageResults[arg1.Id]; try { // delete the result of the original command message await arg2.DeleteMessageAsync(messageId); } catch (HttpException) { } } }
private async Task OnMessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> message, ISocketMessageChannel arg2) { var id = message.Id; if (_responseCache.TryGetValue(id, out var record) && record is ResultCompletionData action) { foreach (var msg in action.Messages) { try { await msg.DeleteAsync(); } finally { } } } }
internal static async Task MessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> cachedMsg, ISocketMessageChannel channel) { if (cachedMsg.HasValue) { var imsg = cachedMsg.Value; if (imsg is SocketUserMessage msg) { SocketCommandContext context = new SocketCommandContext(Globals.discord, msg); bool suspicious = await OwlBrain.EvaluateSuspiciousness(context, msg); if (suspicious) { await OwlBrain.ReportSuspicious(context, msg, "Suspicious message was deleted"); } } } }
private async Task _discord_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { var msg = await arg1.GetOrDownloadAsync(); var user = arg3.User.GetValueOrDefault(); if (msg.Reactions[arg3.Emote].IsMe) { return; } if (user == null) { return; } if (_config.Owners.Contains(user.Id)) { await msg.AddReactionAsync(arg3.Emote); } }
private static async Task Client_MessageUpdated(Discord.Cacheable <Discord.IMessage, ulong> old, SocketMessage updated, ISocketMessageChannel arg3) { IMessage baseMessage = await old.GetOrDownloadAsync(); IUserMessage oldMessage = baseMessage as IUserMessage; IUserMessage newMessage = updated as IUserMessage; SocketTextChannel guildChannel = arg3 as SocketTextChannel; if ((oldMessage != null) && newMessage != null && guildChannel != null && !oldMessage.Author.IsBot && !oldMessage.Author.IsWebhook) { if (TryGetLogChannel(guildChannel.Guild, DiscordEventType.MessageUpdated, out SocketTextChannel logChannel, out EmbedBuilder embed)) { StringBuilder description = new StringBuilder($"Location: {guildChannel.Mention}\n" + $"Author: {oldMessage.Author} ({oldMessage.Author.Mention})\n" + $"Message Link: {oldMessage.GetMessageURL(guildChannel.Guild.Id)}\n"); if (newMessage.IsPinned != oldMessage.IsPinned) { description.Append("Pinned: "); description.AppendLine(newMessage.IsPinned.ToString(CultureInfo.InvariantCulture)); } bool resend = false; if (newMessage.EditedTimestamp != oldMessage.EditedTimestamp) { embed.Title = "Message edited. For a copy see below"; resend = true; } else { embed.Title = "Message updated"; } embed.Description = description.ToString(); await logChannel.SendEmbedAsync(embed); if (resend) { await logChannel.SendMessageAsync(oldMessage.Content.Replace("@everyone", "@-everyone").Replace("<@&", "<Role-").Replace("<@", ",<@User-").MaxLength(EmbedHelper.MESSAGECONTENT_MAX)); } } } }
public async Task ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> msg, ISocketMessageChannel chan, SocketReaction react) { string emote = react.Emote.ToString(); if (react.UserId != Program.p.client.CurrentUser.Id && (emote == "✅" || emote == "❌")) { var downloadedMsg = await msg.GetOrDownloadAsync(); if (downloadedMsg.Author.Id == Program.p.client.CurrentUser.Id) { if (emote == "✅") { await AcceptFriendRequestAsync(downloadedMsg, react.UserId); } else if (emote == "❌") { await DeleteFriendRequestAsync(downloadedMsg, react.UserId); } } } }
private Task DiscordClient_MessageUpdated(Discord.Cacheable <Discord.IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) { return(Task.Factory.StartNew(() => { if (DateTimeOffset.Now - arg2.CreatedAt > new TimeSpan(1, 0, 0)) { return; } string text = arg2.Content.Trim(); if (arg2.Author.IsBot) { return; } if (text.ToLower().StartsWith("!bot ")) { text = text.Replace("!bot ", ""); } else if (text.StartsWith(Mention)) { text = text.Replace(Mention, "").Trim(); } else { return; } try { using (ICommand command = CommandManager.Parse(text, CommandType.Discord)) command.ExecuteAsBot(arg2); } catch (Exception ex) { arg2.Channel.SendMessageAsync(ex.Message); } })); }
private async Task OnReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { string segIndex = ""; messageMarker messageMarker = messageMarkers[channel.Id]; if (reaction.User.Value.IsBot || message.Id != messageMarker.messageId) { return; } Adventure adventure = adventures[messageMarker.adventureName]; AdventureSegment segment = adventure.segments[messageMarker.segIndex]; foreach (AdventureChoice choice in segment.choices) { Emoji emoji = new Emoji(choice.emote); IUserMessage msg = await message.GetOrDownloadAsync(); if ((await msg.GetReactionUsersAsync(emoji, 5).FlattenAsync()).Count() > 1) { segIndex = choice.target; } } if (adventure.segments[segIndex].choices.Count() > 0) { IUserMessage newmsg = await SendSegmentMessage(channel, messageMarker.adventureName, segIndex); messageMarkers[channel.Id] = new messageMarker(newmsg.Id, messageMarker.adventureName, segIndex); } else { IncrementPlays(messageMarker.adventureName); await SendEndingMessage(channel, messageMarker.adventureName, segIndex); messageMarkers.Remove(channel.Id); } }
private async Task ReactionAddedHandler(Discord.Cacheable <Discord.IUserMessage, ulong> userMessage, ISocketMessageChannel messageChannel, SocketReaction reaction) { SocketGuildChannel guildChannel = messageChannel as SocketGuildChannel; SocketGuildUser user = guildChannel.Guild.Users.FirstOrDefault(x => x.Id == reaction.UserId); DiscordServer server = _main.ServerList.FirstOrDefault(x => x.ServerId == guildChannel.Guild.Id); if (server == null || user == null) { return; } //Reaction Locks foreach (var reactionLock in server.ReactionLockList.Where(x => x.ChannelId == guildChannel.Id && x.MessageId == userMessage.Id)) { if (reactionLock.Emote == reaction.Emote.ToString()) { var giveRole = guildChannel.Guild.Roles.FirstOrDefault(x => x.Id == reactionLock.GiveRole); var takeRole = guildChannel.Guild.Roles.FirstOrDefault(x => x.Id == reactionLock.TakeRole); if (giveRole == null) { return; } if (!user.Roles.Contains(giveRole)) { BotFrame.consoleOut($"Adding role @{giveRole} to user {user} in server {guildChannel.Guild.Name}"); await user.AddRoleAsync(giveRole); if (takeRole != null) { BotFrame.consoleOut($"Removing role @{takeRole} from user {user} in server {guildChannel.Guild.Name}"); await user.RemoveRoleAsync(takeRole); } } } } //-------------- }
private async Task CMessageUpdated(Discord.Cacheable <Discord.IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) => await ReceiveMessage(arg2);
public static async Task LogEditedMessage(Discord.Cacheable <Discord.IMessage, ulong> arg1, SocketMessage arg2, ISocketMessageChannel arg3) { }
public static async Task LogDeletedMessage(Discord.Cacheable <Discord.IMessage, ulong> arg1, ISocketMessageChannel arg2) { }
private async Task _SocketClient_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3) { }
private async Task ReactionRemoved(Discord.Cacheable <Discord.IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { await TicketVote(reaction, channel, false); }
private async Task ReactionAddedAsync(Discord.Cacheable <Discord.IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction reaction) { await UpdateRoleAsync(reaction, isRemove : false); }
private async Task RunReaction(Discord.Cacheable <Discord.IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction, bool added) { var unicodeNumberResult = IsUnicodeNumberEmote(reaction.Emote.Name); if (unicodeNumberResult == -1) { return; } if (!(channel is ITextChannel tChannel)) { return; } if (!Local.LastConfig.IsAcceptable(tChannel.Guild?.Id ?? 0)) { return; } if (!reaction.User.IsSpecified) { return; } if (reaction.User.Value.IsBot || reaction.User.Value.IsWebhook) { return; } var message = await TryGetMessage(cache, tChannel, reaction); if (message == null) { return; } if (!message.Author.IsBot) { return; } var config = GetConfig(tChannel.GuildId); if (config == null) { return; } var match = config.RoleMessages.FirstOrDefault(x => x.MessageId == cache.Id); if (match == null) { return; } if (unicodeNumberResult > match.Roles.Count) { return; } var roleMatch = match.Roles[unicodeNumberResult - 1]; var role = tChannel.Guild.GetRole(roleMatch); if (role == null) { return; } var bot = await tChannel.Guild.GetCurrentUserAsync(); if (!(bot is SocketGuildUser gBot) || !gBot.GuildPermissions.ManageRoles || role.Position >= gBot.Hierarchy || !(reaction.User.Value is IGuildUser gUser)) { return; } if (added) { await gUser.AddRoleAsync(role); } else { await gUser.RemoveRoleAsync(role); } }
private async Task ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { await RunReaction(cache, channel, reaction, true); }
private async Task DiscordClient_ReactionAdded(Discord.Cacheable <Discord.IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction) { try { Log("Reaction coming: " + reaction.User.Value.Username); /* Validity check to continue: * - Reacton must be added to the control message sent by this bot * - User must be a valid user (not a bot, not an admin) * - User should be online when reaction check message has been sent * - User shouldn't be reacted to the message before */ if (message.Id == reactionCheckMessageID && !reaction.User.Value.IsBot && !IsAdmin(reaction.UserId) && !userPresence[reaction.UserId]) { Log("Adding to list: " + reaction.User.Value.Username); userPresence[reaction.UserId] = true; Log("Set to true: " + reaction.User.Value.Username); // Prepare the result line for user SocketGuildUser user = GetUser(reaction.UserId); TimeSpan timeDiff = DateTime.Now - reactionCheckMessageTime; string newLine = string.Format("\n{0, -20} {1}", user.Nickname ?? user.Username, timeDiff.Minutes > ACCEPTED_DELAY_MINUTES ? "+ " + timeDiff.Minutes + " dk" : string.Empty); // Add user to result list message IUserMessage resultMessage = await GetMessage(LOG_TEXT_ID, reactionResultMessageID); Embed oldEmbed = null; EmbedBuilder updatedEmbed = new EmbedBuilder(); foreach (Embed embed in resultMessage.Embeds) { oldEmbed = embed; } if (oldEmbed == null) { Log("ERROR::OldEmbed == null"); } Log("Prepare new embed"); updatedEmbed.Title = oldEmbed.Title; updatedEmbed.Color = oldEmbed.Color; updatedEmbed.Timestamp = oldEmbed.Timestamp; updatedEmbed.Description = oldEmbed.Description + newLine; await resultMessage.ModifyAsync(msg => msg.Embed = updatedEmbed.Build()); Log("New embed added"); } else { StringBuilder builder = new StringBuilder(); builder.Append(reaction.User.Value.Username + " reaction denied. Reason:"); if (message.Id != reactionCheckMessageID) { builder.Append("\n - Incorrect message"); } if (reaction.User.Value.IsBot) { builder.Append("\n - User is bot"); } if (IsAdmin(reaction.UserId)) { builder.Append("\n - User is admin"); } if (userPresence[reaction.UserId]) { builder.Append("\n - Already reacted"); } Log(builder.ToString()); } } catch (Exception e) { Log("EXCEPTION_HANDLED: " + e.Message); } }