Skip to content

Commit

Permalink
create service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekwav committed Dec 17, 2021
1 parent 379be82 commit 18a363f
Show file tree
Hide file tree
Showing 38 changed files with 1,547 additions and 158 deletions.
10 changes: 5 additions & 5 deletions Client/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ VERSION=0.0.1
docker run --rm -v "${PWD}:/local" --network host -u $(id -u ${USER}):$(id -g ${USER}) openapitools/openapi-generator-cli generate \
-i http://localhost:5000/swagger/v1/swagger.json \
-g csharp-netcore \
-o /local/out --additional-properties=packageName=Coflnet.Sky.Base.Client,packageVersion=$VERSION,licenseId=MIT
-o /local/out --additional-properties=packageName=Coflnet.Sky.ModCommands.Client,packageVersion=$VERSION,licenseId=MIT

cd out
sed -i 's/GIT_USER_ID/Coflnet/g' src/Coflnet.Sky.Base.Client/Coflnet.Sky.Base.Client.csproj
sed -i 's/GIT_REPO_ID/SkyBase/g' src/Coflnet.Sky.Base.Client/Coflnet.Sky.Base.Client.csproj
sed -i 's/>OpenAPI/>Coflnet/g' src/Coflnet.Sky.Base.Client/Coflnet.Sky.Base.Client.csproj
sed -i 's/GIT_USER_ID/Coflnet/g' src/Coflnet.Sky.ModCommands.Client/Coflnet.Sky.ModCommands.Client.csproj
sed -i 's/GIT_REPO_ID/SkyModCommands/g' src/Coflnet.Sky.ModCommands.Client/Coflnet.Sky.ModCommands.Client.csproj
sed -i 's/>OpenAPI/>Coflnet/g' src/Coflnet.Sky.ModCommands.Client/Coflnet.Sky.ModCommands.Client.csproj

dotnet pack
cp src/Coflnet.Sky.Base.Client/bin/Debug/Coflnet.Sky.Base.Client.*.nupkg ..
cp src/Coflnet.Sky.ModCommands.Client/bin/Debug/Coflnet.Sky.ModCommands.Client.*.nupkg ..
21 changes: 21 additions & 0 deletions Commands/ChatPart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Coflnet.Sky.Commands.MC
{
public class ChatPart
{
public string text;
public string onClick;
public string hover;

public ChatPart()
{
}

public ChatPart(string text, string onClick = null, string hover = null)
{
this.text = text;
this.onClick = onClick;
this.hover = hover;
}

}
}
42 changes: 42 additions & 0 deletions Commands/FirstModVersionAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Linq;
using System.Threading.Tasks;
using hypixel;

namespace Coflnet.Sky.Commands.MC
{
public class FirstModVersionAdapter : IModVersionAdapter
{
MinecraftSocket socket;

public FirstModVersionAdapter(MinecraftSocket socket)
{
this.socket = socket;
SendUpdateMessage();
}

private void SendUpdateMessage()
{
socket.SendMessage(MinecraftSocket.COFLNET + McColorCodes.RED + "There is a newer mod version. click this to open discord and download it", "https://discord.com/channels/267680588666896385/890682907889373257/898974585318416395");
}

public Task<bool> SendFlip(FlipInstance flip)
{
socket.SendMessage(socket.GetFlipMsg(flip), "/viewauction " + flip.Auction.Uuid, "UPDATE");
SendUpdateMessage();
return Task.FromResult(true);
}

public void SendMessage(params ChatPart[] parts)
{
var part = parts.FirstOrDefault();
socket.SendMessage(part.text, part.onClick, part.hover);
SendUpdateMessage();
}

public void SendSound(string name, float pitch = 1f)
{
// no support
SendUpdateMessage();
}
}
}
12 changes: 12 additions & 0 deletions Commands/IModVersionAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;
using hypixel;

namespace Coflnet.Sky.Commands.MC
{
public interface IModVersionAdapter
{
Task<bool> SendFlip(FlipInstance flip);
void SendSound(string name, float pitch = 1);
void SendMessage(params ChatPart[] parts);
}
}
21 changes: 21 additions & 0 deletions Commands/Minecraft/BlacklistCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading.Tasks;
using Coflnet.Sky.Commands.Shared;

namespace Coflnet.Sky.Commands.MC
{
public class BlacklistCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
var tag = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(arguments);
await socket.UpdateSettings(settings =>
{
if (settings.Settings.BlackList == null)
settings.Settings.BlackList = new System.Collections.Generic.List<ListEntry>();
settings.Settings.BlackList.Add(new ListEntry() { ItemTag = tag });
return settings;
});
socket.SendMessage(COFLNET + $"You blacklisted all {arguments} from appearing");
}
}
}
28 changes: 28 additions & 0 deletions Commands/Minecraft/BlockedCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Linq;
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class BlockedCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
if (socket.TopBlocked.Count == 0)
{
socket.SendMessage(COFLNET + "No blocked flips found, make sure you don't click this shortly after the 'flips in 10 seconds' message. (the list gets reset when that message appears)");
return;
}
var r = new Random();
socket.SendMessage(socket.TopBlocked.OrderBy(e=>r.Next()).Take(5).Select(b =>
{
socket.Settings.GetPrice(hypixel.FlipperService.LowPriceToFlip(b.Flip), out long targetPrice, out long profit);
return new ChatPart(
$"{b.Flip.Auction.ItemName} (+{socket.FormatPrice(profit)}) got blocked because {b.Reason.Replace("SNIPER", "experimental flip finder")}\n",
"https://sky.coflnet.com/auction/" + b.Flip.Auction.Uuid,
"Click to open");
})
.Append(new ChatPart() { text = COFLNET + "These are random examples of blocked flips.", onClick = "/cofl blocked", hover = "Execute again to get another sample" }).ToArray());
}
}
}
12 changes: 12 additions & 0 deletions Commands/Minecraft/ClickedCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class ClickedCommand : McCommand
{
public override Task Execute(MinecraftSocket socket, string arguments)
{
return Task.CompletedTask;
}
}
}
17 changes: 17 additions & 0 deletions Commands/Minecraft/ExactCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class ExactCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
await socket.UpdateSettings(settings =>
{
settings.Settings.AllowedFinders = LowPricedAuction.FinderType.SNIPER | LowPricedAuction.FinderType.SNIPER_MEDIAN;
return settings;
});
socket.SendMessage(COFLNET + $"You enabled the exact flip mode, this is experimental");
}
}
}
19 changes: 19 additions & 0 deletions Commands/Minecraft/ExperimentalCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class ExperimentalCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
await socket.UpdateSettings(settings =>
{
settings.Settings.AllowedFinders = LowPricedAuction.FinderType.FLIPPER | LowPricedAuction.FinderType.SNIPER_MEDIAN | LowPricedAuction.FinderType.SNIPER;
return settings;
});
socket.SendMessage(COFLNET + $"You opted in into experimental flips");
}
}


}
11 changes: 11 additions & 0 deletions Commands/Minecraft/McCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public abstract class McCommand
{
public string COFLNET => MinecraftSocket.COFLNET;
public static string DEFAULT_COLOR => McColorCodes.GRAY;
public abstract Task Execute(MinecraftSocket socket, string arguments);
}
}
17 changes: 17 additions & 0 deletions Commands/Minecraft/NormalCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class NormalCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
await socket.UpdateSettings(settings =>
{
settings.Settings.AllowedFinders = LowPricedAuction.FinderType.FLIPPER;
return settings;
});
socket.SendMessage(COFLNET + $"You went back to normal flipper mode again");
}
}
}
13 changes: 13 additions & 0 deletions Commands/Minecraft/OnlineCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class OnlineCommand : McCommand
{
public override Task Execute(MinecraftSocket socket, string arguments)
{
socket.SendMessage(COFLNET + $"There are {hypixel.FlipperService.Instance.PremiumUserCount} users connected to this server");
return Task.CompletedTask;
}
}
}
12 changes: 12 additions & 0 deletions Commands/Minecraft/PurchaseConfirmCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class PurchaseConfirmCommand : McCommand
{
public override Task Execute(MinecraftSocket socket, string arguments)
{
return Task.CompletedTask;
}
}
}
12 changes: 12 additions & 0 deletions Commands/Minecraft/PurchaseStartCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace Coflnet.Sky.Commands.MC
{
public class PurchaseStartCommand : McCommand
{
public override Task Execute(MinecraftSocket socket, string arguments)
{
return Task.CompletedTask;
}
}
}
62 changes: 62 additions & 0 deletions Commands/Minecraft/RateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using hypixel;
using Coflnet.Sky.Commands.Shared;

namespace Coflnet.Sky.Commands.MC
{
public class RateCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
var args = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(arguments).Split(" ");
var uuid = args[0];
var finder = args[1];
var rating = args[2];
using var span = socket.tracer.BuildSpan("vote").WithTag("type", rating).WithTag("finder", finder).WithTag("uuid", uuid).AsChildOf(socket.ConSpan).StartActive();
var bad = socket.GetFlip(uuid);
span.Span.Log(JSON.Stringify(bad));
span.Span.Log(JSON.Stringify(bad?.AdditionalProps));


if (rating == "down")
{
if(bad != null)
Blacklist(socket, bad);
socket.SendMessage(new ChatPart(COFLNET + "Thanks for your feedback, Please help us better understand why this flip is bad\n", null, "you can also send free text with /cofl report"),
new ChatPart(" * Its overpriced\n", "/cofl report overpriced "),
new ChatPart(" * This item sells slowly\n", "/cofl report slow sell"),
new ChatPart(" * I blacklisted this before\n", "/cofl report blacklist broken"),
new ChatPart(" * This item is manipulated\n", "/cofl report manipulated item"),
new ChatPart(" * Reference auctions are wrong \n", "/cofl report reference auctions are wrong ", "please send /cofl report with further information"));
await FlipTrackingService.Instance.DownVote(uuid, socket.McUuid);
}
else if (rating == "up")
{
socket.SendMessage(new ChatPart(COFLNET + "Thanks for your feedback, Please help us better understand why this flip is good\n"),
new ChatPart(" * it isn't I mis-clicked \n", "/cofl report misclicked "),
new ChatPart(" * This item sells fast\n", "/cofl report fast sell"),
new ChatPart(" * High profit\n", "/cofl report high profit"),
new ChatPart(" * Something else \n", null, "please send /cofl report with further information"));
await FlipTrackingService.Instance.UpVote(uuid, socket.McUuid);
}
else
{
socket.SendMessage(COFLNET + $"Thanks for your feedback, you voted this flip " + rating, "/cofl undo", "We will try to improve the flips accordingly");
}
await Task.Delay(3000);
var based = await hypixel.CoreServer.ExecuteCommandWithCache<string, IEnumerable<BasedOnCommandResponse>>("flipBased", uuid);
span.Span.Log(string.Join('\n', based.Select(b => $"{b.ItemName} {b.highestBid} {b.uuid}")));
}

private static void Blacklist(MinecraftSocket socket, LowPricedAuction bad)
{
if (socket.Settings.BlackList == null)
socket.Settings.BlackList = new System.Collections.Generic.List<ListEntry>();
socket.Settings.BlackList.Add(new ListEntry() { ItemTag = bad.Auction.Tag });
}
}


}
49 changes: 49 additions & 0 deletions Commands/Minecraft/ReferenceCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coflnet.Sky.Commands.Shared;
using hypixel;

namespace Coflnet.Sky.Commands.MC
{
public class ReferenceCommand : McCommand
{
public override async Task Execute(MinecraftSocket socket, string arguments)
{
Console.WriteLine(arguments);
var uuid = arguments.Trim('"');
var flip = socket.GetFlip(uuid);
if (flip.Finder.HasFlag(LowPricedAuction.FinderType.SNIPER))
{
await SniperReference(socket, uuid, flip, "sniping");
return;
}
if (flip.Finder.HasFlag(LowPricedAuction.FinderType.SNIPER_MEDIAN))
{
await SniperReference(socket, uuid, flip, "median sniper");
return;
}
socket.ModAdapter.SendMessage(new ChatPart("Caclulating references", "https://sky.coflnet.com/auction/" + uuid, "please give it a second"));
var based = await CoreServer.ExecuteCommandWithCache<string, IEnumerable<BasedOnCommandResponse>>("flipBased", uuid);
socket.ModAdapter.SendMessage(based
.Select(b => new ChatPart(
$"\n-> {b.ItemName} for {McColorCodes.AQUA}{socket.FormatPrice(b.highestBid)}{McColorCodes.GRAY} {b.end}",
"https://sky.coflnet.com/auction/" + b.uuid,
"Click to open this auction"))
.ToArray());
await Task.Delay(200);
socket.ModAdapter.SendMessage(new ChatPart(MinecraftSocket.COFLNET + "click this to open the auction on the website (in case you want to report an error or share it)", "https://sky.coflnet.com/auction/" + uuid, "please give it a second"));
}

private async Task SniperReference(MinecraftSocket socket, string uuid, LowPricedAuction flip, string algo)
{
var reference = await AuctionService.Instance.GetAuctionAsync(flip.AdditionalProps["reference"]);
Console.WriteLine(JSON.Stringify(flip.AdditionalProps));
Console.WriteLine(JSON.Stringify(reference));
socket.ModAdapter.SendMessage(new ChatPart($"{COFLNET}This flip was found by the {algo} algorithm\n", "https://sky.coflnet.com/auction/" + uuid, "click this to open the flip on website"),
new ChatPart($"It was compared to {McColorCodes.AQUA} this auction {DEFAULT_COLOR}, open ah", $"/viewauction {reference.Uuid}", McColorCodes.GREEN + "open it on ah"),
new ChatPart($"{McColorCodes.WHITE} open on website", $"https://sky.coflnet.com/auction/{reference.Uuid}", "open it on website"));
}
}
}
Loading

0 comments on commit 18a363f

Please sign in to comment.