Skip to content

Commit

Permalink
Merge pull request #750 from area363/add-arena-data-slack-notification
Browse files Browse the repository at this point in the history
send slack message when arena season ranking is finalized
  • Loading branch information
area363 authored Aug 14, 2024
2 parents c885719 + ed422cb commit ffd0636
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Net.Http;
using System.Threading.Tasks;

namespace NineChronicles.DataProvider.Executable.Commands
{
using System;
Expand Down Expand Up @@ -133,7 +136,19 @@ public void Migration(
[Option(
"mysql-database",
Description = "The name of MySQL database to use.")]
string mysqlDatabase
string mysqlDatabase,
[Option(
"slack-token",
Description = "slack token to send the migration data.")]
string slackToken,
[Option(
"slack-channel",
Description = "slack channel that receives the migration data.")]
string slackChannel,
[Option(
"network",
Description = "Name of network(e.g., Odin or Heimdall)")]
string network
)
{
DateTimeOffset start = DateTimeOffset.UtcNow;
Expand Down Expand Up @@ -1001,6 +1016,16 @@ string mysqlDatabase
connection.Close();
Console.WriteLine($"Delete {fbBARDbName}_Dump Complete!");
Console.WriteLine($"Finalize {fbBARDbName} & {fbUSDbName} Tables Complete!");

if (slackToken is not null && slackChannel is not null)
{
var slackMessage = $"@here {network} arena season(Championship Id: {prevArenaData.ChampionshipId}/Round: {prevArenaData.Round}) ranking finalized! Check tables {fbBARDbName} & {fbUSDbName}.";
SendMessageAsync(
slackToken,
slackChannel,
slackMessage
).Wait();
}
}

bARDbName = $"{bARDbName}_{arenaData.ChampionshipId}_{arenaData.Round}";
Expand Down Expand Up @@ -1655,6 +1680,25 @@ string mysqlDatabase
Console.WriteLine("Shop Count for {0} avatars: {1}", avatars.Count, shopOrderCount);
}

private async Task SendMessageAsync(string token, string channel, string message)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);

var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("channel", channel),
new KeyValuePair<string, string>("text", message)
});

var url = "https://slack.com/api/chat.postMessage";
var response = await client.PostAsync(url, content);
var responseJson = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseJson);
}
}

private void FlushBulkFiles()
{
_agentBulkFile.Flush();
Expand Down

0 comments on commit ffd0636

Please sign in to comment.