-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.cs
More file actions
98 lines (88 loc) · 2.88 KB
/
Global.cs
File metadata and controls
98 lines (88 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Discord;
using Discord.Commands;
namespace DabSquadBot
{
public class Global
{
static string errorLogFilePath = @"..\Data\ErrorLog.txt";
public static string filePath = @"..\Data\";
public static JSONHelper JSONHelper = new JSONHelper();
public static Data Data;
public static List<Color> Colors = new List<Color>
{
Color.Blue,
Color.DarkBlue,
Color.DarkerGrey,
Color.DarkGreen,
Color.DarkGrey,
Color.DarkMagenta,
Color.DarkOrange,
Color.DarkPurple,
Color.DarkRed,
Color.DarkTeal,
Color.Gold,
Color.Green,
Color.LighterGrey,
Color.LightGrey,
Color.LightOrange,
Color.Magenta,
Color.Orange,
Color.Purple,
Color.Red,
Color.Teal
};
public static Task InitGlobalVars()
{
try
{
if (!File.Exists(errorLogFilePath))
{
Directory.CreateDirectory(@"..\Data\");
File.CreateText(errorLogFilePath);
}
if (!File.Exists(filePath + "Data.json"))
{
JSONHelper.JsonSerialize(new Data());
}
Data = JSONHelper.JsonDeserialize();
return Task.CompletedTask;
}
catch (Exception ex)
{
LogError(ex);
return null;
}
}
public static Embed LogError(Exception ex, SocketCommandContext context = null)
{
Console.WriteLine(ex.Message);
string User = null;
string UserMessage = null;
if (context != null)
{
User = context.User.Username;
UserMessage = context.Message.Content;
}
string Message = ex.Message;
string StackTrace = ex.StackTrace;
EmbedBuilder embedBuilder = new EmbedBuilder
{
Color = Color.Red,
Title = Message,
Footer = new EmbedFooterBuilder
{
Text = DateTime.UtcNow.ToString() + " UTC"
},
};
File.AppendAllLines(errorLogFilePath, new string[] { $"({User}) {{{UserMessage}}}", $"{DateTime.Now.ToString()}: {ex.Message}", ex.StackTrace });
Embed embed = embedBuilder.Build();
return embed;
}
}
}