Skip to content

Commit

Permalink
GRIDBOT-25: Deployment and log file commands (#39)
Browse files Browse the repository at this point in the history
* GRIDBOT-25 (Deployment and log file commands): Make FileName public

* GRIDBOT-25 (Deployment and log file commands): Add Commands and Slash Commands
  • Loading branch information
nikita-petko authored Mar 12, 2022
1 parent 1742e3d commit 85f2a68
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed class EventLogConsoleSystemLogger : ILogger
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MFDLABS", "Logs");

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly string FileName =
public static readonly string FileName =
#if DEBUG
"dev_" +
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public sealed class EventLogSystemLogger : ILogger
private static readonly string FileBasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MFDLABS", "Logs");

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly string FileName =
public static readonly string FileName =
#if DEBUG
"dev_" +
#endif
Expand Down
2 changes: 1 addition & 1 deletion Assemblies/MFDLabs.Logging/Implementation/SystemLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class SystemLogger : ILogger
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MFDLABS", "Logs");

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static readonly string FileName =
public static readonly string FileName =
#if DEBUG
"dev_" +
#endif
Expand Down
31 changes: 31 additions & 0 deletions Shared/MFDLabs.GridCommands/Commands/DeploymentId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.IO;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using MFDLabs.Grid.Bot.Extensions;
using MFDLabs.Grid.Bot.Interfaces;

namespace MFDLabs.Grid.Bot.Commands
{
internal sealed class DeploymentId : IStateSpecificCommandHandler
{
public string CommandName => "Get Deployment ID";
public string CommandDescription => "Fetches the deployment ID for the current instance.";
public string[] CommandAliases => new[] { "dep", "dply", "deploy", "depid", "deployment", "deploymentid" };
public bool Internal => false;
public bool IsEnabled { get; set; } = true;

public async Task Invoke(string[] messageContentArray, SocketMessage message, string originalCommand)
{
// The deployment ID is literally just the name of the current directory that the executable is in.
// This is not a great way to do this, but it's the best I can think of for now.

// Fetch current directory name.
var currentDirectory = Directory.GetCurrentDirectory();
var currentDirectoryName = Path.GetFileName(currentDirectory);

// Reply with the deployment ID.
await message.ReplyAsync($"The deployment ID for this instance is: `{currentDirectoryName}`\nPlease paste this into the `Deployment ID` field in grid-bot-support templates to that the internal team can easily identify this instance.");
}
}
}
23 changes: 23 additions & 0 deletions Shared/MFDLabs.GridCommands/Commands/LogFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using MFDLabs.Logging;
using MFDLabs.Grid.Bot.Extensions;
using MFDLabs.Grid.Bot.Interfaces;

namespace MFDLabs.Grid.Bot.Commands
{
internal sealed class LogFile : IStateSpecificCommandHandler
{
public string CommandName => "Get Log File Name";
public string CommandDescription => "Fetches the log file name for the current instance.";
public string[] CommandAliases => new[] { "log", "lfile", "logfile", "log-file-name", "log-file", "log-name" };
public bool Internal => false;
public bool IsEnabled { get; set; } = true;

public async Task Invoke(string[] messageContentArray, SocketMessage message, string originalCommand)
{
await message.ReplyAsync($"The log file name for this instance is: `{SystemLogger.FileName}`\nPlease paste this into the `Log File Name` field in grid-bot-support templates to that the internal team can easily identify this instance's log files.");
}
}
}
40 changes: 40 additions & 0 deletions Shared/MFDLabs.GridCommands/SlashCommands/DeploymentId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#if WE_LOVE_EM_SLASH_COMMANDS

using System.IO;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using MFDLabs.Grid.Bot.Extensions;
using MFDLabs.Grid.Bot.Interfaces;
using MFDLabs.Grid.Bot.Utility;

namespace MFDLabs.Grid.Bot.SlashCommands
{
internal sealed class DeploymentId : IStateSpecificSlashCommandHandler
{
public string CommandDescription => "Get Deployment ID";
public string CommandAlias => "deployment";
public bool Internal => false;
public bool IsEnabled { get; set; } = true;
public ulong? GuildId => null;
public SlashCommandOptionBuilder[] Options => null;

public async Task Invoke(SocketSlashCommand command)
{
using (await command.DeferEphemeralAsync())
{
// The deployment ID is literally just the name of the current directory that the executable is in.
// This is not a great way to do this, but it's the best I can think of for now.

// Fetch current directory name.
var currentDirectory = Directory.GetCurrentDirectory();
var currentDirectoryName = Path.GetFileName(currentDirectory);

// Reply with the deployment ID.
await command.RespondEphemeralAsync($"The deployment ID for this instance is: `{currentDirectoryName}`\nPlease paste this into the `Deployment ID` field in grid-bot-support templates to that the internal team can easily identify this instance.");
}
}
}
}

#endif
32 changes: 32 additions & 0 deletions Shared/MFDLabs.GridCommands/SlashCommands/LogFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#if WE_LOVE_EM_SLASH_COMMANDS

using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using MFDLabs.Logging;
using MFDLabs.Grid.Bot.Extensions;
using MFDLabs.Grid.Bot.Interfaces;
using MFDLabs.Grid.Bot.Utility;

namespace MFDLabs.Grid.Bot.SlashCommands
{
internal sealed class LogFile : IStateSpecificSlashCommandHandler
{
public string CommandDescription => "Get Log File Name";
public string CommandAlias => "log-file-name";
public bool Internal => false;
public bool IsEnabled { get; set; } = true;
public ulong? GuildId => null;
public SlashCommandOptionBuilder[] Options => null;

public async Task Invoke(SocketSlashCommand command)
{
using (await command.DeferEphemeralAsync())
{
await command.RespondEphemeralAsync($"The log file name for this instance is: `{SystemLogger.FileName}`\nPlease paste this into the `Log File Name` field in grid-bot-support templates to that the internal team can easily identify this instance's log files.");
}
}
}
}

#endif

0 comments on commit 85f2a68

Please sign in to comment.