Пример #1
0
        public async Task ContactUser(IGuildUser user, ISocketMessageChannel channel)
        {
            using (var db = new Database()){
                var exists = db.ModMailThreads.Where(th => th.UserId == user.Id && th.State != "CLOSED");
                if (exists.Count() > 0)
                {
                    await channel.SendMessageAsync(embed : ModMailEmbedHandler.GetThreadAlreadyExistsEmbed(exists.First()));

                    return;
                }

                var existingUser = db.Users.Where(us => us.UserId == user.Id).FirstOrDefault();
                if (existingUser == null)
                {
                    var newUser = new User();
                    newUser.UserId       = user.Id;
                    newUser.ModMailMuted = false;
                    db.Users.Add(newUser);
                }
                else
                {
                    existingUser.ModMailMuted = false;
                }


                db.SaveChanges();
            }
            var createdChannel = await CreateModMailThread(user);

            ModMailThread createdModMailThread;

            using (var db = new Database()){
                createdModMailThread = db.ModMailThreads.Where(th => th.ChannelId == createdChannel.Id).First();
            }
            var embedContainingLink = ModMailEmbedHandler.GetThreadHasBeendCreatedEmbed(createdModMailThread);
            await channel.SendMessageAsync(embed : embedContainingLink);
        }
Пример #2
0
        /// <summary>
        /// Creates a modmail thread with the given user and responds in the given thread with a link to the newly created channel.
        /// </summary>
        /// <param name="user">The <see cref="Discord.IUser"> to create the channel for</param>
        /// <param name="channel">The <see cref="Discord.ISocketMessageChannel"> in which the response should be posted to</param>
        /// <returns>The <see cref="Discord.Rest.RestChannel"> newly created channel</returns>
        public static async Task <RestTextChannel> ContactUser(IUser user, ISocketMessageChannel channel, bool createNote)
        {
            using (var db = new Database())
            {
                var existingUser = db.Users.AsQueryable().Where(us => us.Id == user.Id).FirstOrDefault();
                if (existingUser == null)
                {
                    var newUser = new UserBuilder(user.Id).Build();
                    db.Users.Add(newUser);
                }
                else
                {
                    existingUser.ModMailMuted = false;
                }
                db.SaveChanges();
            }
            var createdChannel = await CreateModMailThread(user);

            ModMailThread createdModMailThread;

            using (var db = new Database())
            {
                createdModMailThread = db.ModMailThreads.AsQueryable().Where(th => th.ChannelId == createdChannel.Id).First();
            }

            await createdChannel.SendMessageAsync(embed : ModMailEmbedHandler.GetUserInfoHeader(createdModMailThread));

            if (createNote)
            {
                var embedContainingLink = ModMailEmbedHandler.GetThreadHasBeendCreatedEmbed(createdModMailThread);
                await channel.SendMessageAsync(embed : embedContainingLink);
            }
            // we need to return the channel, because we *directly* need the channel after wards, and loading the channel by id again
            // resulted in null
            return(createdChannel);
        }