Skip to content

Commit 9dc927e

Browse files
authored
Merge pull request #184 from Erol444/hotfixes/2.2.1
- Fix crash when open with old database file - Fix farmlist cannot be sent - Fix hero adventures timer things (again, it should be fixed this time) - Change version window UI If you like my work, you can donate to me through [ko-fi.com/vinaghost](https://ko-fi.com/vinaghost)
2 parents 0dd664c + 270f062 commit 9dc927e

File tree

10 files changed

+52
-92
lines changed

10 files changed

+52
-92
lines changed

.github/workflows/pre-release.yml renamed to .github/workflows/hotfix.yml

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
name: PreReleaseFlow
1+
name: HotfixFlow
22

33
on:
44
pull_request:
5-
branches:
6-
- 'releases/**'
5+
branches: [master]
76
types: [closed]
8-
workflow_dispatch:
97

108
jobs:
119
version:
1210
if: github.event.pull_request.merged == true
1311
runs-on: ubuntu-latest
1412
outputs:
1513
version: ${{ steps.semvers.outputs.patch }}
14+
changelog: ${{ steps.Changelog.outputs.changelog }}
15+
1616
steps:
1717
- uses: docker://agilepathway/pull-request-label-checker:latest
1818
with:
19-
one_of: pre-release
19+
one_of: hotfix
2020
repo_token: ${{ secrets.GITHUB_TOKEN }}
2121

2222
- name: 'Checkout repo'
@@ -34,6 +34,15 @@ jobs:
3434
uses: "WyriHaximus/github-action-next-semvers@v1"
3535
with:
3636
version: ${{ steps.previoustag.outputs.tag }}
37+
38+
- name: 'Create changelog'
39+
id: Changelog
40+
run: |
41+
changelog="${{github.event.pull_request.body}}"
42+
changelog="${changelog//'%'/'%25'}"
43+
changelog="${changelog//$'\n'/'%0A'}"
44+
changelog="${changelog//$'\r'/'%0D'}"
45+
echo "::set-output name=changelog::$changelog"
3746
3847
build:
3948
runs-on: windows-2019
@@ -63,7 +72,7 @@ jobs:
6372
path: WPFUI\bin\Release\net6.0-windows\win-x86\publish\
6473
if-no-files-found: error
6574

66-
prerelease:
75+
release:
6776
runs-on: ubuntu-latest
6877
needs: [build, version]
6978
steps:
@@ -72,42 +81,48 @@ jobs:
7281
with:
7382
path: TBS
7483

75-
- name: Archive pre release
84+
- name: Archive release
7685
run: |
7786
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip" TBS-TRAVIAN_OFFICIAL; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip" ../; cd ..
7887
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip" TBS-TRAVIAN_OFFICIAL_HEROUI; cp -R "TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip" ../; cd ..
7988
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
8089
81-
- name: Create pre release
90+
- name: Create release
8291
uses: ncipollo/release-action@v1
8392
with:
8493
name: TBS-${{needs.version.outputs.version}}
85-
prerelease: true
8694
tag: ${{needs.version.outputs.version}}
87-
commit: develop
95+
commit: master
8896
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
8997
token: ${{ secrets.GITHUB_TOKEN }}
9098
body: |
91-
This is pre-release version of TBS. Please report any bugs you found.
9299
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
93-
94-
100+
101+
**Changelog**:
102+
${{needs.version.outputs.changelog}}
103+
95104
Discord:
96105
runs-on: ubuntu-latest
97-
needs: [prerelease, version]
98-
steps:
106+
needs: [release, version]
107+
steps:
108+
- name: Ping @everyone
109+
run: |
110+
curl --header "Content-Type: application/json" --data "{\"content\": \"@everyone\"}" "${{ secrets.DISCORD_BOT }}"
99111
- name: Send to discord server
100112
uses: sarisia/actions-status-discord@v1
101113
with:
102-
webhook: ${{ secrets.DISCORD_PRE_BOT }}
103-
title: New pre-release
104-
nodetail: true
114+
webhook: ${{ secrets.DISCORD_BOT }}
115+
title: New hotfix
116+
nodetail: true
105117
description: |
106118
Version `TBS-${{needs.version.outputs.version}}`
107-
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download
119+
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download!
120+
121+
**Changelog**:
122+
${{needs.version.outputs.changelog}}
108123
Clear:
109124
runs-on: ubuntu-latest
110-
needs: prerelease
125+
needs: release
111126
strategy:
112127
matrix:
113128
server: [TRAVIAN_OFFICIAL, TRAVIAN_OFFICIAL_HEROUI, TTWARS]

MainCore/Helper/GithubHelper.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,5 @@ public static async Task<Version> CheckGitHubLatestVersion()
3030
}
3131
return null;
3232
}
33-
34-
public static async Task<Version> CheckGitHublatestBuild()
35-
{
36-
try
37-
{
38-
var releases = await _client.Repository.Release.GetAll(_username, _repo);
39-
if (releases.Count > 0) return new Version(releases[0].TagName);
40-
}
41-
catch
42-
{
43-
}
44-
return null;
45-
}
4633
}
4734
}

MainCore/MainCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
55
<!--<Server>TRAVIAN_OFFICIAL</Server>-->
6-
<!--<Server>TRAVIAN_OFFICIAL_HEROUI</Server>-->
7-
<Server>TTWARS</Server>
6+
<Server>TRAVIAN_OFFICIAL_HEROUI</Server>
7+
<!--<Server>TTWARS</Server>-->
88

99
<DefineConstants Condition="'$(Server)' != ''">$(DefineConstants);$(Server)</DefineConstants>
1010
</PropertyGroup>

MainCore/Migrations/202210181120_UpgradeTroopMigrations.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public override void Up()
1616
{
1717
Alter.Table("VillagesSettings")
1818
.AddColumn("IsUpgradeTroop").AsBoolean().WithDefaultValue(false)
19-
.AddColumn("UpgradeTroop").AsString();
19+
.AddColumn("UpgradeTroop").AsString().Nullable();
2020
}
2121
}
2222
}

MainCore/Tasks/Attack/StartFarmList.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ public StartFarmList(int accountId, int farmId) : base(accountId, "Start farmlis
3232
public int FarmId => _farmId;
3333
private string _nameFarm;
3434

35-
private readonly Random rand = new();
36-
3735
public override void CopyFrom(BotTask source)
3836
{
3937
base.CopyFrom(source);
@@ -62,7 +60,7 @@ public override void Execute()
6260
using var context = _contextFactory.CreateDbContext();
6361
NavigateHelper.AfterClicking(_chromeBrowser, context, AccountId);
6462
}
65-
if (!IsUpdateFail())
63+
if (IsUpdateFail())
6664
{
6765
return;
6866
}
@@ -87,7 +85,7 @@ public override void Execute()
8785
{
8886
using var context = _contextFactory.CreateDbContext();
8987
var setting = context.FarmsSettings.Find(FarmId);
90-
var time = rand.Next(setting.IntervalMin, setting.IntervalMax);
88+
var time = Random.Shared.Next(setting.IntervalMin, setting.IntervalMax);
9189
ExecuteAt = DateTime.Now.AddSeconds(time);
9290
_logManager.Information(AccountId, $"Farmlist {_nameFarm} was sent.");
9391
}
@@ -150,7 +148,7 @@ private void ClickStartFarm(AppDbContext context, int accountId)
150148
return !table.HasClass("hide");
151149
});
152150

153-
var delay = rand.Next(setting.ClickDelayMin, setting.ClickDelayMax);
151+
var delay = Random.Shared.Next(setting.ClickDelayMin, setting.ClickDelayMax);
154152
Thread.Sleep(delay);
155153

156154
var checkboxAlls = chrome.FindElements(By.Id($"raidListMarkAll{FarmId}"));
@@ -160,7 +158,7 @@ private void ClickStartFarm(AppDbContext context, int accountId)
160158
}
161159
checkboxAlls.Click(_chromeBrowser, context, accountId);
162160

163-
delay = rand.Next(setting.ClickDelayMin, setting.ClickDelayMax);
161+
delay = Random.Shared.Next(setting.ClickDelayMin, setting.ClickDelayMax);
164162
Thread.Sleep(delay);
165163

166164
var html = _chromeBrowser.GetHtml();

MainCore/Tasks/Update/UpdateAdventures.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public override void Execute()
4040
taskAutoSend.CopyFrom(this);
4141
taskAutoSend.Execute();
4242
taskUpdate.Execute();
43+
NavigateHelper.Sleep(800, 1500);
4344
NextExecute();
4445
}
4546
}
@@ -62,12 +63,14 @@ private void NextExecute()
6263
#endif
6364
if (tileDetails is null)
6465
{
65-
throw new Exception("Cannot find timer");
66+
ExecuteAt = DateTime.Now.AddMinutes(Random.Shared.Next(5, 10));
67+
return;
6668
}
6769
var timer = tileDetails.Descendants("span").FirstOrDefault(x => x.HasClass("timer"));
6870
if (timer is null)
6971
{
70-
throw new Exception("Cannot find timer");
72+
ExecuteAt = DateTime.Now.AddMinutes(Random.Shared.Next(5, 10));
73+
return;
7174
}
7275

7376
int sec = int.Parse(timer.GetAttributeValue("value", "0"));

TravianOfficialNewHeroUICore/Parsers/HeroInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ public static (int, int) GetAdventureCoordinates(HtmlNode node)
127127
if (tdList.Length < 2) return (0, 0);
128128
var coords = tdList[1].InnerText.Split('|');
129129
if (coords.Length < 2) return (0, 0);
130+
coords[0] = coords[0].Replace('−', '-');
130131
var valueX = new string(coords[0].Where(c => char.IsDigit(c) || c == '-').ToArray());
131132
if (string.IsNullOrEmpty(valueX)) return (0, 0);
133+
coords[1] = coords[1].Replace('−', '-');
132134
var valueY = new string(coords[1].Where(c => char.IsDigit(c) || c == '-').ToArray());
133135
if (string.IsNullOrEmpty(valueY)) return (0, 0);
134136
return (int.Parse(valueX), int.Parse(valueY));

WPFUI/ViewModels/VersionViewModel.cs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ public VersionViewModel()
1818

1919
DiscordCommand = ReactiveCommand.Create(DiscordTask);
2020
LatestVersionCommand = ReactiveCommand.Create(LatestVersionTask, this.WhenAnyValue(x => x.IsNewVersion));
21-
LatestBuildCommand = ReactiveCommand.Create(LatestBuildTask, this.WhenAnyValue(x => x.IsNewBuild));
2221
CloseCommand = ReactiveCommand.Create(CloseTask);
2322
}
2423

2524
public async Task Load()
2625
{
27-
var result = await Task.WhenAll(GithubHelper.CheckGitHubLatestVersion(), GithubHelper.CheckGitHublatestBuild());
26+
var result = await GithubHelper.CheckGitHubLatestVersion();
2827

29-
LatestVersion = result[0].ToString();
30-
LatestBuild = result[1].ToString();
28+
LatestVersion = result.ToString();
3129
}
3230

3331
private void DiscordTask()
@@ -49,16 +47,6 @@ private void LatestVersionTask()
4947
CloseTask();
5048
}
5149

52-
private void LatestBuildTask()
53-
{
54-
Process.Start(new ProcessStartInfo
55-
{
56-
FileName = GithubHelper.GetLink(_latestBuild),
57-
UseShellExecute = true
58-
});
59-
CloseTask();
60-
}
61-
6250
private void CloseTask()
6351
{
6452
CloseWindow?.Invoke();
@@ -68,7 +56,7 @@ private void CloseTask()
6856

6957
public string CurrentVersion
7058
{
71-
get => $"Current: {_currentVersion}";
59+
get => $"Current version: {_currentVersion}";
7260
set => this.RaiseAndSetIfChanged(ref _currentVersion, value);
7361
}
7462

@@ -85,18 +73,6 @@ public string LatestVersion
8573
}
8674
}
8775

88-
private string _latestBuild;
89-
90-
public string LatestBuild
91-
{
92-
get => $"Latest build: {_latestBuild}";
93-
set
94-
{
95-
this.RaiseAndSetIfChanged(ref _latestBuild, value);
96-
this.RaisePropertyChanged(nameof(IsNewBuild));
97-
}
98-
}
99-
10076
public bool IsNewVersion
10177
{
10278
get
@@ -107,16 +83,6 @@ public bool IsNewVersion
10783
}
10884
}
10985

110-
public bool IsNewBuild
111-
{
112-
get
113-
{
114-
var current = new Version($"{_currentVersion}.0");
115-
var last = new Version($"{_latestVersion}.0");
116-
return current.CompareTo(last) < 0;
117-
}
118-
}
119-
12086
public string Message
12187
{
12288
get => message[IsNewVersion ? 1 : 0];
@@ -131,7 +97,6 @@ public string Message
13197

13298
public ReactiveCommand<Unit, Unit> DiscordCommand { get; }
13399
public ReactiveCommand<Unit, Unit> LatestVersionCommand { get; }
134-
public ReactiveCommand<Unit, Unit> LatestBuildCommand { get; }
135100
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
136101

137102
public event Action CloseWindow;

WPFUI/Views/VersionWindow.xaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<Grid.ColumnDefinitions>
1414
<ColumnDefinition Width="1*" />
1515
<ColumnDefinition Width="1*" />
16-
<ColumnDefinition Width="1*" />
1716
</Grid.ColumnDefinitions>
1817
<Grid.RowDefinitions>
1918
<RowDefinition Height="2*" />
@@ -31,15 +30,8 @@
3130
<Border x:Name="LastVersionBorder" BorderBrush="Black" BorderThickness="1" Grid.Column="1" Margin="20,10,20,0" Grid.Row="2">
3231
<TextBlock x:Name="LastVersionLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" />
3332
</Border>
34-
<Border x:Name="LastBuildBorder" BorderBrush="Black" BorderThickness="1" Grid.Column="2" Margin="20,10,20,0" Grid.Row="2">
35-
<TextBlock x:Name="LastBuildLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" />
36-
</Border>
37-
<Border x:Name="NoteBorder" BorderBrush="Black" BorderThickness="1" Grid.ColumnSpan="3" Margin="20,5,20,5" Grid.Row="3">
38-
<TextBlock x:Name="NoteLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="Latest version is stable (we hope) while latest build is unstable and maybe for tester only" VerticalAlignment="Center" />
39-
</Border>
4033
<Button x:Name="DiscordButton" Content="Discord" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
4134
<Button x:Name="LastVersionButton" Grid.Column="1" Content="Download latest version" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
42-
<Button x:Name="LastBuildButton" Grid.Column="2" Content="Download latest build" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
4335
<Button x:Name="CloseButton" Content="Close" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Margin="20,0,20,10" Grid.Row="4" VerticalAlignment="Stretch" />
4436
</Grid>
4537
</reactiveui:ReactiveWindow>

WPFUI/Views/VersionWindow.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ public VersionWindow()
1919
{
2020
this.BindCommand(ViewModel, vm => vm.DiscordCommand, v => v.DiscordButton).DisposeWith(d);
2121
this.BindCommand(ViewModel, vm => vm.LatestVersionCommand, v => v.LastVersionButton).DisposeWith(d);
22-
this.BindCommand(ViewModel, vm => vm.LatestBuildCommand, v => v.LastBuildButton).DisposeWith(d);
2322
this.BindCommand(ViewModel, vm => vm.CloseCommand, v => v.CloseButton).DisposeWith(d);
2423

2524
this.OneWayBind(ViewModel, vm => vm.Message, v => v.StatusLabel.Text).DisposeWith(d);
2625
this.OneWayBind(ViewModel, vm => vm.CurrentVersion, v => v.CurrentLabel.Text).DisposeWith(d);
2726
this.OneWayBind(ViewModel, vm => vm.LatestVersion, v => v.LastVersionLabel.Text).DisposeWith(d);
28-
this.OneWayBind(ViewModel, vm => vm.LatestBuild, v => v.LastBuildLabel.Text).DisposeWith(d);
2927
});
3028
}
3129
}

0 commit comments

Comments
 (0)