Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new discord bot #45

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9e3a72d
new discord bot
TheUbMunster Dec 22, 2022
bb02fa6
only print logged commands if it was a valid command
TheUbMunster Dec 24, 2022
3a34ec2
Made the logging colors smarter.
TheUbMunster Dec 24, 2022
fb26986
refactoring of command parsing in discord bot
TheUbMunster Dec 24, 2022
317a495
Fix deadlock from Stop/HandleCommandAsync
TheUbMunster Dec 24, 2022
28c4cfa
alias logchannel as adminchannel (code only)
TheUbMunster Dec 24, 2022
3f6d581
Filter out a non-issue warning.
TheUbMunster Dec 25, 2022
0b5d0b7
enable/disable the filtering of non-warning log messages
TheUbMunster Dec 25, 2022
c3e664d
Update to sanae
TheUbMunster Jun 27, 2023
fc70cb9
Updated readme with the new settings, added another exception filter …
TheUbMunster Jun 28, 2023
67a0071
Added garbage to attempt to update json field name.
TheUbMunster Jun 28, 2023
5b4de5f
Removed the aforementioned garbage
TheUbMunster Jun 28, 2023
e549723
Removed bad using
TheUbMunster Jun 28, 2023
3b935d1
Property migration of LogChannel->AdminChannel in discord settings, g…
TheUbMunster Jul 3, 2023
f15ded0
lgtm?
TheUbMunster Jul 11, 2023
cfe6c3e
but actually now
TheUbMunster Jul 11, 2023
a5b8348
reordered Init to make startup more clear.
TheUbMunster Jul 11, 2023
ba1a283
Added the ability to enable/disable the discord bot via settings.json
TheUbMunster Jul 13, 2023
e198e4a
Merge branch 'master' into new-discord-bot
Sanae6 Sep 5, 2023
beb199e
Update Server/Settings.cs
TheUbMunster Oct 14, 2024
35e521b
Update Server/DiscordBot.cs
TheUbMunster Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ Banlist: banned people are unable to join the server, default: false
PersistShines/Moons: Allows the server to remember moon progress across crashes/restarts

### Discord
Note: Token and LogChannel needs to a string puts "" around it
Note: Token, AdminChannel (formerly known as "LogChannel") and CommandChannel need to have quotes "" around it
Token: the token of the bot you want to load into, default: null
Prefix: the bot prefix to be used, default: $
LogChannel: logs the server console to that channel, default: null
CommandChannel: allows discord commands, default: null
LogChannel/(AdminChannel): allows discord commands & logs the server console to that channel, default: null
LogCommands: log all executed commands to log handlers (discord, console), default: false
FilterOutNonIssueWarnings: filter out the nonsense warnings/errors? default: true
359 changes: 234 additions & 125 deletions Server/DiscordBot.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
bool restartRequested = false;
Logger consoleLogger = new Logger("Console");
DiscordBot bot = new DiscordBot();
await bot.Run();
await bot.FirstInit();

async Task PersistShines()
{
Expand Down
2 changes: 1 addition & 1 deletion Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task Listen(CancellationToken? token = null) {
continue;
}

Logger.Warn($"Accepted connection for client {socket.RemoteEndPoint}");
Logger.Notify($"Accepted connection for client {socket.RemoteEndPoint}");

try {
#pragma warning disable CS4014
Expand Down
2 changes: 1 addition & 1 deletion Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DSharpPlus" Version="4.3.0-nightly-01142" />
<PackageReference Include="Discord.Net" Version="3.8.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

Expand Down
11 changes: 10 additions & 1 deletion Server/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,19 @@ public class FlipTable {
}

public class DiscordTable {
public bool Enabled { get; set; } = false;
public string? Token { get; set; }
public string Prefix { get; set; } = "$";
public string? CommandChannel { get; set; }
public string? LogChannel { get; set; }
//This funkyness is to migrate the JSON "LogChannel" to "AdminChannel"
public string? AdminChannel { get; set; }
[JsonProperty(PropertyName = "LogChannel")]
public string? LogChannel
{
set => AdminChannel = value;
}
public bool LogCommands { get; set; } = false;
public bool FilterOutNonIssueWarnings { get; set; } = true;
}

public class ShineTable {
Expand Down
2 changes: 2 additions & 0 deletions Shared/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public Logger(string name) {

public string Name { get; set; }

public void Notify(string text) => Handler?.Invoke(Name, "Info", text, ConsoleColor.Green);

public void Info(string text) => Handler?.Invoke(Name, "Info", text, ConsoleColor.White);

public void Warn(string text) => Handler?.Invoke(Name, "Warn", text, ConsoleColor.Yellow);
Expand Down