Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ウェブフックのリファクタ #52

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove legacy methods
  • Loading branch information
Hyz-sui committed Apr 9, 2024
commit 72b63b02f791b90c91730bd774af4d3b351abcea
44 changes: 0 additions & 44 deletions Modules/Utils.cs
Original file line number Diff line number Diff line change
@@ -1130,50 +1130,6 @@ public static void FlashColor(Color color, float duration = 1f)
obj.GetComponent<SpriteRenderer>().color = new(color.r, color.g, color.b, Mathf.Clamp01((-2f * Mathf.Abs(t - 0.5f) + 1) * color.a)); //アルファ値を0→目標→0に変化させる
})));
}
public static void MakeWebhookUrlFile()
{
Logger.Info("WebhookUrl.txtを作成", "Webhook");
try
{
File.WriteAllText("WebhookUrl.txt", "この文章を削除してウェブフックのURLを記述/Remove this text and enter Webhook url");
}
catch (Exception ex)
{
Logger.Error(ex.ToString(), "Webhook");
}
}
public static void SendWebhook(string text, string userName = "Town Of Host")
{
if (!File.Exists("WebhookUrl.txt"))
MakeWebhookUrlFile();
HttpClient client = new();
Dictionary<string, string> message = new()
{
{ "content", text },
{ "username", userName },
{ "avatar_url", "https://raw.githubusercontent.com/Hyz-sui/TownOfHost-H/images-H/Images/discord-avatar.png" }
};
using StreamReader sr = new("WebhookUrl.txt", Encoding.UTF8);
string webhookUrl = sr.ReadLine();
if (!Regex.IsMatch(webhookUrl, "^(https://(ptb.|canary.)?discord(app)?.com/api/webhooks/)")) // ptbとcanaryとappはあってもなくてもいい
{
Logger.Info("WebhookUrl.txtの内容がdiscordのウェブフックurlではなかったためウェブフックの送信をキャンセル", "Webhook");
return;
}
try
{
TaskAwaiter<HttpResponseMessage> awaiter = client.PostAsync(webhookUrl, new FormUrlEncodedContent(message)).GetAwaiter();
var response = awaiter.GetResult();
Logger.Info("ウェブフックを送信しました", "Webhook");
if (!response.IsSuccessStatusCode)
Logger.Warn("応答が異常です", "Webhook");
Logger.Info($"{(int)response.StatusCode} {response.ReasonPhrase}", "Webhook"); // 正常な応答: 204 No Content
}
catch (Exception ex)
{
Logger.Error(ex.ToString(), "Webhook");
}
}
public static string ColorIdToDiscordEmoji(int colorId, bool alive)
{
if (alive)