Keeps the repo root clean - only README.md visible on landing page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
108 lines
4.8 KiB
C#
108 lines
4.8 KiB
C#
/// @name [*] MarketSales Bot
|
|
(int Average, List < (int price, int daysAgo, int volume) > Prices) GetRealAverage(Xabbo.Core.GameData.FurniInfo finditem) {
|
|
var mpInfo = GetMarketplaceInfo(finditem).TradeInfo;
|
|
int total = 0;
|
|
List < (int, int, int) > prices = new List < (int, int, int) > {};
|
|
foreach(var info in mpInfo) {
|
|
total += info.AverageSalePrice;
|
|
prices.Add((info.AverageSalePrice, info.DayOffset, info.TradeVolume));
|
|
}
|
|
int average = mpInfo.Count != 0 ? total / mpInfo.Count : -1;
|
|
return (average, prices);
|
|
}
|
|
|
|
|
|
void SendVisibleMessage(int userId, string message) {
|
|
Delay(DelayTime());
|
|
SendMessage(userId, message);
|
|
Send(In.MessengerNewConsoleMessage, userId, "> " + message, 0, "");
|
|
}
|
|
|
|
|
|
Queue<(int messenger, string message)> messageQueue = new Queue<(int messenger, string message)>();
|
|
bool isProcessing = false;
|
|
|
|
int DelayTime() {
|
|
return Rand(500, 1000);
|
|
}
|
|
|
|
void ProcessQueue() {
|
|
if (messageQueue.Count > 0 && !isProcessing) {
|
|
isProcessing = true;
|
|
var msgq = messageQueue.Dequeue();
|
|
int messenger = msgq.messenger;
|
|
var message = msgq.message;
|
|
if (message == "pc") {
|
|
string NoFurniReply = $"Woopsie, you forgot to give me a furni, please refer to this example: 'pc holoboy'";
|
|
SendVisibleMessage(messenger, NoFurniReply);
|
|
} else if (message.StartsWith("pc")) {
|
|
var furnidata = FurniData.FindItem(message[3..]);
|
|
Log($"{Friends.Where(x => x.Id == messenger).FirstOrDefault().Name}: {message[3..]}");
|
|
if(furnidata == null) {
|
|
string FurniNotFoundReply = $"Sadly I could not find the item you are looking for :(";
|
|
SendVisibleMessage(messenger, FurniNotFoundReply);
|
|
} else {
|
|
(int average,var prices) = GetRealAverage(furnidata);
|
|
if (average == -1) {
|
|
string noneFoundReply = $"Sadly {furnidata.Name} has had no sales in the last 30 days :(";
|
|
SendVisibleMessage(messenger, noneFoundReply);
|
|
} else {
|
|
string greetingReply = $"Here are {furnidata.Name}'s most recent average sales:";
|
|
SendVisibleMessage(messenger, greetingReply);
|
|
foreach(var priceDate in prices.TakeLast(7)) {
|
|
int daysAgo = Math.Abs(priceDate.daysAgo);
|
|
string priceReply = $"Sold {priceDate.volume} {(priceDate.volume == 1 ? "time" : "times")} {daysAgo} {(daysAgo == 1 ? "day" : "days")} ago for {priceDate.price}c";
|
|
SendVisibleMessage(messenger, priceReply);
|
|
}
|
|
string averageReply = $"The average over the last 30 days is: {average}c";
|
|
SendVisibleMessage(messenger, averageReply);
|
|
}
|
|
}
|
|
} else if (message == "help") {
|
|
SendVisibleMessage(messenger, $"(?) How to use examples correctly");
|
|
SendVisibleMessage(messenger, $"'pc furni name'" );
|
|
string extraInfo = $"/!\\ To avoid misunderstanding only check unique items (example no plasto) and be as accurate to the name as possible";
|
|
SendVisibleMessage(messenger, extraInfo);
|
|
SendVisibleMessage(messenger, $"• 'pc Silver Dragon Lamp'");
|
|
SendVisibleMessage(messenger, $"• 'pC GoldeN dRAGOn'" );
|
|
SendVisibleMessage(messenger, $"• 'pc bronze drag'" );
|
|
SendVisibleMessage(messenger, $"÷ 'pc plastic pod chair' you can't specify color");
|
|
SendVisibleMessage(messenger, $"÷ 'pc golden' incomplete" );
|
|
SendVisibleMessage(messenger, $"÷ 'pc infobus' old posters not possible" );
|
|
} else if (message == "--FRIEND ADDED--") {
|
|
string welcomeMessage = $"Welcome {Friends.Where(x => x.Id == messenger).FirstOrDefault().Name} to Marketplace Sales & Price Checker!";
|
|
SendVisibleMessage(messenger, welcomeMessage);
|
|
string instructionsMessage = $"To get started, simply type 'pc' followed by the name of the furni you want to check (e.g. 'pc hologirl').";
|
|
SendVisibleMessage(messenger, instructionsMessage);
|
|
string ExtraHelpMessage = $"To stay up to date write help to get usage info and possibly new commands in the future";
|
|
SendVisibleMessage(messenger, ExtraHelpMessage);
|
|
string extraInfo = $"/!\\ To avoid misunderstanding only check unique items (example no plasto) and be as accurate to the name as possible";
|
|
SendVisibleMessage(messenger, extraInfo);
|
|
}
|
|
isProcessing = false;
|
|
}
|
|
}
|
|
|
|
OnIntercept(In.MessengerNewConsoleMessage, p => {
|
|
var messenger = p.Packet.ReadInt();
|
|
var message = p.Packet.ReadString();
|
|
RunTask(() => {
|
|
messageQueue.Enqueue((messenger,message));
|
|
ProcessQueue();
|
|
});
|
|
});
|
|
|
|
OnIntercept(In["NewFriendRequest"], p => {
|
|
int userId = p.Packet.ReadInt();
|
|
string userName = p.Packet.ReadString();
|
|
AcceptFriendRequest(userId);
|
|
Log($"{userName} added");
|
|
Delay(DelayTime()*10);
|
|
string welcomeMessage = $"--FRIEND ADDED--";
|
|
messageQueue.Enqueue((userId, welcomeMessage));
|
|
});
|
|
|
|
while (true) {
|
|
ProcessQueue();
|
|
Delay(DelayTime());
|
|
} |