Skip to content

Commit

Permalink
Merge pull request #184 from Erol444/hotfixes/2.2.1
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
vinaghost authored Oct 26, 2022
2 parents 0dd664c + 270f062 commit 9dc927e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 92 deletions.
55 changes: 35 additions & 20 deletions .github/workflows/pre-release.yml → .github/workflows/hotfix.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: PreReleaseFlow
name: HotfixFlow

on:
pull_request:
branches:
- 'releases/**'
branches: [master]
types: [closed]
workflow_dispatch:

jobs:
version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semvers.outputs.patch }}
changelog: ${{ steps.Changelog.outputs.changelog }}

steps:
- uses: docker://agilepathway/pull-request-label-checker:latest
with:
one_of: pre-release
one_of: hotfix
repo_token: ${{ secrets.GITHUB_TOKEN }}

- name: 'Checkout repo'
Expand All @@ -34,6 +34,15 @@ jobs:
uses: "WyriHaximus/github-action-next-semvers@v1"
with:
version: ${{ steps.previoustag.outputs.tag }}

- name: 'Create changelog'
id: Changelog
run: |
changelog="${{github.event.pull_request.body}}"
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
echo "::set-output name=changelog::$changelog"
build:
runs-on: windows-2019
Expand Down Expand Up @@ -63,7 +72,7 @@ jobs:
path: WPFUI\bin\Release\net6.0-windows\win-x86\publish\
if-no-files-found: error

prerelease:
release:
runs-on: ubuntu-latest
needs: [build, version]
steps:
Expand All @@ -72,42 +81,48 @@ jobs:
with:
path: TBS

- name: Archive pre release
- name: Archive release
run: |
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 ..
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 ..
cd TBS; zip -r "TBS-${{needs.version.outputs.version}}-TTWars.zip" TBS-TTWARS; cp -R "TBS-${{needs.version.outputs.version}}-TTWars.zip" ../; cd ..
- name: Create pre release
- name: Create release
uses: ncipollo/release-action@v1
with:
name: TBS-${{needs.version.outputs.version}}
prerelease: true
tag: ${{needs.version.outputs.version}}
commit: develop
commit: master
artifacts: "TBS-${{needs.version.outputs.version}}-TravianOfficial-OldHeroUI.zip, TBS-${{needs.version.outputs.version}}-TravianOfficial-NewHeroUI.zip, TBS-${{needs.version.outputs.version}}-TTWars.zip"
token: ${{ secrets.GITHUB_TOKEN }}
body: |
This is pre-release version of TBS. Please report any bugs you found.
Please join our Discord server for more information: [https://discord.gg/mBa4f2K](https://discord.gg/mBa4f2K)
**Changelog**:
${{needs.version.outputs.changelog}}
Discord:
runs-on: ubuntu-latest
needs: [prerelease, version]
steps:
needs: [release, version]
steps:
- name: Ping @everyone
run: |
curl --header "Content-Type: application/json" --data "{\"content\": \"@everyone\"}" "${{ secrets.DISCORD_BOT }}"
- name: Send to discord server
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_PRE_BOT }}
title: New pre-release
nodetail: true
webhook: ${{ secrets.DISCORD_BOT }}
title: New hotfix
nodetail: true
description: |
Version `TBS-${{needs.version.outputs.version}}`
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download
Click [here](https://github.com/Erol444/TravianBotSharp/releases/tag/${{needs.version.outputs.version}}) to download!
**Changelog**:
${{needs.version.outputs.changelog}}
Clear:
runs-on: ubuntu-latest
needs: prerelease
needs: release
strategy:
matrix:
server: [TRAVIAN_OFFICIAL, TRAVIAN_OFFICIAL_HEROUI, TTWARS]
Expand Down
13 changes: 0 additions & 13 deletions MainCore/Helper/GithubHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,5 @@ public static async Task<Version> CheckGitHubLatestVersion()
}
return null;
}

public static async Task<Version> CheckGitHublatestBuild()
{
try
{
var releases = await _client.Repository.Release.GetAll(_username, _repo);
if (releases.Count > 0) return new Version(releases[0].TagName);
}
catch
{
}
return null;
}
}
}
4 changes: 2 additions & 2 deletions MainCore/MainCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!--<Server>TRAVIAN_OFFICIAL</Server>-->
<!--<Server>TRAVIAN_OFFICIAL_HEROUI</Server>-->
<Server>TTWARS</Server>
<Server>TRAVIAN_OFFICIAL_HEROUI</Server>
<!--<Server>TTWARS</Server>-->

<DefineConstants Condition="'$(Server)' != ''">$(DefineConstants);$(Server)</DefineConstants>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion MainCore/Migrations/202210181120_UpgradeTroopMigrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void Up()
{
Alter.Table("VillagesSettings")
.AddColumn("IsUpgradeTroop").AsBoolean().WithDefaultValue(false)
.AddColumn("UpgradeTroop").AsString();
.AddColumn("UpgradeTroop").AsString().Nullable();
}
}
}
10 changes: 4 additions & 6 deletions MainCore/Tasks/Attack/StartFarmList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public StartFarmList(int accountId, int farmId) : base(accountId, "Start farmlis
public int FarmId => _farmId;
private string _nameFarm;

private readonly Random rand = new();

public override void CopyFrom(BotTask source)
{
base.CopyFrom(source);
Expand Down Expand Up @@ -62,7 +60,7 @@ public override void Execute()
using var context = _contextFactory.CreateDbContext();
NavigateHelper.AfterClicking(_chromeBrowser, context, AccountId);
}
if (!IsUpdateFail())
if (IsUpdateFail())
{
return;
}
Expand All @@ -87,7 +85,7 @@ public override void Execute()
{
using var context = _contextFactory.CreateDbContext();
var setting = context.FarmsSettings.Find(FarmId);
var time = rand.Next(setting.IntervalMin, setting.IntervalMax);
var time = Random.Shared.Next(setting.IntervalMin, setting.IntervalMax);
ExecuteAt = DateTime.Now.AddSeconds(time);
_logManager.Information(AccountId, $"Farmlist {_nameFarm} was sent.");
}
Expand Down Expand Up @@ -150,7 +148,7 @@ private void ClickStartFarm(AppDbContext context, int accountId)
return !table.HasClass("hide");
});

var delay = rand.Next(setting.ClickDelayMin, setting.ClickDelayMax);
var delay = Random.Shared.Next(setting.ClickDelayMin, setting.ClickDelayMax);
Thread.Sleep(delay);

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

delay = rand.Next(setting.ClickDelayMin, setting.ClickDelayMax);
delay = Random.Shared.Next(setting.ClickDelayMin, setting.ClickDelayMax);
Thread.Sleep(delay);

var html = _chromeBrowser.GetHtml();
Expand Down
7 changes: 5 additions & 2 deletions MainCore/Tasks/Update/UpdateAdventures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override void Execute()
taskAutoSend.CopyFrom(this);
taskAutoSend.Execute();
taskUpdate.Execute();
NavigateHelper.Sleep(800, 1500);
NextExecute();
}
}
Expand All @@ -62,12 +63,14 @@ private void NextExecute()
#endif
if (tileDetails is null)
{
throw new Exception("Cannot find timer");
ExecuteAt = DateTime.Now.AddMinutes(Random.Shared.Next(5, 10));
return;
}
var timer = tileDetails.Descendants("span").FirstOrDefault(x => x.HasClass("timer"));
if (timer is null)
{
throw new Exception("Cannot find timer");
ExecuteAt = DateTime.Now.AddMinutes(Random.Shared.Next(5, 10));
return;
}

int sec = int.Parse(timer.GetAttributeValue("value", "0"));
Expand Down
2 changes: 2 additions & 0 deletions TravianOfficialNewHeroUICore/Parsers/HeroInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ public static (int, int) GetAdventureCoordinates(HtmlNode node)
if (tdList.Length < 2) return (0, 0);
var coords = tdList[1].InnerText.Split('|');
if (coords.Length < 2) return (0, 0);
coords[0] = coords[0].Replace('−', '-');
var valueX = new string(coords[0].Where(c => char.IsDigit(c) || c == '-').ToArray());
if (string.IsNullOrEmpty(valueX)) return (0, 0);
coords[1] = coords[1].Replace('−', '-');
var valueY = new string(coords[1].Where(c => char.IsDigit(c) || c == '-').ToArray());
if (string.IsNullOrEmpty(valueY)) return (0, 0);
return (int.Parse(valueX), int.Parse(valueY));
Expand Down
41 changes: 3 additions & 38 deletions WPFUI/ViewModels/VersionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ public VersionViewModel()

DiscordCommand = ReactiveCommand.Create(DiscordTask);
LatestVersionCommand = ReactiveCommand.Create(LatestVersionTask, this.WhenAnyValue(x => x.IsNewVersion));
LatestBuildCommand = ReactiveCommand.Create(LatestBuildTask, this.WhenAnyValue(x => x.IsNewBuild));
CloseCommand = ReactiveCommand.Create(CloseTask);
}

public async Task Load()
{
var result = await Task.WhenAll(GithubHelper.CheckGitHubLatestVersion(), GithubHelper.CheckGitHublatestBuild());
var result = await GithubHelper.CheckGitHubLatestVersion();

LatestVersion = result[0].ToString();
LatestBuild = result[1].ToString();
LatestVersion = result.ToString();
}

private void DiscordTask()
Expand All @@ -49,16 +47,6 @@ private void LatestVersionTask()
CloseTask();
}

private void LatestBuildTask()
{
Process.Start(new ProcessStartInfo
{
FileName = GithubHelper.GetLink(_latestBuild),
UseShellExecute = true
});
CloseTask();
}

private void CloseTask()
{
CloseWindow?.Invoke();
Expand All @@ -68,7 +56,7 @@ private void CloseTask()

public string CurrentVersion
{
get => $"Current: {_currentVersion}";
get => $"Current version: {_currentVersion}";
set => this.RaiseAndSetIfChanged(ref _currentVersion, value);
}

Expand All @@ -85,18 +73,6 @@ public string LatestVersion
}
}

private string _latestBuild;

public string LatestBuild
{
get => $"Latest build: {_latestBuild}";
set
{
this.RaiseAndSetIfChanged(ref _latestBuild, value);
this.RaisePropertyChanged(nameof(IsNewBuild));
}
}

public bool IsNewVersion
{
get
Expand All @@ -107,16 +83,6 @@ public bool IsNewVersion
}
}

public bool IsNewBuild
{
get
{
var current = new Version($"{_currentVersion}.0");
var last = new Version($"{_latestVersion}.0");
return current.CompareTo(last) < 0;
}
}

public string Message
{
get => message[IsNewVersion ? 1 : 0];
Expand All @@ -131,7 +97,6 @@ public string Message

public ReactiveCommand<Unit, Unit> DiscordCommand { get; }
public ReactiveCommand<Unit, Unit> LatestVersionCommand { get; }
public ReactiveCommand<Unit, Unit> LatestBuildCommand { get; }
public ReactiveCommand<Unit, Unit> CloseCommand { get; }

public event Action CloseWindow;
Expand Down
8 changes: 0 additions & 8 deletions WPFUI/Views/VersionWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
Expand All @@ -31,15 +30,8 @@
<Border x:Name="LastVersionBorder" BorderBrush="Black" BorderThickness="1" Grid.Column="1" Margin="20,10,20,0" Grid.Row="2">
<TextBlock x:Name="LastVersionLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" />
</Border>
<Border x:Name="LastBuildBorder" BorderBrush="Black" BorderThickness="1" Grid.Column="2" Margin="20,10,20,0" Grid.Row="2">
<TextBlock x:Name="LastBuildLabel" HorizontalAlignment="Center" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Center" />
</Border>
<Border x:Name="NoteBorder" BorderBrush="Black" BorderThickness="1" Grid.ColumnSpan="3" Margin="20,5,20,5" Grid.Row="3">
<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" />
</Border>
<Button x:Name="DiscordButton" Content="Discord" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
<Button x:Name="LastVersionButton" Grid.Column="1" Content="Download latest version" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
<Button x:Name="LastBuildButton" Grid.Column="2" Content="Download latest build" HorizontalAlignment="Stretch" Margin="20,0,20,0" Grid.Row="1" VerticalAlignment="Stretch" />
<Button x:Name="CloseButton" Content="Close" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" Margin="20,0,20,10" Grid.Row="4" VerticalAlignment="Stretch" />
</Grid>
</reactiveui:ReactiveWindow>
2 changes: 0 additions & 2 deletions WPFUI/Views/VersionWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public VersionWindow()
{
this.BindCommand(ViewModel, vm => vm.DiscordCommand, v => v.DiscordButton).DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.LatestVersionCommand, v => v.LastVersionButton).DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.LatestBuildCommand, v => v.LastBuildButton).DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.CloseCommand, v => v.CloseButton).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.Message, v => v.StatusLabel.Text).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.CurrentVersion, v => v.CurrentLabel.Text).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.LatestVersion, v => v.LastVersionLabel.Text).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.LatestBuild, v => v.LastBuildLabel.Text).DisposeWith(d);
});
}
}
Expand Down

0 comments on commit 9dc927e

Please sign in to comment.