Skip to content

Commit

Permalink
feat: add embed check to misskey
Browse files Browse the repository at this point in the history
similar to twitter, wait for a small period to check if an embed was made first
  • Loading branch information
Sn0wCrack committed Jan 10, 2025
1 parent 1c0ba02 commit afdad22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
23 changes: 21 additions & 2 deletions SaucyBot/Site/Misskey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ public sealed class Misskey : BaseSite
protected override Color Color => new(0x85B300);

private readonly ILogger<Misskey> _logger;
private readonly IConfiguration _configuration;
private readonly IMisskeyClient _client;

public Misskey(
ILogger<Misskey> logger,
IConfiguration configuration,
IMisskeyClient client
) {
_logger = logger;
_configuration = configuration;
_client = client;

var domains = new List<string> { "misskey.io", "misskey.design", "oekakiskey.com" }
Expand All @@ -38,12 +41,28 @@ IMisskeyClient client
var id = match.Groups["id"].Value;

var note = await _client.ShowNote(url, id);

if (note is null)
{
return null;
}

if (!ShouldEmbed(note))

var hasEmbed = false;

// If we have a message attached, we need to wait a bit for Discord to process the embed,
// we when need to refresh the message and see if an embed has been added in that time.
if (message is not null)
{
await Task.Delay(TimeSpan.FromSeconds(_configuration.GetSection("Sites:Misskey:Delay").Get<double>()));

// NOTE: Discord.NET works a little interestingly, basically when a message updates the Bot learns of this change
// and then proceeds to update its internal cache, so while we're waiting around it should update the message cache
// automatically, so there's no need to refresh the message object.

hasEmbed = message.Embeds.Count != 0;
}

if (hasEmbed && !ShouldEmbed(note))
{
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions SaucyBot/appsettings.Development.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"DeviantArt": {
"ClientId": 0,
"ClientSecret": ""
},
"Misskey": {
"Delay": "2.00"
}
}
}
3 changes: 3 additions & 0 deletions SaucyBot/appsettings.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
"DeviantArt": {
"ClientId": 0,
"ClientSecret": ""
},
"Misskey": {
"Delay": "2.00"
}
}
}

0 comments on commit afdad22

Please sign in to comment.