Ejemplo n.º 1
0
        public async Task HandleModMailUserReply(SocketMessage message)
        {
            var           bot   = Global.Bot;
            var           guild = bot.GetGuild(Global.ServerID);
            ModMailThread modMailThread;

            using (var db = new Database())
            {
                modMailThread = db.ModMailThreads
                                .Include(sub => sub.Subscriber)
                                .Where(th => th.UserId == message.Author.Id && th.State != "CLOSED")
                                .FirstOrDefault();
            }

            if (modMailThread != null)
            {
                UpdateModThreadUpdatedField(modMailThread.ChannelId, "USER_REPLIED");
                var mentions = new StringBuilder("");
                foreach (var subscriber in modMailThread.Subscriber)
                {
                    var subscriberUser = guild.GetUser(subscriber.UserId);
                    if (subscriberUser != null)
                    {
                        mentions.Append(subscriberUser.Mention);
                    }
                }
                var msg = await guild.GetTextChannel(modMailThread.ChannelId).SendMessageAsync(mentions.ToString(), embed: ModMailEmbedHandler.GetReplyEmbed(message));

                AddModMailMessage(modMailThread.ChannelId, msg, null, message.Author.Id);
                var userMsg = await message.Channel.GetMessageAsync(message.Id);

                if (userMsg is RestUserMessage)
                {
                    var currentMessageInUserDmChannel = userMsg as RestUserMessage;
                    await currentMessageInUserDmChannel.AddReactionAsync(new Emoji("✅"));
                }
                else if (userMsg is SocketUserMessage)
                {
                    var currentMessageInUserDmChannel = userMsg as SocketUserMessage;
                    await currentMessageInUserDmChannel.AddReactionAsync(new Emoji("✅"));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task CreateModmailThread(SocketMessage message)
        {
            var userFromCache = Global.ModMailThreads.Where(th => th.UserId == message.Author.Id).FirstOrDefault();

            if (userFromCache != null && userFromCache.ThreadUser.ModMailMuted && userFromCache.ThreadUser.ModMailMutedUntil > DateTime.Now)
            {
                if (!userFromCache.ThreadUser.ModMailMutedReminded)
                {
                    await message.Channel.SendMessageAsync($"You are unable to contact modmail until {userFromCache.ThreadUser.ModMailMutedUntil:dd.MM.yyyy HH:mm} {TimeZoneInfo.Local}.");

                    using (var db = new Database())
                    {
                        db.Users.Where(us => us.UserId == message.Author.Id).First().ModMailMutedReminded = true;
                        db.SaveChanges();
                    }

                    Global.ReloadModmailThreads();
                }
                return;
            }

            using (var db = new Database())
            {
                var user = db.Users.Where(us => us.UserId == message.Author.Id).FirstOrDefault();
                if (user == null)
                {
                    var newUser = new User();
                    newUser.UserId       = message.Author.Id;
                    newUser.ModMailMuted = false;
                    db.Users.Add(newUser);
                    db.SaveChanges();
                }
            }
            int pastThreads = 0;

            using (var db = new Database())
            {
                pastThreads = db.ModMailThreads.Where(ch => ch.UserId == message.Author.Id).Count();
            }
            // when I tried to load the channel via getTextChannel, I got null in return, my only guess is that the channel
            // did not get peristent completely, so it did not find it
            // if we return the directly returned channel it worked
            var channel = await CreateModMailThread(message.Author);

            var guild = Global.Bot.GetGuild(Global.ServerID);
            await channel.SendMessageAsync(embed : ModMailEmbedHandler.GetUserInformation(pastThreads, message.Author));

            var channelMessage = await channel.SendMessageAsync(embed : ModMailEmbedHandler.GetReplyEmbed(message, "Initial message from user"));

            AddModMailMessage(channel.Id, channelMessage, null, message.Author.Id);
            await message.Author.SendMessageAsync(embed : ModMailEmbedHandler.GetInitialUserReply(message));

            ModMailThread modmailThread;

            using (var db = new Database())
            {
                modmailThread = db.ModMailThreads.Where(th => th.ChannelId == channel.Id).First();
            }

            var modQueue  = guild.GetTextChannel(Global.Channels["modqueue"]);
            var staffRole = guild.GetRole(Global.Roles["staff"]);
            await staffRole.ModifyAsync(x => x.Mentionable = true);

            try
            {
                await modQueue.SendMessageAsync(staffRole.Mention, embed : ModMailEmbedHandler.GetModqueueNotificationEmbed(message.Author, modmailThread));
            }
            finally
            {
                await staffRole.ModifyAsync(x => x.Mentionable = false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the user reply: updates the state in the db, posts the message to the modmail thread and mentions subscribers
        /// </summary>
        /// <param name="message">The <see chref="Discord.WebSocket.SocketMessage"> message object coming from the user</param>
        /// <returns></returns>
        public async Task HandleModMailUserReply(SocketMessage message)
        {
            var bot           = Global.Bot;
            var guild         = bot.GetGuild(Global.ServerID);
            var modMailThread = ModMailManager.GetOpenModmailForUser(message.Author);

            if (modMailThread != null)
            {
                UpdateModThreadUpdatedField(modMailThread.ChannelId, "USER_REPLIED");
                var mentions = new StringBuilder("");
                foreach (var subscriber in modMailThread.Subscriber)
                {
                    var subscriberUser = guild.GetUser(subscriber.UserId);
                    if (subscriberUser != null)
                    {
                        mentions.Append(subscriberUser.Mention);
                    }
                }
                var channel = guild.GetTextChannel(modMailThread.ChannelId);
                if (channel != null)
                {
                    var msg = await channel.SendMessageAsync(mentions.ToString(), embed : ModMailEmbedHandler.GetReplyEmbed(message));

                    AddModMailMessage(modMailThread.ChannelId, msg, null, message.Author.Id);
                }
                var userMsg = await message.Channel.GetMessageAsync(message.Id);

                if (userMsg is RestUserMessage)
                {
                    var currentMessageInUserDmChannel = userMsg as RestUserMessage;
                    await currentMessageInUserDmChannel.AddReactionAsync(new Emoji("✅"));
                }
                else if (userMsg is SocketUserMessage)
                {
                    var currentMessageInUserDmChannel = userMsg as SocketUserMessage;
                    await currentMessageInUserDmChannel.AddReactionAsync(new Emoji("✅"));
                }
            }
        }