예제 #1
0
        public Task LogErrorMessage(Exception exception, ParsedCommand context)
        {
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            string message = $"[Error] {DateTime.UtcNow.ToString(@"yyyy-MM-dd_HH-mm")}: {exception}";

            Console.WriteLine(message);
            File.AppendAllText($"files/sessions/{SessionId.Substring(0, 8)}.log", message + "\n");

            if (!string.IsNullOrEmpty(Core.GlobalConfig.CriticalLoggingWebhookUrl))
            {
                var webhook = new Discord.Webhook.DiscordWebhookClient(Core.GlobalConfig.CriticalLoggingWebhookUrl);

                ExceptionReport report = Core.AddOrUpdateExceptionReport(new ExceptionReport(exception));

                var builder = new EmbedBuilder()
                              .WithColor(255, 0, 0)
                              .WithCurrentTimestamp()
                              .AddField(new EmbedFieldBuilder()
                                        .WithName("Error Message")
                                        .WithValue(exception.GetType() + ": " + exception.Message));
                if (!string.IsNullOrEmpty(exception.StackTrace))
                {
                    builder.AddField(new EmbedFieldBuilder()
                                     .WithName("Stack Trace")
                                     .WithValue(exception.StackTrace.Length > 1000 ? exception.StackTrace.Substring(exception.StackTrace.Length - 1000, 1000) : exception.StackTrace));
                }

                if (context != null)
                {
                    builder.AddField(new EmbedFieldBuilder()
                                     .WithName($"Location")
                                     .WithValue($"{context.Guild.Name} ({context.Guild.Id}) - #{context.Channel.Name} ({context.Channel.Id})"));
                    builder.AddField(new EmbedFieldBuilder()
                                     .WithName($"Author")
                                     .WithValue($"{context.Author.Username}#{context.Author.Discriminator} ({context.Author.Id})"));
                    builder.AddField(new EmbedFieldBuilder()
                                     .WithName($"Message")
                                     .WithValue(context.Message.Content));
                }

                builder.AddField(new EmbedFieldBuilder()
                                 .WithName("Count")
                                 .WithValue(report.Count).WithIsInline(true))
                .AddField(new EmbedFieldBuilder()
                          .WithName("Reported")
                          .WithValue(report.Reported)
                          .WithIsInline(true));

                webhook.SendMessageAsync("", embeds: new List <Embed> {
                    builder.Build()
                });
            }

            return(Task.FromResult(1));
        }
        public async Task SendWelcomeMessageAsync(SocketGuildUser User)
        {
            Task.Run(() => {
                if (IsWebhook)
                {
                    if (Client == null)
                    {
                        Client = new Discord.Webhook.DiscordWebhookClient(WebhookId, WebhookToken);
                    }

                    Client.SendMessageAsync(Notification.Replace("{User.Mention}", User.Mention).Replace("{User.Username}", User.Username), username: Name, avatarUrl: AvatarUrl ?? Program.Client.CurrentUser.GetAvatarUrl());
                }

                else
                {
                    ((ITextChannel)Program.Client.GetChannel(ChannelId)).SendMessageAsync(Notification.Replace("{User.Mention}", User.Mention).Replace("{User.Username}", User.Username));
                }
            });
        }
예제 #3
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!_filter(_categoryName, logLevel))
            {
                return;
            }

            var webhookClient = new Discord.Webhook.DiscordWebhookClient(_id, _token);

            var message = new EmbedBuilder()
                          .WithAuthor("DiscordLogger")
                          .WithTitle(_categoryName)
                          .WithTimestamp(DateTimeOffset.UtcNow)
                          .WithColor(Color.Red)
                          .AddField(new EmbedFieldBuilder()
                                    .WithIsInline(false)
                                    .WithName($"LogLevel: {logLevel}")
                                    .WithValue(Format.Code($"{formatter(state, exception)}\n{exception?.ToString()}".TruncateTo(1010))));

            webhookClient.SendMessageAsync(string.Empty, embeds: new[] { message.Build() }, username: "******");
        }
예제 #4
0
        private void SendAnnouncement()
        {
            if (string.IsNullOrWhiteSpace(ClusterFolder) || string.IsNullOrWhiteSpace(SaveFilePath))
            {
                MessageBox.Show("You must select both a cluster folder and a save file path.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrWhiteSpace(txtWebhookID.Text) || string.IsNullOrWhiteSpace(txtWebhookToken.Text) || !IsInt(txtWebhookID.Text))
            {
                MessageBox.Show("Invalid Webhook data. ID must be an integer and both fields must have an entry.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            client = new Discord.Webhook.DiscordWebhookClient(Convert.ToUInt64(txtWebhookID.Text), txtWebhookToken.Text);

            var cd = new ArkClusterData(ClusterFolder, loadOnlyPropertiesInDomain: true);
            var gd = new ArkGameData(SaveFilePath, cd, loadOnlyPropertiesInDomain: true);

            //extract savegame
            var upd = gd.Update(CancellationToken.None, deferApplyNewData: true);

            if (upd == null)
            {
                return;
            }
            if (upd.Success == true)
            {
                //extract cluster data
                var cr = cd.Update(CancellationToken.None);

                //assign the new data to the domain model
                gd.ApplyPreviousUpdate();

                // Populate Wild dinos
                var wildDinos = gd.WildCreatures;

                // init message
                var message = @"```autohotkey" + Environment.NewLine;

                // Go through entries
                foreach (DataGridViewRow row in dgvTrackList.Rows)
                {
                    if (string.IsNullOrWhiteSpace(row.Cells[0].Value.ToString()) || string.IsNullOrWhiteSpace(row.Cells[1].Value.ToString()))
                    {
                        MessageBox.Show("Incomplete Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var dType        = row.Cells[0].Value.ToString();
                    var searchString = row.Cells[1].Value.ToString();

                    //init controllers
                    var foundDinos = false;

                    // Get desired Dinos
                    var queriedDinos = new List <ArkWildCreature>();
                    queriedDinos = wildDinos.Where(q => q.ClassName.Contains(searchString)).ToList();

                    // Discord
                    if (queriedDinos.Count > 0)
                    {
                        foundDinos = true;
                        message   += $"{dType} sightings on " + queriedDinos.First().Location.MapName + ":" + Environment.NewLine;

                        message += $"_{"_______",-7}_{"________________",-16}_{"_______",-7}_{"_________",-9}_" + Environment.NewLine;
                        message += $"|{"Gender",-7}|{"Type",-16}|{"Level",-7}|{"Location",-9}|" + Environment.NewLine;
                        message += $"|{"_______",-7}|{"________________",-16}|{"_______",-7}|{"_________",-9}|" + Environment.NewLine;
                        foreach (var dino in queriedDinos)
                        {
                            var gender = $" {dino.Gender.ToString()}";
                            var name   = $" {dino.ClassName.Split('_').First()}";
                            var level  = $" {dino.BaseLevel.ToString()}";
                            var loc    = $" {dino.Location.Latitude.Value.ToString("N0", CultureInfo.InvariantCulture)}, { dino.Location.Latitude.Value.ToString("N0", CultureInfo.InvariantCulture)}";
                            message += $"|{gender,-7}|{name,-16}|{level,-7}|{loc,-9}|" + Environment.NewLine;
                        }
                        message += $"|{"_______",-7}|{"________________",-16}|{"_______",-7}|{"_________",-9}|" + Environment.NewLine;
                    }

                    if (MessageTooLong)
                    {
                        message += Environment.NewLine + "```";
                        client.SendMessageAsync(message).Wait();
                        MessageFragsSent = true;
                        message          = @"```autohotkey" + Environment.NewLine;
                    }

                    if (!MessageTooLong && foundDinos && row.Index < dgvTrackList.RowCount)
                    {
                        message += Environment.NewLine + Environment.NewLine + Environment.NewLine;
                    }
                }

                MessageTooLong = message.Length >= 2000 && !MessageFragsSent;

                if (MessageTooLong)
                {
                    SendAnnouncement();
                    MessageTooLong = false;
                }
                else if (!MessageTooLong && !MessageFragsSent)
                {
                    message += Environment.NewLine + "```";
                    client.SendMessageAsync(message).Wait();
                }

                MessageTooLong   = false;
                MessageFragsSent = false;
            }
        }