Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
109 lines (98 loc) · 4.33 KB
/
Copy pathProgram.cs
File metadata and controls
109 lines (98 loc) · 4.33 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
99
100
101
102
103
104
105
106
107
108
109
usingDSharpPlus;
usingDSharpPlus.Entities;
usingDSharpPlus.EventArgs;
usingDSharpPlus.SlashCommands;
usingNewtonsoft.Json;
usingMicrosoft.Extensions.Logging;
usingSystem;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.IO;
usingSystem.Reflection;
usingSystem.Runtime.CompilerServices;
usingSystem.Threading.Tasks;
namespaceStoreBot
{
publicclassProgram
{
publicstaticDictionary<ulong,string>TokenDictionary=newDictionary<ulong,string>();
publicstructConfigJson
{
[JsonProperty("discordtoken")]
publicstringToken{get;privateset;}
}
publicstaticTaskClient_Ready(DiscordClient_,ReadyEventArgse)
{
_.Logger.LogInformation(newEventId(1337,"StoreBot"),"Client is ready to process events.");
returnTask.CompletedTask;
}
privatestaticTaskClient_GuildAvailable(DiscordClient_,GuildCreateEventArgse)
{
_.Logger.LogInformation(newEventId(1337,"StoreBot"),$"Server available: {e.Guild.Name}");
returnTask.CompletedTask;
}
privatestaticTaskClient_ClientError(DiscordClient_,ClientErrorEventArgse)
{
_.Logger.LogInformation(newEventId(1337,"StoreBot"),$"Exception occured: {e.Exception.GetType()}: {e.Exception.Message}");
returnTask.CompletedTask;
}
privatestaticTaskSlash_SlashCommandErrored(SlashCommandsExtensionsender,DSharpPlus.SlashCommands.EventArgs.SlashCommandErrorEventArgse)
{
sender.Client.Logger.LogInformation(newEventId(1337,"StoreBot"),$"{e.Context.User.Username} tried executing '{e.Context?.CommandName??"<unknown command>"}' but it errored: {e.Exception.GetType()}: {e.Exception.Message??"<no message>"}");
thrownewNotImplementedException();
}
privatestaticTaskSlash_SlashCommandExecuted(SlashCommandsExtensionsender,DSharpPlus.SlashCommands.EventArgs.SlashCommandExecutedEventArgse)
{
sender.Client.Logger.LogInformation(newEventId(1337,"StoreBot"),$"{e.Context.User.Username}:{e.Context.User.Id.ToString()} ran command '{e.Context.CommandName}'");
returnTask.CompletedTask;
}
publicstaticasyncTask<DiscordConfiguration>LoadConfig()
{
stringtoken=Environment.GetEnvironmentVariable("STOREBOTTOKEN");
if(!String.IsNullOrEmpty(token))
{
DiscordConfigurationconfigenv=newDiscordConfiguration()
{
Token=token,
TokenType=TokenType.Bot,
AutoReconnect=true,
MinimumLogLevel=LogLevel.Information
};
returnconfigenv;
}
stringjson="";
using(FileStreamfs=File.Open("config.json",FileMode.Open))
{
using(StreamReadersr=newStreamReader(fs))
{
json=awaitsr.ReadToEndAsync();
}
}
varcfgjson=JsonConvert.DeserializeObject<ConfigJson>(json);
DiscordConfigurationconfig=newDiscordConfiguration()
{
Token=cfgjson.Token,
TokenType=TokenType.Bot,
AutoReconnect=true,
MinimumLogLevel=LogLevel.Information
};
returnconfig;
}
publicstaticasyncTaskMain(string[]args)
{
Console.WriteLine($"StoreBot - {Assembly.GetExecutingAssembly().GetName().Version.ToString()}");
DiscordClientclient=newDiscordClient(awaitLoadConfig());
client.Ready+=Client_Ready;
client.GuildAvailable+=Client_GuildAvailable;
client.ClientErrored+=Client_ClientError;
varslash=client.UseSlashCommands();
slash.RegisterCommands<StoreCommands>();
slash.RegisterCommands<AuthCommands>();
slash.SlashCommandErrored+=Slash_SlashCommandErrored;
slash.SlashCommandExecuted+=Slash_SlashCommandExecuted;
awaitclient.ConnectAsync(newDiscordActivity
("DisplayCatalog",ActivityType.Watching),UserStatus.Online);
awaitTask.Delay(-1);
}
}
}