Ejemplo n.º 1
0
        public async Task ShowMessages()
        {
            await Context.Channel.TriggerTypingAsync();

            _logger.LogInformation("{user}#{discriminator} invoked welcome show in {channel} on {server}",
                                   Context.User.Username, Context.User.Discriminator, Context.Channel.Name, Context.Guild.Name);

            var welcomeMessages = await _welcomeMessageRepository.GetWelcomeMessagesByServerId(Context.Guild.Id);

            var partMessages = await _partMessageRepository.GetPartMessagesByServerId(Context.Guild.Id);

            StringBuilder output = new StringBuilder();

            output.AppendLine("`Welcome messages:`");
            for (int i = 0; i < welcomeMessages.Count; i++)
            {
                output.AppendLine($"{i + 1}: {welcomeMessages[i].Message} (Id: {welcomeMessages[i].Id})");
            }

            if (welcomeMessages.Count > 0)
            {
                await ReplyAsync(output.ToString());
            }
            else
            {
                await ReplyAsync("No Custom Welcome messages have been set!");
            }

            output = new StringBuilder();
            output.AppendLine("`Part messages:`");
            for (int i = 0; i < partMessages.Count; i++)
            {
                output.AppendLine($"{i + 1}: {partMessages[i].Message} (Id: {partMessages[i].Id})");
            }

            if (partMessages.Count > 0)
            {
                await ReplyAsync(output.ToString());
            }
            else
            {
                await ReplyAsync("No Custom Part messages have been set!");
            }
        }
Ejemplo n.º 2
0
        private async Task ShowPartMessage(SocketGuildUser userParting)
        {
            var server = await _servers.GetServer(userParting.Guild);

            if (server.WelcomeUsers)
            {
                _logger.LogInformation("Showing parting message for {user} in {server}", userParting.Username, userParting.Guild.Name);

                var channelId = server.WelcomeChannel;
                if (channelId == 0)
                {
                    return;
                }

                ISocketMessageChannel channel = userParting.Guild.GetTextChannel(channelId);
                if (channel == null)
                {
                    await _servers.ClearWelcomeChannel(userParting.Guild.Id);

                    return;
                }

                var partMessages = await _partMessageRepository.GetPartMessagesByServerId(userParting.Guild.Id);

                if (partMessages.Count < 1)
                {
                    await channel.SendMessageAsync($"{userParting.Username} {_settings.PartingMessage}");
                }
                else
                {
                    var message = partMessages.RandomItem().Message;
                    message = message.Replace("{username}", userParting.Username);
                    message = message.Replace("{mention}", userParting.Username); //You can't mention a used that left!!

                    await channel.SendMessageAsync(message);
                }
            }
        }