-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add weekly swap overview consumers
- Loading branch information
Showing
12 changed files
with
481 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
chainflip-insights/Consumers/Discord/Discord-WeeklySwapOverview.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace ChainflipInsights.Consumers.Discord | ||
{ | ||
using System; | ||
using System.Text; | ||
using ChainflipInsights.Feeders.WeeklySwapOverview; | ||
using global::Discord; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public partial class DiscordConsumer | ||
{ | ||
private void ProcessWeeklySwapOverviewInfo(WeeklySwapOverviewInfo weeklySwapOverviewInfo) | ||
{ | ||
if (!_configuration.DiscordWeeklySwapOverviewEnabled.Value) | ||
{ | ||
_logger.LogInformation( | ||
"Weekly Swap Overview disabled for Discord. {StartDate} -> {EndDate}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
return; | ||
} | ||
|
||
if (_discordClient.ConnectionState != ConnectionState.Connected) | ||
return; | ||
|
||
try | ||
{ | ||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview for {StartDate} -> {EndDate} on Discord.", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
var text = new StringBuilder(); | ||
text.AppendLine($"💵 Weekly Top Swaps for **{weeklySwapOverviewInfo.StartDate:yyyy-MM-dd}** -> **{weeklySwapOverviewInfo.EndDate:yyyy-MM-dd}** are in!"); | ||
|
||
var emojis = new[] | ||
{ | ||
"🥇", | ||
"🥈", | ||
"🥉", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅" | ||
}; | ||
|
||
for (var i = 0; i < weeklySwapOverviewInfo.Swaps.Count; i++) | ||
{ | ||
var swap = weeklySwapOverviewInfo.Swaps[i].Swap; | ||
var brokerExists = _brokers.TryGetValue(swap.Broker ?? string.Empty, out var broker); | ||
|
||
text.AppendLine( | ||
$"{emojis[i]} " + | ||
$"**{swap.DepositAmountFormatted} {swap.SourceAsset}** (*${swap.DepositValueUsdFormatted}*) → " + | ||
$"**{swap.EgressAmountFormatted} {swap.DestinationAsset}** (*${swap.EgressValueUsdFormatted}*) " + | ||
$"{(brokerExists ? $"@ **{broker}** " : string.Empty)}" + | ||
$"// **[#{swap.Id}]({_configuration.ExplorerSwapsUrl}{swap.Id})**"); | ||
} | ||
|
||
var infoChannel = (ITextChannel)_discordClient | ||
.GetChannel(_configuration.DiscordSwapInfoChannelId.Value); | ||
|
||
var message = infoChannel | ||
.SendMessageAsync( | ||
text.ToString(), | ||
flags: MessageFlags.SuppressEmbeds) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview {StartDate} -> {EndDate} on Discord as Message {MessageId}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd"), | ||
message.Id); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Discord meh."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
chainflip-insights/Consumers/FullTelegram/Telegram-WeeklySwapOverview.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
namespace ChainflipInsights.Consumers.FullTelegram | ||
{ | ||
using System; | ||
using System.Text; | ||
using System.Threading; | ||
using ChainflipInsights.Feeders.WeeklySwapOverview; | ||
using global::Telegram.Bot; | ||
using global::Telegram.Bot.Requests; | ||
using global::Telegram.Bot.Types; | ||
using global::Telegram.Bot.Types.Enums; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public partial class FullTelegramConsumer | ||
{ | ||
private void ProcessWeeklySwapOverviewInfo( | ||
WeeklySwapOverviewInfo weeklySwapOverviewInfo, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (!_configuration.DiscordWeeklySwapOverviewEnabled.Value) | ||
{ | ||
_logger.LogInformation( | ||
"Weekly Swap Overview disabled for Full Telegram. {StartDate} -> {EndDate}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
return; | ||
} | ||
|
||
try | ||
{ | ||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview for {StartDate} -> {EndDate} on Full Telegram.", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
var text = new StringBuilder(); | ||
text.AppendLine($"💵 Weekly Top Swaps for **{weeklySwapOverviewInfo.StartDate:yyyy-MM-dd}** -> **{weeklySwapOverviewInfo.EndDate:yyyy-MM-dd}** are in!"); | ||
|
||
var emojis = new[] | ||
{ | ||
"🥇", | ||
"🥈", | ||
"🥉", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅" | ||
}; | ||
|
||
for (var i = 0; i < weeklySwapOverviewInfo.Swaps.Count; i++) | ||
{ | ||
var swap = weeklySwapOverviewInfo.Swaps[i].Swap; | ||
|
||
text.AppendLine( | ||
$"{emojis[i]} " + | ||
$"**{swap.DepositAmountFormatted} {swap.SourceAsset}** → " + | ||
$"**{swap.EgressAmountFormatted} {swap.DestinationAsset}** " + | ||
$"// **[#{swap.Id}]({_configuration.ExplorerSwapsUrl}{swap.Id})**"); | ||
} | ||
|
||
var message = _telegramClient | ||
.SendMessageAsync( | ||
new SendMessageRequest | ||
{ | ||
ChatId = new ChatId(_configuration.TelegramInfoChannelId.Value), | ||
Text = text.ToString(), | ||
ParseMode = ParseMode.Markdown, | ||
DisableNotification = true, | ||
LinkPreviewOptions = new LinkPreviewOptions | ||
{ | ||
IsDisabled = true | ||
}, | ||
ReplyParameters = new ReplyParameters | ||
{ | ||
AllowSendingWithoutReply = true, | ||
} | ||
}, | ||
cancellationToken) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview {StartDate} -> {EndDate} on Full Telegram as Message {MessageId}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd"), | ||
message.MessageId); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Full Telegram meh."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
chainflip-insights/Consumers/Mastodon/Mastodon-WeeklySwapOverview.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
namespace ChainflipInsights.Consumers.Mastodon | ||
{ | ||
using System; | ||
using System.Text; | ||
using ChainflipInsights.Feeders.WeeklySwapOverview; | ||
using Mastonet; | ||
using Microsoft.Extensions.Logging; | ||
|
||
public partial class MastodonConsumer | ||
{ | ||
private void ProcessWeeklySwapOverviewInfo(WeeklySwapOverviewInfo weeklySwapOverviewInfo) | ||
{ | ||
if (!_configuration.MastodonWeeklySwapOverviewEnabled.Value) | ||
{ | ||
_logger.LogInformation( | ||
"Weekly Swap Overview disabled for Mastodon. {StartDate} -> {EndDate}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
return; | ||
} | ||
|
||
try | ||
{ | ||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview for {StartDate} -> {EndDate} on Mastodon.", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd")); | ||
|
||
var text = new StringBuilder(); | ||
text.AppendLine($"💵 Weekly Top Swaps for {weeklySwapOverviewInfo.StartDate:yyyy-MM-dd} -> {weeklySwapOverviewInfo.EndDate:yyyy-MM-dd} are in!"); | ||
|
||
var emojis = new[] | ||
{ | ||
"🥇", | ||
"🥈", | ||
"🥉", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅", | ||
"🏅" | ||
}; | ||
|
||
for (var i = 0; i < weeklySwapOverviewInfo.Swaps.Count; i++) | ||
{ | ||
var swap = weeklySwapOverviewInfo.Swaps[i].Swap; | ||
var brokerExists = _brokers.TryGetValue(swap.Broker ?? string.Empty, out var broker); | ||
|
||
text.AppendLine( | ||
$"{emojis[i]} " + | ||
$"{swap.DepositAmountFormatted} #{swap.SourceAsset} (${swap.DepositValueUsdFormatted}) → " + | ||
$"{swap.EgressAmountFormatted} #{swap.DestinationAsset} (${swap.EgressValueUsdFormatted}) " + | ||
$"{(brokerExists ? $"@ {broker}" : string.Empty)}"); | ||
} | ||
|
||
text.AppendLine("#chainflip #flip"); | ||
|
||
var status = _mastodonClient | ||
.PublishStatus( | ||
text.ToString(), | ||
Visibility.Public) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
_logger.LogInformation( | ||
"Announcing Weekly Swap Overview {StartDate} -> {EndDate} on Mastodon as Message {MessageId}", | ||
weeklySwapOverviewInfo.StartDate.ToString("yyyy-MM-dd"), | ||
weeklySwapOverviewInfo.EndDate.ToString("yyyy-MM-dd"), | ||
status.Id); | ||
} | ||
catch (Exception e) | ||
{ | ||
_logger.LogError(e, "Mastodon meh."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.