Skip to content

Commit

Permalink
Update Octokit. Better error handling for ClientReady(). Fix filename…
Browse files Browse the repository at this point in the history
… string issue for Linux/Mac.
  • Loading branch information
thomasloupe committed Dec 22, 2022
1 parent db73d4d commit 0f685d8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
Binary file modified Slackord_Mac_Linux/.vs/Slackord/v17/.suo
Binary file not shown.
35 changes: 25 additions & 10 deletions Slackord_Mac_Linux/Slackord/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Slackord
{
internal partial class Slackord : InteractionModuleBase<SocketInteractionContext>
{
private const string CurrentVersion = "v2.4.3.1";
private const string CurrentVersion = "v2.4.3.2";
private DiscordSocketClient _discordClient;
private string _discordToken;
private bool _isFileParsed;
Expand Down Expand Up @@ -370,7 +370,7 @@ The following parse is over 2000 characters. Discord does not allow messages ove
Console.WriteLine(debugResponse + "\n");
}
}
Console.WriteLine("""
Console.WriteLine($$"""
-----------------------------------------
Parsing of {{file}} completed successfully!
-----------------------------------------
Expand Down Expand Up @@ -560,6 +560,7 @@ public async Task MainAsync()
catch (Exception ex)
{
Console.WriteLine("Discord bot task failed with: " + ex.Message);
await _discordClient.StopAsync();
}
}

Expand All @@ -575,18 +576,32 @@ private async Task SlashCommandHandler(SocketSlashCommand command)

private async Task ClientReady()
{
var guildID = _discordClient.Guilds.FirstOrDefault().Id;
var guild = _discordClient.GetGuild(guildID);
var guildCommand = new SlashCommandBuilder();
guildCommand.WithName("slackord");
guildCommand.WithDescription("Posts all parsed Slack JSON messages to the text channel the command came from.");
try
{
await guild.CreateApplicationCommandAsync(guildCommand.Build());
if (_discordClient.Guilds.Count > 0)
{
var guildID = _discordClient.Guilds.FirstOrDefault().Id;
var guild = _discordClient.GetGuild(guildID);
var guildCommand = new SlashCommandBuilder();
guildCommand.WithName("slackord");
guildCommand.WithDescription("Posts all parsed Slack JSON messages to the text channel the command came from.");
try
{
await guild.CreateApplicationCommandAsync(guildCommand.Build());
}
catch (HttpException Ex)
{
Console.WriteLine("Error creating slash command: " + Ex.Message);
}
}
else
{
Console.WriteLine("Slackord was unable to find any guilds to create a slash command in.");
}
}
catch (HttpException Ex)
catch (Exception ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine("Error encountered while creating slash command: " + ex.Message);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Slackord_Mac_Linux/Slackord/Slackord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Discord.Net.Interactions" Version="3.8.1" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.8.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Octokit" Version="4.0.1" />
<PackageReference Include="Octokit" Version="4.0.3" />
</ItemGroup>

</Project>
33 changes: 23 additions & 10 deletions Slackord_Win/Slackord/Slackord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Slackord
{
public partial class Slackord : MaterialForm
{
private const string CurrentVersion = "v2.4.3.1";
private const string CurrentVersion = "v2.4.3.2";
public DiscordSocketClient _discordClient;
private OpenFileDialog _ofd;
private string _discordToken;
Expand Down Expand Up @@ -505,19 +505,32 @@ private async Task SlashCommandHandler(SocketSlashCommand command)

private async Task ClientReady()
{
var guildID = _discordClient.Guilds.FirstOrDefault().Id;
var guild = _discordClient.GetGuild(guildID);
var guildCommand = new SlashCommandBuilder();
guildCommand.WithName("slackord");
guildCommand.WithDescription("Posts all parsed Slack JSON messages to the text channel the command came from.");

try
{
await guild.CreateApplicationCommandAsync(guildCommand.Build());
if (_discordClient.Guilds.Count > 0)
{
var guildID = _discordClient.Guilds.FirstOrDefault().Id;
var guild = _discordClient.GetGuild(guildID);
var guildCommand = new SlashCommandBuilder();
guildCommand.WithName("slackord");
guildCommand.WithDescription("Posts all parsed Slack JSON messages to the text channel the command came from.");
try
{
await guild.CreateApplicationCommandAsync(guildCommand.Build());
}
catch (HttpException Ex)
{
Console.WriteLine("Error creating slash command: " + Ex.Message);
}
}
else
{
Console.WriteLine("Slackord was unable to find any guilds to create a slash command in.");
}
}
catch (HttpException Ex)
catch (Exception ex)
{
Console.WriteLine(Ex.Message);
Console.WriteLine("Error encountered while creating slash command: " + ex.Message);
}
}

Expand Down

0 comments on commit 0f685d8

Please sign in to comment.