Skip to content

Commit

Permalink
Fix mods and change formatting for !rs
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed Sep 30, 2023
1 parent a823002 commit d7723d1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
49 changes: 49 additions & 0 deletions BanchoMultiplayerBot/Extensions/ApiModsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Text;
using BanchoMultiplayerBot.OsuApi;
using BanchoSharp.Multiplayer;

namespace BanchoMultiplayerBot.Extensions;

public static class ApiModsExtensions
{
public static string ToAbbreviatedForm(this ModsModel mods, bool showFreemod = true)
{
var ret = new StringBuilder(16);

// Just going to keep appending to this string, to get everything
// in the "right" order. This might not be the cleanest solution,
// but I can't think of anything better right now.

if ((mods & ModsModel.Relax) != 0)
ret.Append("RX");
if ((mods & ModsModel.Relax2) != 0)
ret.Append("AP");
if ((mods & ModsModel.SpunOut) != 0)
ret.Append("SO");
if ((mods & ModsModel.Easy) != 0)
ret.Append("EZ");
if ((mods & ModsModel.NoFail) != 0)
ret.Append("NF");
if ((mods & ModsModel.Hidden) != 0)
ret.Append("HD");
if ((mods & ModsModel.HalfTime) != 0)
ret.Append("HT");
if ((mods & ModsModel.DoubleTime) != 0)
ret.Append("DT");
if ((mods & ModsModel.Nightcore) != 0)
ret.Append("NC");
if ((mods & ModsModel.HardRock) != 0)
ret.Append("HR");
if ((mods & ModsModel.SuddenDeath) != 0)
ret.Append("SD");
if ((mods & ModsModel.Perfect) != 0)
ret.Append("PF");
if ((mods & ModsModel.Flashlight) != 0)
ret.Append("FL");

if (ret.Length == 0)
ret.Append("None");

return ret.ToString();
}
}
24 changes: 15 additions & 9 deletions BanchoMultiplayerBot/GlobalCommands.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Globalization;
using System.Text;
using BanchoMultiplayerBot.Extensions;
using BanchoMultiplayerBot.OsuApi;
using BanchoSharp.Interfaces;
using BanchoSharp.Multiplayer;
using Serilog;
Expand Down Expand Up @@ -72,23 +73,28 @@ private async void OnPrivateMessageReceived(IPrivateIrcMessage msg)

var response = new StringBuilder();

response.Append($"Recent score for {msg.Sender}: {ppInformation.PerformancePoints} pp ");
response.Append($"Recent score for {msg.Sender}: ");

if (recentScore.Perfect != "1")
response.Append(
$"[https://osu.ppy.sh/b/{beatmapInformation.BeatmapId} {beatmapInformation.Artist} - {beatmapInformation.Title} [{beatmapInformation.Version ?? string.Empty}]]");

if (recentScore.EnabledMods != "0")
{
response.Append($"({ppInformation.MaximumPerformancePoints} pp if FC) ");
response.Append($" + {((ModsModel)int.Parse(recentScore.EnabledMods!)).ToAbbreviatedForm()}");
}

response.Append($"| {acc:0.00}% | ");

response.Append($"x{recentScore.Maxcombo}/{beatmapInformation.MaxCombo} | {recentScore.Count300}/{recentScore.Count100}/{recentScore.Count50}/{recentScore.Countmiss}");
response.Append($" | {recentScore.Rank}");

response.Append($" | [https://osu.ppy.sh/b/{beatmapInformation.BeatmapId} {beatmapInformation.Artist} - {beatmapInformation.Title} [{beatmapInformation.Version ?? string.Empty}]] ");
response.Append($" | {ppInformation.PerformancePoints} pp ");

if (recentScore.EnabledMods != "0")
if (recentScore.Perfect != "1" && ppInformation.MaximumPerformancePoints != ppInformation.PerformancePoints)
{
response.Append($" + {((Mods)int.Parse(recentScore.EnabledMods!)).ToAbbreviatedForm()}");
response.Append($"({ppInformation.MaximumPerformancePoints} pp if FC) ");
}

response.Append($"| {acc:0.00}% | ");

response.Append($"x{recentScore.Maxcombo}/{beatmapInformation.MaxCombo} | {recentScore.Count300}/{recentScore.Count100}/{recentScore.Count50}/{recentScore.Countmiss}");

_bot.SendMessage(msg.IsDirect ? msg.Sender : msg.Recipient, response.ToString());
}
Expand Down

0 comments on commit d7723d1

Please sign in to comment.