예제 #1
0
        public async Task LogMessage(string msg, bool channel = true, bool console = true, bool alert = false,
                                     ConsoleColor color       = ConsoleColor.White)
        {
            string alertUser = null;
            var    date      = DateTime.Now.ToString("HH:mm:ss.fff - dddd, MMMM dd yyyy");

            if (alert)
            {
                alertUser = _dataService.AlertUser.Mention;
            }

            if (msg.Length > 1950)
            {
                msg = msg.Substring(0, 1950);
            }

            if (console)
            {
                Console.ForegroundColor = color;
                Console.WriteLine(date + "\n" + msg.Replace("```", "") + "\n");
                Console.ResetColor();
            }

            if (channel && _dataService.LogChannel == null)
            {
                Console.WriteLine($"Attempted to log:\n[{msg}]\nto the log channel, but log channel is not yet set.");
                return;
            }

            if (channel)
            {
                await _dataService.LogChannel.SendMessageAsync(alertUser, embed : new EmbedBuilder()
                                                               .WithDescription(msg)
                                                               .WithColor(GeneralUtil.ColorFromConsoleColor(color))
                                                               .WithFooter(date)
                                                               .Build());
            }
        }