Skip to content

Commit

Permalink
clean up + wild / modern fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Glooomster committed Jul 23, 2022
1 parent fc1d57a commit a6b59dd
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SplinterTools.Helpers
{
public static class SplinterData
public static class SpDataHelper
{
public static SplinterlandsSetting splinterlandsSetting = new();
public static BattlesModel battles = new();
Expand Down
12 changes: 6 additions & 6 deletions SplinterTools/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@
Width="100"

>
<ComboBoxItem IsSelected="True">10 (sec)</ComboBoxItem>
<ComboBoxItem>30 (sec)</ComboBoxItem>
<ComboBoxItem>1 (min)</ComboBoxItem>
<ComboBoxItem>5 (min)</ComboBoxItem>
<ComboBoxItem>10 (min)</ComboBoxItem>
</ComboBox>
<ComboBoxItem IsSelected="True">1 (min)</ComboBoxItem>
<ComboBoxItem>5 (min)</ComboBoxItem>
<ComboBoxItem>10 (min)</ComboBoxItem>
<ComboBoxItem>30 (min)</ComboBoxItem>
<ComboBoxItem>1 (hour)</ComboBoxItem>
</ComboBox>


</Grid>
Expand Down
94 changes: 25 additions & 69 deletions SplinterTools/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,59 @@

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;



namespace SplinterTools
{

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>

public partial class MainWindow : Window
{

public string fileOfReportInXML = Directory.GetCurrentDirectory() + "/Files/AppConfig.json";

public string warningMessageTotal = "";
public string sentWhatsUpMessage = "";

public DispatcherTimer dispatcherTimer = new();
public int TestValue;

public Boolean enableWhatsup = false;




public MainWindow()
{
InitializeComponent();
ApiHelper.InitializeClient();
}


public void Window_Loaded(object sender, RoutedEventArgs e)
{
Helpers.SplinterData.splinterlandsSetting = Task.Run(() => new Processors.Splinterlands().GetSplinterlandsSetting()).Result;
bool checkSecurity = Processors.MessageProcessor.CheckSecurityDetails();

if (checkSecurity)
{
BtnEnableWhatsUp.IsEnabled = false;
};


Helpers.SpDataHelper.splinterlandsSetting = Task.Run(() => new Processors.SplinterProcessor().LoadSplinterlandsSetting()).Result;
GetSplinterData(0);
}

List<ListViewItem> UserModelList = new List<ListViewItem>();



public async void GetSplinterData(int testr)
{




var accountDetails = Processors.AccountDetailsProcessor.LoadAccountsObject();


UserModelList.Clear();




for (int i = 0; i < accountDetails.Count; i++)
{

Expand All @@ -75,8 +66,8 @@ public async void GetSplinterData(int testr)
var RentalInfo = await Processors.SplinterProcessor.LoadRentalInformation(accountDetails[i].AccName);


int baseRshares = Helpers.SplinterData.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].@base;
double multiplier = Helpers.SplinterData.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].step_multiplier;
int baseRshares = Helpers.SpDataHelper.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].@base;
double multiplier = Helpers.SpDataHelper.splinterlandsSetting.loot_chests.quest[QuestInfo[0].chest_tier].step_multiplier;
int chests = 0;
int fp_limit = baseRshares;

Expand All @@ -87,59 +78,48 @@ public async void GetSplinterData(int testr)
fp_limit = Convert.ToInt32(baseRshares + fp_limit * multiplier);
}



string leagueWildName = Helpers.SplinterData.splinterlandsSetting.leagues.modern[SplinterInfo.league].name;
string leagueModernName = Helpers.SplinterData.splinterlandsSetting.leagues.modern[SplinterInfo.modern_league].name;
string splinter = Helpers.SplinterData.splinterlandsSetting.daily_quests.Where(x => x.active == true && x.name == QuestInfo[0].name).FirstOrDefault().data.value;
string leagueWildName = Helpers.SpDataHelper.splinterlandsSetting.leagues.modern[SplinterInfo.league].name;
string leagueModernName = Helpers.SpDataHelper.splinterlandsSetting.leagues.modern[SplinterInfo.modern_league].name;
string splinter = Helpers.SpDataHelper.splinterlandsSetting.daily_quests.Where(x => x.active == true && x.name == QuestInfo[0].name).FirstOrDefault().data.value;
string questItems = QuestInfo[0].completed_items.ToString();




//Last 50 Matches Win rate modern


Helpers.SplinterData.battles = Task.Run(() => new Processors.Splinterlands().GetRateSetting(accountDetails[i].AccName, "modern")).Result;
Helpers.SpDataHelper.battles = Task.Run(() => new Processors.SplinterProcessor().LoadBattleHiistory(accountDetails[i].AccName, "modern")).Result;

int totalmodernWins = 0;
int totalmoderngames = Helpers.SplinterData.battles.battles.Length;
int totalmoderngames = Helpers.SpDataHelper.battles.battles.Length;


if (Helpers.SplinterData.battles != null)
if (Helpers.SpDataHelper.battles != null)
{
for (int it = 0; it < totalmoderngames; it++)
{
if (Helpers.SplinterData.battles.battles[it].winner == accountDetails[i].AccName)
if (Helpers.SpDataHelper.battles.battles[it].winner == accountDetails[i].AccName)
{
totalmodernWins++;
}
}
}


//Last 50 Matches Win rate wild


Helpers.SplinterData.battles = Task.Run(() => new Processors.Splinterlands().GetRateSetting(accountDetails[i].AccName, "wild")).Result;
Helpers.SpDataHelper.battles = Task.Run(() => new Processors.SplinterProcessor().LoadBattleHiistory(accountDetails[i].AccName, "wild")).Result;

int totalWildnWins = 0;
int totalWildgames = Helpers.SplinterData.battles.battles.Length;
int totalWildgames = Helpers.SpDataHelper.battles.battles.Length;


if (Helpers.SplinterData.battles != null)
if (Helpers.SpDataHelper.battles != null)
{
for (int it = 0; it < totalWildgames; it++)
{
if (Helpers.SplinterData.battles.battles[it].winner == accountDetails[i].AccName)
if (Helpers.SpDataHelper.battles.battles[it].winner == accountDetails[i].AccName)
{
totalWildnWins++;
}
}
}



//rental check
int rentCancelNumber = 0;

Expand All @@ -149,16 +129,11 @@ public async void GetSplinterData(int testr)
{
if (RentalInfo[it].cancel_date != null)
{
//System.Diagnostics.Debug.Print(RentalInfo[it].cancel_date.ToString());
//System.Diagnostics.Debug.Print(it.ToString());
rentCancelNumber++;
}
}
}




if (SplinterInfo.collection_power < accountDetails[i].Power)
{

Expand Down Expand Up @@ -187,8 +162,6 @@ public async void GetSplinterData(int testr)
warningMessageTotal = warningMessageTotal + SplinterInfo.name + ":\n" + warningMessage + "\n";
}



OneListItem.Content = new Helpers.UserModel()
{
RentCancel = rentCancelNumber,
Expand All @@ -215,16 +188,10 @@ public async void GetSplinterData(int testr)

};





UserModelList.Add(OneListItem);

}



if (warningMessageTotal.Length > 0)
{

Expand All @@ -240,7 +207,6 @@ public async void GetSplinterData(int testr)
sentWhatsUpMessage = warningMessageTotal;

}


//clear the message
warningMessageTotal = "";
Expand All @@ -249,12 +215,8 @@ public async void GetSplinterData(int testr)
SplinterList.ItemsSource = UserModelList;
SplinterList.Items.Refresh();


}




private void BtnRefresh_Click(object sender, RoutedEventArgs e)
{
sentWhatsUpMessage = "";
Expand All @@ -273,17 +235,11 @@ private void BtnRefresh_Click(object sender, RoutedEventArgs e)

}





BtnRefresh.IsEnabled = false;
cmbRefresh.IsEnabled = false;

}



protected void DispatcherTimer_Tick(object sender, EventArgs e)
{
TestValue += 1;
Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions SplinterTools/Processors/AccountDetailsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@
using System.Collections.Generic;
using System.IO;



namespace SplinterTools.Processors
{
public class AccountDetailsProcessor
{
public static List<Model.AccountModel> LoadAccountsObject()
{



string json = Directory.GetCurrentDirectory() + "/Files/AppConfig.json";
var SplinterAccounts = JsonConvert.DeserializeObject<List<Model.AccountModel>>(File.ReadAllText(json));

return SplinterAccounts;


}

public static void updateAccounts(string account, int power)
Expand All @@ -40,15 +34,6 @@ public static void updateAccounts(string account, int power)

jsonData = JsonConvert.SerializeObject(SplinterAccounts);
System.IO.File.WriteAllText(json, jsonData);



}


}




}
30 changes: 24 additions & 6 deletions SplinterTools/Processors/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

Expand All @@ -22,6 +19,22 @@ public class Security
}


public static bool CheckSecurityDetails ()

{
using (StreamReader r = new StreamReader(Directory.GetCurrentDirectory() + "/Files/SecurityConfig.json"))
{
string json = r.ReadToEnd();
List<Processors.MessageProcessor.Security> items = JsonConvert.DeserializeObject<List<Processors.MessageProcessor.Security>>(json);
if (items[0].accountSid == "")
{
return true;
}

return false;
}
}



public static void SendMessage(string Message)
Expand All @@ -34,9 +47,14 @@ public static void SendMessage(string Message)
string json = r.ReadToEnd();
List<Security> items = JsonConvert.DeserializeObject<List<Security>>(json);

TwilioClient.Init(items[0].accountSid, items[0].authToken);
var message = MessageResource.Create(from: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].from), body: Message, to: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].to));
Console.WriteLine(message.Sid);
if (items[0].accountSid != "")
{
TwilioClient.Init(items[0].accountSid, items[0].authToken);
var message = MessageResource.Create(from: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].from), body: Message, to: new Twilio.Types.PhoneNumber("whatsapp:" + items[0].to));
Console.WriteLine(message.Sid);
}


}


Expand Down
Loading

0 comments on commit a6b59dd

Please sign in to comment.