Esempio n. 1
0
        private async Task SocketClient_ReactionAdded(Cacheable <IUserMessage, ulong> message, Cacheable <IMessageChannel, ulong> channel, SocketReaction reaction)
        {
            IGuildChannel guildChannel;

            if (channel.HasValue)
            {
                guildChannel = channel.Value as IGuildChannel;
            }
            else
            {
                guildChannel = socketClient.GetChannel(channel.Id) as IGuildChannel;
            }

            if (guildChannel == null)
            {
                return;
            }
            else if (!config.SelfStarPreventionServers.Contains(guildChannel.GuildId))
            {
                return;
            }

            if (reaction.Emote.Name != "⭐")
            {
                return;
            }

            //if (PreventedStars.Contains(cache.Id))
            //    return;

            IUserMessage msg;

            if (!message.HasValue)
            {
                msg = (IUserMessage)(await channel.GetOrDownloadAsync()).GetMessageAsync(message.Id);
            }
            else
            {
                msg = message.Value;
            }

            if (msg.Author.Id == reaction.UserId)
            {
                try
                {
                    await msg.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    if (PreventedStars.Contains(message.Id))
                    {
                        await(await channel.GetOrDownloadAsync()).SendMessageAsync($"Prevented self-star by {reaction.User.Value.Mention} *(msg: `{msg.Id}`)*");
                        PreventedStars.Add(message.Id);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to remove self-star in {guildChannel.GuildId}");
                }
            }
        }
Esempio n. 2
0
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            async Task RevokeReaction(IUserMessage message, SocketUser culpritUser)
            {
                await message.RemoveReactionAsync(arg3.Emote, culpritUser);
            }

            if (Equals(arg3.Emote, _ack))
            {
                var culpritUser = _discord.GetUser(arg3.User.Value.Id);

                // We're the only one allowed to do that one!
                if (culpritUser.Id != _discord.CurrentUser.Id)
                {
                    await RevokeReaction(await arg1.GetOrDownloadAsync(), culpritUser);
                }
            }
            else if (Equals(arg3.Emote, _feature))
            {
                var message = await arg1.GetOrDownloadAsync();

                var culpritUser = _discord.GetUser(arg3.User.Value.Id);

                if (_config["approver"] == culpritUser.Id.ToString())
                {
                    var issue = await _github.CreateIssue(message,
                                                          $"{message.Author.Username}'s Feature Request [{message.Id}]",
                                                          "feature");

                    await HandleAck(issue, message, GitHubService.ItemType.Feature);
                }
                else
                {
                    await RevokeReaction(message, culpritUser);
                }
            }
            else if (Equals(arg3.Emote, _bug))
            {
                var message = await arg1.GetOrDownloadAsync();

                var culpritUser = _discord.GetUser(arg3.User.Value.Id);

                if (_config["approver"] == culpritUser.Id.ToString())
                {
                    var issue = await _github.CreateIssue(message,
                                                          $"{message.Author.Username}'s Bug Report [{message.Id}]",
                                                          "bug");

                    await HandleAck(issue, message, GitHubService.ItemType.Bug);
                }
                else
                {
                    await RevokeReaction(message, culpritUser);
                }
            }
        }
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2, SocketReaction arg3)
        {
            async Task RevokeReaction(IUserMessage message, IUser user)
            {
                await message.RemoveReactionAsync(arg3.Emote, user);
            }

            if (Equals(arg3.Emote, _ackYes))
            {
                var associatedMessage = await arg1.GetOrDownloadAsync();

                if (associatedMessage == null || associatedMessage.Id != _nag.LastNagMessage.Id)
                {
                    return;
                }

                foreach (var user in await(await arg1.GetOrDownloadAsync()).GetReactionUsersAsync(_ackYes, 20).FlattenAsync())
                {
                    if (user.Id == _discord.CurrentUser.Id)
                    {
                        continue;                                     // Ignore us
                    }
                    await RevokeReaction(associatedMessage, user);

                    await _nag.AddAckUser(user);
                }
            }
            else if (Equals(arg3.Emote, _ackNo))
            {
                var associatedMessage = await arg1.GetOrDownloadAsync();

                if (associatedMessage == null || associatedMessage.Id != _nag.LastNagMessage.Id)
                {
                    return;
                }

                foreach (var user in await(await arg1.GetOrDownloadAsync()).GetReactionUsersAsync(_ackNo, 20).FlattenAsync())
                {
                    if (user.Id == _discord.CurrentUser.Id)
                    {
                        continue;                                     // Ignore us
                    }
                    await RevokeReaction(associatedMessage, user);

                    await _nag.RemoveAckUser(user);
                }
            }
        }
Esempio n. 4
0
        private async Task ReactionAddedAsync(Cacheable <IUserMessage, ulong> cachedMessage, ISocketMessageChannel originalChannel, SocketReaction reaction)
        {
            // Delete Message if it has a score > 5
            int score   = 5;
            var message = await cachedMessage.GetOrDownloadAsync();

            if (message != null && reaction.User.IsSpecified)
            {
                if (reaction.Emote.Name.Equals("Patboo"))
                {
                    foreach (var item in message.Reactions)
                    {
                        if (item.Key.Name == "Patboo")
                        {
                            if (item.Value.ReactionCount >= score)
                            {
                                await message.Channel.SendMessageAsync(message.Author.Username + " posted a bad meme and he/she should feel bad.");

                                await message.DeleteAsync();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private async Task HandleMessageUpdatedAsync(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
        {
            // If the message was not in the cache, downloading it will result in getting a copy of `after`.
            var message = await before.GetOrDownloadAsync();

            _loggingService.Info($"Message updated: {message} -> {after}");
        }
Esempio n. 6
0
        /// <summary>
        /// Called when a message is edited. If there is a chat log channel assigned to the guild, the edited message is posted in it.
        /// </summary>
        /// <param name="word">The old message before the edit.</param>
        /// <param name="MessageParam">The new message after the edit.</param>
        /// <param name="channel">The channel the edit happened in.</param>
        private async Task Client_MessageUpdated(Cacheable <IMessage, ulong> word, SocketMessage MessageParam, ISocketMessageChannel channel)
        {
            SocketGuildChannel guildChannel = MessageParam.Channel as SocketGuildChannel;
            ulong guild      = guildChannel.Guild.Id;
            ulong logChannel = Data.GetChatLogChannel(guild);

            if (logChannel != 0)
            {
                IMessage words = await word.GetOrDownloadAsync();

                if (words.Author.IsBot)
                {
                    return;
                }

                SocketTextChannel channelPost = guildChannel.Guild.GetTextChannel(logChannel);

                try
                {
                    //Convert the time to EST
                    timeUtc = DateTime.UtcNow;
                    today   = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, easternZone);

                    //Format: Name#1111: "This is a sentence." -- #channel at 1/11/1111 1:11:11 PM EST
                    await channelPost.SendMessageAsync($"{words.Author} has edited \"{words.Content}\" " +
                                                       $"to \"{MessageParam.Content}\" in <#{channel.Name}> at {today} EST");
                }
                catch (Exception)
                {
                    await channel.SendMessageAsync("I do not have permission to post in the chat log channel.");
                }
            }
        }
Esempio n. 7
0
        private async Task MinMaxCloseReactionsCleared(Cacheable <IUserMessage, ulong> cacheable, ISocketMessageChannel messageChannel)
        {
            var message = await cacheable.GetOrDownloadAsync();

            MinMaxCloseMessage minMaxCloseMessage = null;

            if (messages.Any(x => x.Message.Id == message.Id))
            {
                minMaxCloseMessage = messages.FirstOrDefault(x => x.Message.Id == message.Id);
            }
            else
            {
                return;
            }
            if (!(message.Reactions.ContainsKey(stop)))
            {
                await message.AddReactionAsync(stop);
            }
            if (!(message.Reactions.ContainsKey(minimize)))
            {
                await message.AddReactionAsync(minimize);
            }
            if (!(message.Reactions.ContainsKey(maximize)))
            {
                await message.AddReactionAsync(maximize);
            }
            if (!(message.Reactions.ContainsKey(info)))
            {
                await message.AddReactionAsync(info);
            }
        }
Esempio n. 8
0
        private async Task _client_MessageUpdated(Cacheable <IMessage, ulong> b, SocketMessage a, ISocketMessageChannel channel)
        {
            if (a.Id == _client.CurrentUser.Id)
            {
                return;
            }

            var before = await b.GetOrDownloadAsync();

            if (before == null)
            {
                return;
            }
            if (before.Content == a.Content)
            {
                return;
            }
            var author = a.Author as SocketGuildUser;

            if (author == null)
            {
                return;
            }
            await LogServerMessageAsync($"{author.Nickname ?? author.Username}#{author.Discriminator} ({author.Id}) edited their message in {(a.Channel as SocketTextChannel).Mention}:\n" +
                                        $"Before: {before.Content}\n" +
                                        $"After: {a.Content}");
        }
Esempio n. 9
0
        public async Task GuildMemberUpdated(Cacheable <SocketGuildUser, ulong> cacheableOldMember, SocketGuildUser newMember)
        {
            // Note: Use EnforcementEnabled or something in DB.
            var oldMember = await cacheableOldMember.GetOrDownloadAsync();

            if (oldMember == null)
            {
                Log.Warning("Tried to respond to a guild member update for user {UserId}, but they were null!", cacheableOldMember.Id);
                return;
            }

            switch (oldMember.Guild.Id)
            {
            case 550702475112480769:
                await CEMNamingScheme(SpecialGuilds.CrystalExploratoryMissions, cacheableOldMember, newMember);

                break;

            case 550910482194890781:
                await CEMNamingScheme(SpecialGuilds.CrystalExploratoryMissions, cacheableOldMember, newMember);

                break;

            case 318592736066273280:
                await CEMNamingScheme(SpecialGuilds.CrystalExploratoryMissions, cacheableOldMember, newMember);

                break;
            }
        }
Esempio n. 10
0
        public static async Task HandlerAdd(DiscordSocketClient client, IDbService db, Cacheable <IUserMessage, ulong> cachedMessage, SocketReaction reaction)
        {
            var message = await cachedMessage.GetOrDownloadAsync();

            var messageId    = message.Id;
            var userId       = reaction.UserId;
            var reactionName = reaction.Emote.Name;

            if (message.Author.Id == userId)
            {
                return;
            }

            var voteHost = await db.VoteHosts
                           .FirstOrDefaultAsync(vh => vh.MessageId == messageId);

            if (voteHost == null)
            {
                return;
            }

            await db.RemoveVote(messageId, userId);

            await db.AddVote(messageId, userId, reactionName);

            var user = client.GetUser(userId);
            await user.SendMessageAsync($"You have voted for option `{reactionName}`.");

            await message.RemoveReactionAsync(reaction.Emote, userId);
        }
Esempio n. 11
0
        private async Task ReactionAdded(Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            if (channel.Id != 381889909113225237 && channel.Id != 443162366360682508)
            {
                return;
            }
            var emote = new Emoji("#⃣");

            if (emote.Name != reaction.Emote.Name)
            {
                return;
            }
            var msg = await message.GetOrDownloadAsync();

            if (msg is null)
            {
                return;
            }
            if (_handledMessages.Contains(msg.Id))
            {
                return;
            }
            var code = await _handler.GetCode(msg.Content);

            if (code is null)
            {
                return;
            }
            await channel.SendMessageAsync(await _handler.CreateHasteOrGist(code));

            _handledMessages.Enqueue(msg.Id);
        }
Esempio n. 12
0
        public async Task ReactionReceived(Cacheable <IUserMessage, ulong> cacheMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try
            {
                if (reaction.User.Value.IsBot)
                {
                    return;
                }

                //TO BE REMOVED- SAVE TOWNS EVERY 5-10 MINS INSTEAD. CREATE SAFE SHUTDOWN METHOD THAT SAVES TOWNS/USERS ETC.
                TownHandler.SaveTowns();

                var message = await cacheMessage.GetOrDownloadAsync();

                var user = UserHandler.GetUser(reaction.UserId);
                //Console.WriteLine($"Cache {cacheMessage.Id}\nMessage {message.Id}\nReaction: {reaction.MessageId}");

                if (user.ReactionMessages.ContainsKey(message.Id))
                {
                    await EmoteCommands.ParseEmote(user, message, reaction);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 13
0
        private async Task HandleReactionAsync(Cacheable <IUserMessage, ulong> message,
                                               Cacheable <IMessageChannel, ulong> _,
                                               SocketReaction reaction)
        {
            if (reaction.UserId == _client.CurrentUser.Id)
            {
                return;
            }
            if (!_callbacks.TryGetValue(message.Id, out var callback))
            {
                return;
            }
            if (!await callback.Criterion.JudgeAsync(callback.Context, reaction))
            {
                return;
            }
            var callbackTask = Executor.ExecuteAsync(async() =>
            {
                if (await callback.HandleAsync(reaction))
                {
                    RemoveReactionCallback(await message.GetOrDownloadAsync());
                }
            });

            if (callback.RunMode is RunMode.Sequential)
            {
                await callbackTask;
            }
        }
Esempio n. 14
0
        private async Task MessageUpdated(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
        {
            //If message not in cache, if we download it we get an after eather than before
            var message = await before.GetOrDownloadAsync();

            Console.WriteLine($"{message} -> {after}");
        }
Esempio n. 15
0
File: Lua.cs Progetto: ItsKaa/Ditto
        private static Task GuildMemberUpdated(Cacheable <SocketGuildUser, ulong> cachedSocketGuildUserOld, SocketGuildUser socketGuildUser)
        {
            var _ = Task.Run(async() =>
            {
                var socketGuildUserOld = await cachedSocketGuildUserOld.GetOrDownloadAsync().ConfigureAwait(false);
                var addedRoles         = socketGuildUser.Roles.Where(r => socketGuildUserOld.Roles.FirstOrDefault(rr => rr.Id == r.Id) == null);
                var removedRoles       = socketGuildUserOld.Roles.Where(r => socketGuildUser.Roles.FirstOrDefault(rr => rr.Id == r.Id) == null);
                foreach (var role in addedRoles)
                {
                    ExecuteMethods(
                        LuaScriptMethods.RoleChanged,
                        socketGuildUser.Guild,
                        user: socketGuildUser,
                        role: role,
                        roleAdded: true
                        );
                }
                foreach (var role in removedRoles)
                {
                    ExecuteMethods(
                        LuaScriptMethods.RoleChanged,
                        guild: socketGuildUser.Guild,
                        user: socketGuildUser,
                        role: role,
                        roleAdded: false
                        );
                }
            });

            return(Task.CompletedTask);
        }
Esempio n. 16
0
        private async Task onReactionAdd(Cacheable <IUserMessage, ulong> arg1, Cacheable <IMessageChannel, ulong> arg2, SocketReaction arg3)
        {
            if (arg3.MessageId != _context.Message.Id || arg3.UserId == _context.Guild.CurrentUser.Id)
            {
                return;
            }

            SocketUserMessage message = (SocketUserMessage)await arg1.GetOrDownloadAsync();

            await message.RemoveReactionAsync(arg3.Emote, arg3.UserId);

            if (arg3.Emote.Name == "\u25B6")
            {
                if (pageIndex >= pages.Count - 1)
                {
                    return;
                }

                pageIndex += 1;
            }

            else if (arg3.Emote.Name == "\u23EA")
            {
                if (pageIndex <= 0)
                {
                    return;
                }

                pageIndex -= 1;
            }

            await UpdateMessage();
        }
Esempio n. 17
0
        private async Task MessageUpdated(Cacheable <IMessage, ulong> pBefore, SocketMessage pAfter, ISocketMessageChannel pChannel)
        {
            // If the message was not in the cache, downloading it will result in getting a copy of 'after'.
            var lMessage = await pBefore.GetOrDownloadAsync();

            Console.WriteLine($"{lMessage} -> {pAfter} on Channel {pChannel}");
        }
        /// <summary>
        /// The handling method for when a user adds a reaction to the role assignment message. The bot will
        /// assign the associated role to the user if it's assignable.
        /// </summary>
        /// <param name="message">The message the user reacted to</param>
        /// <param name="channel">The channel the message/reaction are in</param>
        /// <param name="reaction">The reaction by the user</param>
        /// <returns></returns>
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> messageCached, Cacheable <IMessageChannel, ulong> channelCached, SocketReaction reaction)
        {
            var message = await messageCached.GetOrDownloadAsync();

            var channel = await channelCached.GetOrDownloadAsync();

            var guildChannel = channel as SocketTextChannel;
            var guild        = GuildRepo.Get(guildChannel.Guild.Id);
            var user         = reaction.User.Value as SocketGuildUser;

            if (message.Id != guild.Settings.RoleAssignment.MessageId)
            {
                return;
            }

            var roleToAdd = guild.Settings.RoleAssignment.Roles.Find(r => r.Reaction == reaction.Emote.ToString());

            // If a user adds an unknown reaction, just delete it.
            if (roleToAdd == null)
            {
                var guildMessage = await channel.GetMessageAsync(message.Id);

                await guildMessage.RemoveReactionAsync(reaction.Emote, user);

                return;
            }

            var discordRoleToAdd = guildChannel.Guild.GetRole(roleToAdd.RoleId);
            await user.AddRoleAsync(discordRoleToAdd);
        }
Esempio n. 19
0
        async Task OnReactionAsync(bool added, Cacheable <IUserMessage, ulong> message, ISocketMessageChannel channel, SocketReaction reaction)
        {
            var msg = await message.GetOrDownloadAsync();

            if (msg is null)
            {
                return;
            }

            if (reaction is null)
            {
                return;
            }

            var userId = reaction.UserId;

            if (msg.Id == PositionsMessageId)
            {
                await LeagueReactionAsync(userId, added, reaction.Emote.Name);

                return;
            }

            if (msg.Id == HuntersMessageId)
            {
                await HuntersReactionAsync(userId, added, reaction.Emote.Name);

                return;
            }
        }
        /// <summary>
        /// The handling method for when a user removes their reaction to the role assignment message. The bot will
        /// remove the associated role from the user if it's assignable.
        /// </summary>
        /// <param name="message">The message the user removed their reaction from</param>
        /// <param name="channel">The channel the message/reaction are in</param>
        /// <param name="reaction">The reaction removed by the user</param>
        /// <returns></returns>
        private async Task OnReactionRemoved(Cacheable <IUserMessage, ulong> messageCached, Cacheable <IMessageChannel, ulong> channelCached, SocketReaction reaction)
        {
            var message = await messageCached.GetOrDownloadAsync();

            var channel = await channelCached.GetOrDownloadAsync();

            var guildChannel = channel as SocketTextChannel;
            var guild        = GuildRepo.Get(guildChannel.Guild.Id);

            if (message.Id != guild.Settings.RoleAssignment.MessageId)
            {
                return;
            }

            var roleToRemove = guild.Settings.RoleAssignment.Roles.Find(r => r.Reaction == reaction.Emote.ToString());

            if (roleToRemove == null)
            {
                return;
            }

            var discordRoleToRemove = guildChannel.Guild.GetRole(roleToRemove.RoleId);

            if (discordRoleToRemove == null)
            {
                return;
            }

            var user = reaction.User.Value as SocketGuildUser;
            await user.RemoveRoleAsync(discordRoleToRemove);
        }
Esempio n. 21
0
        private async Task MessageUpdated(Cacheable <IMessage, ulong> arg1, SocketMessage messageAfter,
                                          ISocketMessageChannel arg2)
        {
            if (messageAfter.Author.IsBot)
            {
                return;
            }
            if (!(arg2 is ITextChannel channel))
            {
                return;
            }
            if (messageAfter.Author.Id == _client.CurrentUser.Id)
            {
                return;
            }
            var message = await arg1.GetOrDownloadAsync();

            if (message.Content == messageAfter.Content)
            {
                return;
            }

            var description =
                $"Author ❯ {messageAfter.Author.Mention}\nId ❯ {messageAfter.Id}\nResponsible User ❯ {messageAfter.Author.Mention}\nChannel ❯ {channel.Mention}\nContent ❯ {message.Content} ⇒ {messageAfter.Content}\nReason ❯ none";

            await SendLog(channel.Guild, "Message Updated", description);
        }
Esempio n. 22
0
        private async Task HandleMessageQueryByReaction(Cacheable <IUserMessage, ulong> message, ulong userWhoReacted, IEmote reactedEmote)
        {
            // Find the user who sent the reaction, so we can DM them
            var user = await _client.GetUserAsync(userWhoReacted);

            if (user == null)
            {
                return;
            }

            // Find the message in the DB
            var msg = await _data.GetMessage(message.Id);

            if (msg == null)
            {
                return;
            }

            // DM them the message card
            await user.SendMessageAsync(embed : await _embeds.CreateMessageInfoEmbed(msg));

            // And finally remove the original reaction (if we can)
            var msgObj = await message.GetOrDownloadAsync();

            if (await msgObj.Channel.HasPermission(ChannelPermission.ManageMessages))
            {
                await msgObj.RemoveReactionAsync(reactedEmote, user);
            }
        }
Esempio n. 23
0
        public async Task CheckReaction(Cacheable <IUserMessage, ulong> cachedMessage, ISocketMessageChannel channel, SocketReaction reaction)
        {
            try {
                if ((reaction.User.IsSpecified && reaction.User.Value.IsBot) || !(channel is SocketGuildChannel))
                {
                    return; //Makes sure it's not logging a message from a bot and that it's in a discord server
                }
                var message              = cachedMessage.GetOrDownloadAsync().Result;
                SocketGuildChannel chnl  = channel as SocketGuildChannel;
                SocketGuild        guild = chnl?.Guild;
                if (guild == null)
                {
                    return;
                }

                ModerationSettings settings = guild.LoadFromFile <ModerationSettings>(false);
                SocketGuildUser    gUser    = guild.GetUser(reaction.UserId);
                var Guild = chnl.Guild;
                if (settings?.badUEmojis.IsNullOrEmpty() ?? true || (reaction.User.Value as SocketGuildUser).CantBeWarned() || reaction.User.Value.IsBot)
                {
                    return;
                }
                if (settings.badUEmojis.Select(emoji => new Emoji(emoji)).Contains(reaction.Emote))
                {
                    await message.RemoveReactionAsync(reaction.Emote, reaction.User.Value);

                    await((SocketGuildUser)reaction.User.Value).Warn(1, "Bad reaction used", channel as SocketTextChannel);
                    IUserMessage warnMessage = await channel.SendMessageAsync(
                        $"{reaction.User.Value.Mention} has been given their {(reaction.User.Value as SocketGuildUser).LoadInfractions().Count.Suffix()} infraction because of bad reaction used");
                }
            } catch (Exception e) {
                await new LogMessage(LogSeverity.Error, "Filter", "Something went wrong with the reaction filter", e).Log();
            }
        }
Esempio n. 24
0
        public async Task HandleMessageDeletionByReaction(Cacheable <IUserMessage, ulong> message, ulong userWhoReacted)
        {
            // Find the message in the database
            var storedMessage = await _data.GetMessage(message.Id);

            if (storedMessage == null)
            {
                return;                        // (if we can't, that's ok, no worries)
            }
            // Make sure it's the actual sender of that message deleting the message
            if (storedMessage.Message.Sender != userWhoReacted)
            {
                return;
            }

            try {
                // Then, fetch the Discord message and delete that
                // TODO: this could be faster if we didn't bother fetching it and just deleted it directly
                // somehow through REST?
                await(await message.GetOrDownloadAsync()).DeleteAsync();
            } catch (NullReferenceException) {
                // Message was deleted before we got to it... cool, no problem, lmao
            }

            // Finally, delete it from our database.
            await _data.DeleteMessage(message.Id);
        }
Esempio n. 25
0
        private async Task ReactionAdded(Cacheable <IUserMessage, ulong> arg1, ISocketMessageChannel arg2,
                                         SocketReaction reaction)
        {
            if (!(arg2 is ITextChannel channel))
            {
                return;
            }
            Server server = null;

            if (Equals(reaction.Emote.Name, "#⃣"))
            {
                _database.Execute(x => server = x.Load <Server>($"{channel.Guild.Id}"));
                if (!server.GetSetting(Setting.Hastebin))
                {
                    return;
                }
                var message = await arg1.GetOrDownloadAsync();

                if (message.Author.IsBot)
                {
                    return;
                }
                if (Regex.IsMatch(message.Content, PublicVariables.CodeBlockRegex,
                                  RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase))
                {
                    await message.Channel.SendMessageAsync(
                        $"{message.Author.Mention} ❯ {message.Content.ToHastebin(_http)}");
                }
            }
        }
Esempio n. 26
0
        private async Task MessageDeletedAsync(Cacheable <IMessage, ulong> cache, ISocketMessageChannel channel)
        {
            var guild = await _database.Guilds.AsNoTracking().FirstAsync(x => x.GuildId == (channel as SocketGuildChannel).Guild.Id);

            if (!guild.EnableDeletionLog)
            {
                return;
            }

            var message = cache.Value ?? await cache.GetOrDownloadAsync();

            if ((string.IsNullOrWhiteSpace(message.Content) && message.Attachments.Count is 0) || message.Author.IsBot)
            {
                return;
            }

            if (guild.MessageLogChannel is 0)
            {
                return;
            }

            var embed = EmbedHelper.Embed(EmbedHelper.Deleted)
                        .WithAuthor(message.Author)
                        .WithThumbnailUrl((message.Author as SocketUser)?.GetAvatar())
                        .WithTitle("Message Deleted")
                        .AddField("**Channel**:", "#" + message.Channel.Name)
                        .AddField("**Content**:", message.Attachments.FirstOrDefault()?.Url ?? message.Content)
                        .WithCurrentTimestamp()
                        .Build();

            var socketGuild = (message.Author as SocketGuildUser)?.Guild;
            var logChannel  = socketGuild.GetTextChannel(guild.MessageLogChannel);
            await logChannel.SendMessageAsync(embed : embed);
        }
Esempio n. 27
0
        public async Task OnMessageEdited(Cacheable <IMessage, ulong> message, SocketMessage m, ISocketMessageChannel channel)
        {
            if (m is not SocketUserMessage msg)
            {
                return;
            }
            if (msg.Author.IsBot)
            {
                return;
            }
            IMessage message2 = await message.GetOrDownloadAsync();

            if (message2.Content != msg.Content && channel is SocketTextChannel textChannel)
            {
                if (Extensions.GetLogChannel(textChannel.Guild) != null && channel != Extensions.GetLogChannel(textChannel.Guild))
                {
                    if (DiscordStaff.Get(textChannel.Guild.Id, "u-" + msg.Author.Id).Count <= 0 ||
                        (textChannel.Guild.GetUser(msg.Author.Id).Roles.Count > 1 &&
                         DiscordStaff.Get(textChannel.Guild.Id, "r-" + textChannel.Guild.GetUser(msg.Author.Id).Roles.Where(x => x.IsEveryone == false).OrderBy(x => x.Position).First().Id).Count > 0))
                    {
                        AutoMod mod = new AutoMod(_client);
                        await mod.FilterMessage(msg, textChannel);
                    }
                }
            }
        }
        private async Task MessageUpdatedAsync(Cacheable <IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
        {
            // If the message was not in the cache, downloading it will result in getting a copy of `after`.
            var message = await before.GetOrDownloadAsync();

            Console.WriteLine($"{message} -> {after}");
        }
Esempio n. 29
0
        private async Task OnStaffVisibility
        (
            Cacheable <IUserMessage, ulong> message,
            bool added
        )
        {
            using (var ctx = new DatabaseContext())
            {
                var post = await ctx.RevisedStarboardPosts.SingleOrDefaultAsync(loadingPost =>
                                                                                loadingPost.MessageId == (long)message.Id &&
                                                                                loadingPost.StarboardChannelId == (long)_starboard.Id);

                if (post == default)
                {
                    // a post doesn't exist to censor - let's ignore this emote then

                    // ctx.RevisedStarboardPosts.Add(new RevisedStarboardPost
                    // {
                    //     MessageId = (long)message.Id,
                    //     StaffToggledVisibility = added,
                    //     StarboardChannelId = (long)_starboard.Id,
                    //     StarboardMessageId = 0
                    // });
                }
                else
                {
                    post.StaffToggledVisibility = added;
                }

                await ctx.SaveChangesAsync();
            }

            await UpdateStarboardPost(await message.GetOrDownloadAsync());
        }
Esempio n. 30
0
        /// <summary>
        /// Checks if given reaction associated to a running game and if the person who game
        /// the reaction is the same who created this game - if so initiates handling the game mechanics
        /// </summary>
        internal static async Task HandleReactionAdded(Cacheable <IUserMessage, ulong> cache, SocketReaction reaction)
        {
            // Only trigger if we listed this messsage and only act on
            // reactions from the user who triggerd the command
            var triviaGame = Global.TriviaGames.FirstOrDefault(game =>
                                                               game.GameMessageId == reaction.MessageId &&
                                                               game.PlayerId == reaction.UserId);

            if (triviaGame != null)
            {
                var msg = await cache.GetOrDownloadAsync();

                // Immediatly remove reaction so user is able to use it as input
                // Check permissions first
                if (reaction.UserId != msg.Author.Id)
                {
                    var user = reaction.User.GetValueOrDefault(null) ?? Global.Client.GetUser(reaction.UserId);
                    try
                    {
                        await msg.RemoveReactionAsync(reaction.Emote, user);
                    }
                    catch (Exception e)

                    {
                        await Logger.Log(new LogMessage(LogSeverity.Warning, $"Discord | Missing Permissions to remove reaction in {msg.Channel}", e.Message, e.InnerException));
                    }
                }
                await triviaGame.HandleReaction(msg, reaction);
            }
        }