Skip to content

Commit

Permalink
♻ Добавление обработчиков ошибок
Browse files Browse the repository at this point in the history
Подготовка к запоминанию refreshToken для последующего написания самообновления токенов.
  • Loading branch information
fet1sov authored Apr 9, 2023
1 parent f57b442 commit 76cd1df
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
5 changes: 4 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace StreamIntegration
namespace DonationIntegration
{
class Config
{
Expand All @@ -8,6 +8,9 @@ I will make an ini config in future
DO NOT TOUCH ACCESS TOKEN AND WHAT'S BELOW IT
*/



// You have to register your app right there -> https://www.donationalerts.com/application/clients
public static string client_id = ""; // You can change it to your own
public static string client_secret = ""; // You can change it to your own
public static string redirect_URL = ""; // You can change it to your own
Expand Down
19 changes: 16 additions & 3 deletions DAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/*
DonationAlerts API in C#
Based on work with Centrifuge server
Based on work with Centrifugo server
╔═══╗╔═╗╔═╗╔═══╗╔╗─╔╗╔═══╗╔╗─╔╗╔═══╗╔════╗
╚╗╔╗║╚╗╚╝╔╝║╔═╗║║║─║║║╔═╗║║║─║║║╔═╗║║╔╗╔╗║
Expand All @@ -19,7 +19,7 @@ Based on work with Centrifuge server
Written by dxAugust (aka fet1sov)
*/

namespace StreamIntegration
namespace DonationIntegration
{
class DAPI
{
Expand Down Expand Up @@ -204,6 +204,19 @@ private static string getAccessToken(string authToken)
accessToken = accessResponse.access_token;
Config.refresh_token = accessResponse.refresh_token;

// Делаем запоминание refreshToken'а, для последующего обновления
string configPath = Path.Combine(Directory.GetCurrentDirectory(), "ServerPlugins/DAIntegration/config.ini");
string configDirectory = Path.Combine(Directory.GetCurrentDirectory(), "ServerPlugins/DAIntegration");

if (Directory.Exists(@configDirectory))
{
if (File.Exists(@configPath))
{
IniParser parser = new IniParser(@configPath);
parser.AddSetting("DonationAlerts", "refreshtoken", accessResponse.refresh_token);
}
}

Debugger.successOutput("Successfully got the Access Token");
}
else
Expand Down Expand Up @@ -324,4 +337,4 @@ private static void OnSocketMessage(object sender, MessageEventArgs evt)
}
}
}
}
}
3 changes: 1 addition & 2 deletions Debugger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace StreamIntegration
namespace DonationIntegration
{
class Debugger
{
Expand All @@ -25,7 +25,6 @@ public static void errorOutput(string message)
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(Config.plugin_tag + message);

makeColorsBack();
}

Expand Down
43 changes: 22 additions & 21 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Hope it will make your streams funnier :)
*/

namespace StreamIntegration
namespace DonationIntegration
{
[ApiVersion(2, 1)]
public class Plugin : TerrariaPlugin
Expand All @@ -37,22 +37,31 @@ public Plugin(Main game) : base(game)
public override void Initialize()
{
/* Gets the ini config with auth code */
if (File.Exists(@FilePath))
if (Directory.Exists(FolderPath))
{
IniParser parser = new IniParser(@FilePath);
Config.authCode = parser.GetSetting("authconfig", "authcode");
} else {
if (File.Exists(@FilePath))
{
IniParser parser = new IniParser(@FilePath);
Config.authCode = parser.GetSetting("DonationAlerts", "authcode");

}
/* ================================== */

if (Config.authCode.Length != 0)
{
DAPI donateAPI = new DAPI(); // Initilization of the DonationAlerts API
random = new Random();
Debugger.messageOutput(Config.authCode);

DAPI donateAPI = new DAPI(); // Initilization of the DonationAlerts API
random = new Random();

parser.AddSetting("DonationAlerts", "refreshtoken", Config.refresh_token);
}
} else {
Directory.CreateDirectory(FolderPath);

string path = @FilePath;
string text = "[DonationAlerts]" + Environment.NewLine + "authcode=";

File.WriteAllText(@FilePath, text);

Debugger.errorOutput("You have to install authcode in your config file");
}
/* ================================== */
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -84,7 +93,7 @@ public static void handleDonate(string name, string currencyCode, int amount)

int badThings = random.Next(1, 10);

int playerID = 0;
int playerID = random.Next(1, TShock.Players.Length);
int spamCount = 30;
int zombieCount = 30;
int batsCount = 50;
Expand All @@ -95,8 +104,6 @@ public static void handleDonate(string name, string currencyCode, int amount)
break;

case 2:
playerID = random.Next(1, TShock.Players.Length);

NPC eye = TShock.Utils.GetNPCById(4);
TSPlayer.Server.SetTime(false, 0.0);
TSPlayer.Server.SpawnNPC(eye.type, name, 1, TShock.Players[playerID].TileX, TShock.Players[playerID].TileY);
Expand All @@ -110,8 +117,6 @@ public static void handleDonate(string name, string currencyCode, int amount)
break;

case 4:
playerID = random.Next(1, TShock.Players.Length);

NPC prime = TShock.Utils.GetNPCById(127);
TSPlayer.Server.SetTime(false, 0.0);
TSPlayer.Server.SpawnNPC(prime.type, name, 1, TShock.Players[playerID].TileX, TShock.Players[playerID].TileY);
Expand All @@ -122,7 +127,6 @@ public static void handleDonate(string name, string currencyCode, int amount)
break;

case 6:
playerID = random.Next(1, TShock.Players.Length);
TShock.Players[playerID].Kick("SORRY FOR DONATION :)", false, true);
break;

Expand All @@ -134,7 +138,6 @@ public static void handleDonate(string name, string currencyCode, int amount)
break;

case 8:
playerID = random.Next(1, TShock.Players.Length);

for (int i = 0; i < zombieCount; i++)
{
Expand All @@ -149,8 +152,6 @@ public static void handleDonate(string name, string currencyCode, int amount)
break;

case 10:
playerID = random.Next(1, TShock.Players.Length);

for (int i = 0; i < batsCount; i++)
{
NPC zombies = TShock.Utils.GetNPCById(51);
Expand Down

0 comments on commit 76cd1df

Please sign in to comment.