Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions TBot.Common/Logging/LogSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum LogSender {
BuyOfferOfTheDay,
LifeformsAutoMine,
LifeformsAutoResearch,
AutoFleepJumpGate,
//End Brain Features
Expeditions,
Harvest,
Expand Down
1 change: 1 addition & 0 deletions TBot.Ogame.Infrastructure/Enums/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum Feature {
BrainLifeformAutoResearch = 13,
AutoDiscovery = 14,
BrainAutobuildDefence = 15,
BrainAutoFleepJumpGate = 16,

BrainCelestialAutoMine = 101,
BrainCelestialLifeformAutoMine = 102,
Expand Down
1 change: 1 addition & 0 deletions TBot.Ogame.Infrastructure/Enums/Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class Features {
Feature.BrainLifeformAutoResearch,
Feature.BrainOfferOfTheDay,
Feature.BrainAutoResearch,
Feature.BrainAutoFleepJumpGate,
Feature.AutoFarm,
Feature.Expeditions,
Feature.AutoDiscovery,
Expand Down
2 changes: 1 addition & 1 deletion TBot.Ogame.Infrastructure/IOgameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void Initialize(Credentials credentials,
bool IsPortAvailable(string host, int port = 8080);
Task<bool> IsUnderAttack();
Task<bool> IsVacationMode();
Task JumpGate(Celestial origin, Celestial destination, Ships ships);
Task<JumpGateResult> JumpGate(Celestial origin, Celestial destination, Ships ships);
Task<bool> SendDiscovery(Celestial origin, Coordinate coords);
void KillOgamedExecutable(CancellationToken ct = default);
Task Login();
Expand Down
16 changes: 16 additions & 0 deletions TBot.Ogame.Infrastructure/Models/JumpGateResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace TBot.Ogame.Infrastructure.Models
{
public class JumpGateResult
{
[JsonProperty("success")]
public bool Success { get; set; }

[JsonProperty("rechargeCountdown")]
public long RechargeCountdown { get; set; }

[JsonIgnore]
public string Error { get; set; }
}
}
16 changes: 13 additions & 3 deletions TBot.Ogame.Infrastructure/OgameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public async Task<EspionageReport> GetEspionageReport(int msgId) {
return await GetAsync<EspionageReport>($"/bot/espionage-report/{msgId}");
}

public async Task JumpGate(Celestial origin, Celestial destination, Ships ships) {
public async Task<JumpGateResult> JumpGate(Celestial origin, Celestial destination, Ships ships) {
List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();

parameters.Add(new KeyValuePair<string, string>("moonDestination", destination.ID.ToString()));
Expand All @@ -698,12 +698,22 @@ public async Task JumpGate(Celestial origin, Celestial destination, Ships ships)
long qty = (long) prop.GetValue(ships, null);
if (qty == 0)
continue;
if (Enum.TryParse<Buildables>(prop.Name, out Buildables buildable)) {

if (Enum.TryParse(prop.Name, out Buildables buildable)) {
parameters.Add(new KeyValuePair<string, string>("ships", $"{(int) buildable},{prop.GetValue(ships, null)}"));
}
}

await PostAsync<object>($"/bot/moons/{origin.ID}/jump-gate", parameters.ToArray());
try {
var result = await PostAsync<JumpGateResult>($"/bot/moons/{origin.ID}/jump-gate", parameters.ToArray());
return result;
} catch (HttpRequestException ex) {
return new JumpGateResult { Success = false, RechargeCountdown = 0, Error = ex.Message };
} catch (OgamedException ex) {
return new JumpGateResult { Success = false, RechargeCountdown = 0, Error = ex.Message };
} catch (Exception ex) {
return new JumpGateResult { Success = false, RechargeCountdown = 0, Error = ex.Message };
}
}

public async Task<List<Fleet>> Phalanx(Celestial origin, Coordinate coords) {
Expand Down
23 changes: 17 additions & 6 deletions TBot/Services/TBotMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public IFleetScheduler FleetScheduler {
return _fleetScheduler;
}
}
public IWorkerFactory WorkerFactory {
get {
return _workerFactory;
}
}

public long SleepDuration { get; set; }
public DateTime NextWakeUpTime { get; set; }

Expand Down Expand Up @@ -264,7 +270,7 @@ public async Task Init(string settingPath,
await Task.Delay(RandomizeHelper.CalcRandomInterval(IntervalType.AFewSeconds));

loggedIn = true;
log(LogLevel.Information, LogSender.Tbot, "Logged in!");
log(LogLevel.Information, LogSender.Tbot, "Logged in!");

await InitUserData();

Expand Down Expand Up @@ -551,7 +557,7 @@ private async void OnSettingsChanged() {
finally {
_settingsReloadSemaphore.Release();
}

}

private void InitializeSleepMode() {
Expand Down Expand Up @@ -639,7 +645,7 @@ public async Task TelegramBuild(Buildables buildable, decimal num = 0) {
return;
}

public async Task TelegramGetCurrentAuction() {
public async Task TelegramGetCurrentAuction() {
Auction auction;
try {
auction = await _ogameService.GetCurrentAuction();
Expand Down Expand Up @@ -920,10 +926,15 @@ public async Task TelegramJumpGate(Celestial origin, Coordinate destination, str
}
}
try {
await _ogameService.JumpGate(origin, moondest, ships);
await SendTelegramMessage($"JumGate Done!");
var jg = await _ogameService.JumpGate(origin, moondest, ships);
if (jg.Success) {
await SendTelegramMessage($"JumpGate done. Cooldown: {jg.RechargeCountdown}s");
} else {
var msg = !string.IsNullOrWhiteSpace(jg.Error) ? jg.Error : $"cooldown {jg.RechargeCountdown}s";
await SendTelegramMessage($"JumpGate failed: {msg}");
}
} catch (Exception ex) {
await SendTelegramMessage($"JumGate Failed! Error: {ex.Message}");
await SendTelegramMessage($"JumpGate Failed! Error: {ex.Message}");
}
}

Expand Down
33 changes: 29 additions & 4 deletions TBot/Services/TelegramMessenger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Serilog.Events;
using Telegram.Bot.Types.ReplyMarkups;
using Tbot.Workers;
using Tbot.Workers.Brain;

namespace Tbot.Services {

Expand Down Expand Up @@ -276,7 +277,8 @@ public async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
"/stopautofarm",
"/startautofarm",
"/stopautodiscovery",
"/startautodiscovery"
"/startautodiscovery",
"/fleetjumpgate"
};

if (update.Type != UpdateType.Message) {
Expand Down Expand Up @@ -352,14 +354,14 @@ await SendMessage(botClient, message.Chat, $"Selected index \"{args.ElementAt(1)
else {
await SendMessage(botClient, message.Chat, "Telegram Logger is disabled.");
}

return;
case "/setloglevel":
if (args.Length != 2) {
await SendMessage(botClient, message.Chat, "Usage is <code>/setloglevel Debug|Information|Warning|Error</code>");
return;
}

if (Enum.TryParse<LogEventLevel>(args[1], true, out LogEventLevel newLevel) == true) {
await SendMessage(botClient, message.Chat, $"Enabling Telegram logger with level {newLevel.ToString()}");
_logger.AddTelegramLogger(Api, Channel);
Expand Down Expand Up @@ -455,7 +457,8 @@ await SendMessage(botClient, message.Chat,
"/stopautofarm - stop autofarm\n" +
"/startautofarm - start autofarm\n" +
"/stopautodiscovery - stop autodiscovery\n" +
"/startautodiscovery - start autodiscovery\n"
"/startautodiscovery - start autodiscovery\n" +
"/fleetjumpgate - run jump gate worker immediately\n"
, ParseMode.Html);
return;
default:
Expand Down Expand Up @@ -1097,6 +1100,28 @@ await SendMessage(botClient, message.Chat,
await SendMessage(botClient, message.Chat, "Autodiscovery started!");
return;

case "/fleetjumpgate":
if (args.Length != 1) {
await SendMessage(botClient, message.Chat, "No arguments accepted with this command!");
return;
}

AutoFleetJumpGateWorker worker = (AutoFleetJumpGateWorker) currInstance.WorkerFactory.GetWorker(Feature.BrainAutoFleepJumpGate);

if (worker == null) {
await SendMessage(botClient, message.Chat, "JumpGate worker not available.");
return;
}

await SendMessage(botClient, message.Chat, "Running JumpGate worker now...");
try {
await worker.RunFromTelegramAsync();
await SendMessage(botClient, message.Chat, "JumpGate worker completed.");
} catch (Exception ex) {
await SendMessage(botClient, message.Chat, $"Error during JumpGate execution: {ex.Message}");
}
return;


case "/getinfo":
args = message.Text.Split(' ');
Expand Down
Loading