Compare commits

...

20 Commits
4.3.2 ... 4.3.3

Author SHA1 Message Date
Kwoth
8d3f2f186a Merge branch 'v4' of https://gitlab.com/kwoth/nadekobot into v4 2022-08-06 17:57:32 +02:00
Kwoth
9572b9dc43 Updated changelog.md 2022-08-06 17:56:53 +02:00
Kwoth
ca32086089 Updated changelog.md 2022-08-06 17:56:14 +02:00
Kwoth
57f839dbcd Added client id as a potential fix for VoiceXp 'bug'. The solution may be to use different redis instances for each bot, or to switch from botCache: from 'redis' to 'memory' in creds.yml 2022-08-06 17:47:24 +02:00
Kwoth
71d6eeb9dd Possibly fixed #375 trivia bug 2022-08-06 17:28:31 +02:00
Kwoth
8c51cf8537 Added .xpshopbuy and .xpshopuse convenience commands 2022-08-06 13:26:41 +02:00
Kwoth
b683026cf3 Owner should also be able to buy items from the xp shop 2022-08-01 21:14:28 +02:00
Kwoth
bca2bc5af1 Fixed awarded amount position on the xp card 2022-08-01 20:59:35 +02:00
Kwoth
b385a83bdd Updated position of the username and club in the .xp image 2022-08-01 17:46:41 +02:00
Kwoth
3bf0286c81 Feature limit should have IsPatronLimit enabled 2022-08-01 16:08:23 +02:00
Kwoth
98272f66e7 Made improvements to the XP card text visibility with other backgrounds 2022-08-01 12:01:01 +02:00
Kwoth
cf3788c6ea Added an optional preview url to the xp shop items 2022-08-01 10:53:59 +02:00
Kwoth
4b3fc53cb6 Updated changelog 2022-07-31 21:31:29 +02:00
Kwoth
4e17dca856 Merge branch 'v4' of https://gitlab.com/kwoth/nadekobot into v4 2022-07-31 21:26:46 +02:00
Kwoth
82d89148f3 Added betroll bettest, fixed a bug which caused betroll to have very low payout 2022-07-31 21:26:34 +02:00
Kwoth
cc4c09b4d7 Merge branch 'hokutochen-v4-patch-85503' into 'v4'
updated redis requirement for release

See merge request Kwoth/nadekobot!262
2022-07-30 10:37:29 +00:00
Kwoth
616f01f8b2 Make sure broken youtube-dl didn't cache invalid data, closes #373 2022-07-30 10:29:33 +02:00
Hokuto Chen
56f89a02bc updated redis requirement for release 2022-07-30 07:32:30 +00:00
Kwoth
48ce988d20 Fixed a mistake in CHANGELOG.md 2022-07-29 19:53:45 +02:00
Kwoth
119b1cdec2 Changelog fixed 2022-07-29 18:38:54 +02:00
21 changed files with 297 additions and 174 deletions

View File

@@ -2,11 +2,29 @@
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
## [4.3.1] - 27.07.2022 ## Unreleased
## [4.3.3] - 06.08.2022
### Added
- Added `betroll` option to `.bettest` command
- Added `.xpshopbuy` and `.xpshopuse` convenience commands
- Added an optional preview url to teh xp shop item config model which will be shown instead of the real Url
### Changed ### Changed
- Check for updates will run once per hour as it was supposed to - Updated position of Username and Club name on the .xp card
- Improved text visibility on the .xp card
### Fixed
- Possibly fixed .trivia not stopping bug
- Fixed very low payout rate on `.betroll`
- Fixed an issue with youtube song resolver which caused invalid data to be cached
- Added client id to the cache key as a potential fix for VoiceXp 'bug'. The solution may be to use different redis instances for each bot, or to switch from botCache: from 'redis' to 'memory' in creds.yml
- Bot owner should now be able to buy items from the xpshop when patron requirement is set
- Fixed youtube-dl caching invalid data. Please use yt-dlp instead
## [4.3.2] - 28.07.2022 ## [4.3.2] - 28.07.2022
@@ -19,6 +37,12 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- Fixed `.bank withdraw <expression>` will now correctly use bank amount for calculation - Fixed `.bank withdraw <expression>` will now correctly use bank amount for calculation
- [dev] Fixed medusa Reply*LocalizedAsync not working with placeholders - [dev] Fixed medusa Reply*LocalizedAsync not working with placeholders
## [4.3.1] - 27.07.2022
### Changed
- Check for updates will run once per hour as it was supposed to
## [4.3.0] - 27.07.2022 ## [4.3.0] - 27.07.2022
### Added ### Added
@@ -32,9 +56,10 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- They payouts are very good, but seven always loses - They payouts are very good, but seven always loses
- Added `.lula` command. Plays the same as `.wof` but looks much nicer, and is easily customizable from gambling.yml without any changes to the sourcecode needed. - Added `.lula` command. Plays the same as `.wof` but looks much nicer, and is easily customizable from gambling.yml without any changes to the sourcecode needed.
- Added `.repeatskip` command which makes the next repeat trigger not post anything - Added `.repeatskip` command which makes the next repeat trigger not post anything
- Added `.imageonly` which will make the bot only allow link posts in the channel. Exclusive with `.imageonly` - Added `.linkonly` which will make the bot only allow link posts in the channel. Exclusive with `.imageonly`
- Added release notifications. Bot owners will now receive new release notifications in dms if they have `checkForUpdates` set to `true` in data/bot.yml - Added release notifications. Bot owners will now receive new release notifications in dms if they have `checkForUpdates` set to `true` in data/bot.yml
- You can also configure it via `.conf bot checkforupdates <true/false>` - You can also configure it via `.conf bot checkfor
- updates <true/false>`
- Added `.xpshop` which lets bot owners add xp backgrounds and xp frames for sale by configuring `data/xp.yml` - Added `.xpshop` which lets bot owners add xp backgrounds and xp frames for sale by configuring `data/xp.yml`
- You can also toggle xpshop feature via `.conf xp shop.is_enabled` - You can also toggle xpshop feature via `.conf xp shop.is_enabled`

View File

@@ -69,7 +69,7 @@ Open Terminal (if you're on an installation with a window manager) and navigate
###### Prerequisites ###### Prerequisites
1. Nadeko requires redis to function 1. (Optional) Installing Redis
- ubuntu installation command: `sudo apt-get install redis-server` - ubuntu installation command: `sudo apt-get install redis-server`
2. Playing music requires `ffmpeg`, `libopus`, `libsodium` and `youtube-dl` (which in turn requires python3) 2. Playing music requires `ffmpeg`, `libopus`, `libsodium` and `youtube-dl` (which in turn requires python3)
- ubuntu installation command: `sudo apt-get install ffmpeg libopus0 opus-tools libopus-dev libsodium-dev -y` - ubuntu installation command: `sudo apt-get install ffmpeg libopus0 opus-tools libopus-dev libsodium-dev -y`

View File

@@ -25,20 +25,6 @@ public class NadekoRandom : Random
_rng.GetBytes(bytes); _rng.GetBytes(bytes);
return Math.Abs(BitConverter.ToInt32(bytes, 0)) % maxValue; return Math.Abs(BitConverter.ToInt32(bytes, 0)) % maxValue;
} }
public byte Next(byte minValue, byte maxValue)
{
if (minValue > maxValue)
throw new ArgumentOutOfRangeException(nameof(maxValue));
if (minValue == maxValue)
return minValue;
var bytes = new byte[1];
_rng.GetBytes(bytes);
return (byte)((bytes[0] % (maxValue - minValue)) + minValue);
}
public override int Next(int minValue, int maxValue) public override int Next(int minValue, int maxValue)
{ {

View File

@@ -12,7 +12,7 @@ public sealed class BetflipGame
public BetflipResult Flip(byte guess, decimal amount) public BetflipResult Flip(byte guess, decimal amount)
{ {
var side = _rng.Next(0, 2); var side = (byte)_rng.Next(0, 2);
if (side == guess) if (side == guess)
{ {
return new BetflipResult() return new BetflipResult()

View File

@@ -13,7 +13,7 @@ public sealed class BetrollGame
public BetrollResult Roll(decimal amount = 0) public BetrollResult Roll(decimal amount = 0)
{ {
var roll = _rng.Next(0, 101); var roll = _rng.Next(1, 101);
for (var i = 0; i < _thresholdPairs.Length; i++) for (var i = 0; i < _thresholdPairs.Length; i++)
{ {

View File

@@ -8,9 +8,9 @@ public class SlotGame
{ {
var rolls = new[] var rolls = new[]
{ {
_rng.Next(0, 6), (byte)_rng.Next(0, 6),
_rng.Next(0, 6), (byte)_rng.Next(0, 6),
_rng.Next(0, 6) (byte)_rng.Next(0, 6)
}; };
ref var a = ref rolls[0]; ref var a = ref rolls[0];

View File

@@ -875,11 +875,12 @@ public partial class Gambling : GamblingModule<GamblingService>
public enum GambleTestTarget public enum GambleTestTarget
{ {
Slot, Slot,
Betroll,
Betflip,
BetflipT,
BetDraw, BetDraw,
BetDrawHL, BetDrawHL,
BetDrawRB, BetDrawRB,
Betflip,
BetflipT,
Lula, Lula,
Rps, Rps,
} }
@@ -920,6 +921,7 @@ public partial class Gambling : GamblingModule<GamblingService>
GambleTestTarget.BetflipT => (await _gs.BetFlipAsync(ctx.User.Id, 0, 1)).AsT0.Multiplier, GambleTestTarget.BetflipT => (await _gs.BetFlipAsync(ctx.User.Id, 0, 1)).AsT0.Multiplier,
GambleTestTarget.Lula => (await _gs.LulaAsync(ctx.User.Id, 0)).AsT0.Multiplier, GambleTestTarget.Lula => (await _gs.LulaAsync(ctx.User.Id, 0)).AsT0.Multiplier,
GambleTestTarget.Rps => (await _gs.RpsAsync(ctx.User.Id, 0, (byte)(i % 3))).AsT0.Multiplier, GambleTestTarget.Rps => (await _gs.RpsAsync(ctx.User.Id, 0, (byte)(i % 3))).AsT0.Multiplier,
GambleTestTarget.Betroll => (await _gs.BetRollAsync(ctx.User.Id, 0)).AsT0.Multiplier,
_ => throw new ArgumentOutOfRangeException(nameof(target)) _ => throw new ArgumentOutOfRangeException(nameof(target))
}; };

View File

@@ -57,123 +57,133 @@ public sealed class TriviaGame
// loop until game is stopped // loop until game is stopped
// each iteration is one round // each iteration is one round
var firstRun = true; var firstRun = true;
while (!_isStopped) try
{ {
if (errorCount >= 5) while (!_isStopped)
{ {
Log.Warning("Trivia errored 5 times and will quit"); if (errorCount >= 5)
break;
}
// wait for 3 seconds before posting the next question
if (firstRun)
{
firstRun = false;
}
else
{
await Task.Delay(3000);
}
var maybeQuestion = await _questionPool.GetQuestionAsync();
if(!(maybeQuestion is TriviaQuestion question))
{
// if question is null (ran out of question, or other bugg ) - stop
break;
}
CurrentQuestion = question;
try
{
// clear out all of the past guesses
while (_inputs.Reader.TryRead(out _)) ;
await OnQuestion(this, question);
}
catch (Exception ex)
{
Log.Warning(ex, "Error executing OnQuestion: {Message}", ex.Message);
errorCount++;
continue;
}
// just keep looping through user inputs until someone guesses the answer
// or the timer expires
var halfGuessTimerTask = TimeOutFactory();
var hintSent = false;
var guessed = false;
while (true)
{
var readTask = _inputs.Reader.ReadAsync().AsTask();
// wait for either someone to attempt to guess
// or for timeout
var task = await Task.WhenAny(readTask, halfGuessTimerTask);
// if the task which completed is the timeout task
if (task == halfGuessTimerTask)
{ {
// if hint is already sent, means time expired Log.Warning("Trivia errored 5 times and will quit");
// break (end the round) await OnEnded(this);
if (hintSent) break;
break; }
// else, means half time passed, send a hint // wait for 3 seconds before posting the next question
hintSent = true; if (firstRun)
// start a new countdown of the same length {
halfGuessTimerTask = TimeOutFactory(); firstRun = false;
// send a hint out }
await OnHint(this, question); else
{
await Task.Delay(3000);
}
var maybeQuestion = await _questionPool.GetQuestionAsync();
if (!(maybeQuestion is TriviaQuestion question))
{
// if question is null (ran out of question, or other bugg ) - stop
break;
}
CurrentQuestion = question;
try
{
// clear out all of the past guesses
while (_inputs.Reader.TryRead(out _))
;
await OnQuestion(this, question);
}
catch (Exception ex)
{
Log.Warning(ex, "Error executing OnQuestion: {Message}", ex.Message);
errorCount++;
continue; continue;
} }
// otherwise, read task is successful, and we're gonna
// get the user input data
var (user, input) = await readTask;
// check the guess // just keep looping through user inputs until someone guesses the answer
if (question.IsAnswerCorrect(input)) // or the timer expires
var halfGuessTimerTask = TimeOutFactory();
var hintSent = false;
var guessed = false;
while (true)
{ {
// add 1 point to the user var readTask = _inputs.Reader.ReadAsync().AsTask();
var val = _users.AddOrUpdate(user.Id, 1, (_, points) => ++points);
guessed = true;
// reset inactivity counter // wait for either someone to attempt to guess
inactivity = 0; // or for timeout
var task = await Task.WhenAny(readTask, halfGuessTimerTask);
var isWin = false; // if the task which completed is the timeout task
// if user won the game, tell the game to stop if (task == halfGuessTimerTask)
if (val >= _opts.WinRequirement)
{ {
_isStopped = true; // if hint is already sent, means time expired
isWin = true; // break (end the round)
if (hintSent)
break;
// else, means half time passed, send a hint
hintSent = true;
// start a new countdown of the same length
halfGuessTimerTask = TimeOutFactory();
// send a hint out
await OnHint(this, question);
continue;
} }
// call onguess // otherwise, read task is successful, and we're gonna
await OnGuess(this, user, question, isWin); // get the user input data
break; var (user, input) = await readTask;
}
}
if (!guessed) // check the guess
{ if (question.IsAnswerCorrect(input))
await OnTimeout(this, question); {
// add 1 point to the user
if (_opts.Timeout != 0 && ++inactivity >= _opts.Timeout) var val = _users.AddOrUpdate(user.Id, 1, (_, points) => ++points);
guessed = true;
// reset inactivity counter
inactivity = 0;
var isWin = false;
// if user won the game, tell the game to stop
if (val >= _opts.WinRequirement)
{
_isStopped = true;
isWin = true;
}
// call onguess
await OnGuess(this, user, question, isWin);
break;
}
}
if (!guessed)
{ {
Log.Information("Trivia game is stopping due to inactivity"); await OnTimeout(this, question);
break;
if (_opts.Timeout != 0 && ++inactivity >= _opts.Timeout)
{
Log.Information("Trivia game is stopping due to inactivity");
break;
}
} }
} }
} }
catch
{
// make sure game is set as ended }
_isStopped = true; finally
{
await OnEnded(this); // make sure game is set as ended
_isStopped = true;
_ = OnEnded(this);
}
} }
public IReadOnlyList<(ulong User, int points)> GetLeaderboard() public IReadOnlyList<(ulong User, int points)> GetLeaderboard()

View File

@@ -274,7 +274,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
Log.Information("Resolving youtube song by search term: {YoutubeQuery}", query); Log.Information("Resolving youtube song by search term: {YoutubeQuery}", query);
var cachedData = await _trackCacher.GetCachedDataByQueryAsync(query, MusicPlatform.Youtube); var cachedData = await _trackCacher.GetCachedDataByQueryAsync(query, MusicPlatform.Youtube);
if (cachedData is null) if (cachedData is null || string.IsNullOrWhiteSpace(cachedData.Title))
{ {
var stringData = await _ytdlSearchOperation.GetDataAsync(query); var stringData = await _ytdlSearchOperation.GetDataAsync(query);
var trackData = ResolveYtdlData(stringData); var trackData = ResolveYtdlData(stringData);

View File

@@ -716,7 +716,7 @@ public sealed class PatronageService
{ {
Name = key.PrettyName, Name = key.PrettyName,
Quota = 0, Quota = 0,
IsPatronLimit = false, IsPatronLimit = true,
}; };
return new() return new()

View File

@@ -334,14 +334,15 @@ public partial class Xp : NadekoModule<XpService>
public enum XpShopInputType public enum XpShopInputType
{ {
F = 0, Backgrounds = 1,
Frs = 0,
Fs = 0,
Frames = 0,
B = 1, B = 1,
Bg = 1, Bg = 1,
Bgs = 1, Bgs = 1,
Backgrounds = 1 Frames = 0,
F = 0,
Fr = 0,
Frs = 0,
Fs = 0,
} }
[Cmd] [Cmd]
@@ -352,9 +353,12 @@ public partial class Xp : NadekoModule<XpService>
await ReplyErrorLocalizedAsync(strs.xp_shop_disabled); await ReplyErrorLocalizedAsync(strs.xp_shop_disabled);
return; return;
} }
await SendConfirmAsync(GetText(strs.available_commands), $@"`{prefix}xpshop bgs` await SendConfirmAsync(GetText(strs.available_commands),
`{prefix}xpshop frames`"); $@"`{prefix}xpshop bgs`
`{prefix}xpshop frames`
*{GetText(strs.xpshop_website)}*");
} }
[Cmd] [Cmd]
@@ -394,13 +398,18 @@ public partial class Xp : NadekoModule<XpService>
.WithOkColor() .WithOkColor()
.WithTitle(item.Name) .WithTitle(item.Name)
.AddField(GetText(strs.price), Gambling.Gambling.N(item.Price, culture), true) .AddField(GetText(strs.price), Gambling.Gambling.N(item.Price, culture), true)
// .AddField(GetText(strs.buy), $"{prefix}xpbuy {key}", true) .WithImageUrl(string.IsNullOrWhiteSpace(item.Preview)
.WithImageUrl(item.Url.ToString()); ? item.Url
: item.Preview);
if (!string.IsNullOrWhiteSpace(item.Desc)) if (!string.IsNullOrWhiteSpace(item.Desc))
eb.WithDescription(item.Desc); eb.AddField(GetText(strs.desc), item.Desc);
var tier = _service.GetXpShopTierRequirement(); if (key == "default")
eb.WithDescription(GetText(strs.xpshop_website));
var tier = _service.GetXpShopTierRequirement(type);
if (tier != PatronTier.None) if (tier != PatronTier.None)
{ {
eb.WithFooter(GetText(strs.xp_shop_buy_required_tier(tier.ToString()))); eb.WithFooter(GetText(strs.xp_shop_buy_required_tier(tier.ToString())));
@@ -454,6 +463,42 @@ public partial class Xp : NadekoModule<XpService>
1, 1,
addPaginatedFooter: false); addPaginatedFooter: false);
} }
[Cmd]
public async Task XpShopBuy(XpShopInputType type, string key)
{
var result = await _service.BuyShopItemAsync(ctx.User.Id, (XpShopItemType)type, key);
if (result != BuyResult.Success)
{
var _ = result switch
{
BuyResult.InsufficientFunds => await ReplyErrorLocalizedAsync(strs.not_enough(_gss.Data.Currency.Sign)),
BuyResult.AlreadyOwned => await ReplyErrorLocalizedAsync(strs.xpshop_already_owned),
BuyResult.UnknownItem => await ReplyErrorLocalizedAsync(strs.xpshop_item_not_found),
BuyResult.InsufficientPatronTier => await ReplyErrorLocalizedAsync(strs.patron_insuff_tier),
_ => throw new ArgumentOutOfRangeException()
};
return;
}
await ReplyConfirmLocalizedAsync(strs.xpshop_buy_success(type.ToString().ToLowerInvariant(),
key.ToLowerInvariant()));
}
[Cmd]
public async Task XpShopUse(XpShopInputType type, string key)
{
var result = await _service.UseShopItemAsync(ctx.User.Id, (XpShopItemType)type, key);
if (!result)
{
await ReplyConfirmLocalizedAsync(strs.xp_shop_item_cant_use);
return;
}
await ctx.OkAsync();
}
private async Task OnShopUse(SocketMessageComponent smc, (string? key, XpShopItemType type)? maybeState) private async Task OnShopUse(SocketMessageComponent smc, (string? key, XpShopItemType type)? maybeState)
{ {

View File

@@ -10,7 +10,7 @@ namespace NadekoBot.Modules.Xp;
public sealed partial class XpConfig : ICloneable<XpConfig> public sealed partial class XpConfig : ICloneable<XpConfig>
{ {
[Comment(@"DO NOT CHANGE")] [Comment(@"DO NOT CHANGE")]
public int Version { get; set; } = 3; public int Version { get; set; } = 5;
[Comment(@"How much XP will the users receive per message")] [Comment(@"How much XP will the users receive per message")]
public int XpPerMessage { get; set; } = 3; public int XpPerMessage { get; set; } = 3;
@@ -37,9 +37,13 @@ True -> Users can access the xp shop using .xpshop command
False -> Users can't access the xp shop")] False -> Users can't access the xp shop")]
public bool IsEnabled { get; set; } = false; public bool IsEnabled { get; set; } = false;
[Comment(@"Which patron tier do users need in order to use the .xpshop command [Comment(@"Which patron tier do users need in order to use the .xpshop bgs command
Leave at 'None' if patron system is disabled or you don't want any restrictions")] Leave at 'None' if patron system is disabled or you don't want any restrictions")]
public PatronTier TierRequirement { get; set; } = PatronTier.None; public PatronTier BgsTierRequirement { get; set; } = PatronTier.None;
[Comment(@"Which patron tier do users need in order to use the .xpshop frames command
Leave at 'None' if patron system is disabled or you don't want any restrictions")]
public PatronTier FramesTierRequirement { get; set; } = PatronTier.None;
[Comment(@"Frames available for sale. Keys are unique IDs. [Comment(@"Frames available for sale. Keys are unique IDs.
Do not change keys as they are not publicly visible. Only change properties (name, price, id) Do not change keys as they are not publicly visible. Only change properties (name, price, id)
@@ -71,6 +75,9 @@ To remove an item from the shop, but keep previous purchases, set the price to -
[Comment(@"Direct url to the .png image which will be applied to the user's XP card")] [Comment(@"Direct url to the .png image which will be applied to the user's XP card")]
public string Url { get; set; } public string Url { get; set; }
[Comment(@"Optional preview url which will show instead of the real URL in the shop ")]
public string Preview { get; set; }
[Comment(@"Optional description of the item")] [Comment(@"Optional description of the item")]
public string Desc { get; set; } public string Desc { get; set; }
} }

View File

@@ -52,11 +52,11 @@ public sealed class XpConfigService : ConfigServiceBase<XpConfig>
}); });
} }
if (data.Version < 3) if (data.Version < 5)
{ {
ModifyConfig(c => ModifyConfig(c =>
{ {
c.Version = 3; c.Version = 5;
}); });
} }
} }

View File

@@ -623,7 +623,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
=> !user.IsDeafened && !user.IsMuted && !user.IsSelfDeafened && !user.IsSelfMuted; => !user.IsDeafened && !user.IsMuted && !user.IsSelfDeafened && !user.IsSelfMuted;
private TypedKey<long> GetVoiceXpKey(ulong userId) private TypedKey<long> GetVoiceXpKey(ulong userId)
=> new($"xp:vc_join:{userId}"); => new($"xp:{_client.CurrentUser.Id}:vc_join:{userId}");
private async Task UserJoinedVoiceChannel(SocketGuildUser user) private async Task UserJoinedVoiceChannel(SocketGuildUser user)
{ {
@@ -767,8 +767,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
return Enumerable.Empty<ulong>(); return Enumerable.Empty<ulong>();
} }
private static TypedKey<bool> GetUserRewKey(ulong userId) private TypedKey<bool> GetUserRewKey(ulong userId)
=> new($"xp:user_gain:{userId}"); => new($"xp:{_client.CurrentUser.Id}:user_gain:{userId}");
private async Task<bool> SetUserRewardedAsync(ulong userId) private async Task<bool> SetUserRewardedAsync(ulong userId)
=> await _c.AddAsync(GetUserRewKey(userId), => await _c.AddAsync(GetUserRewKey(userId),
@@ -887,6 +887,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
throw new ArgumentNullException(nameof(bgBytes)); throw new ArgumentNullException(nameof(bgBytes));
} }
var outlinePen = new Pen(Color.Black, 1f);
using var img = Image.Load<Rgba32>(bgBytes, out var imageFormat); using var img = Image.Load<Rgba32>(bgBytes, out var imageFormat);
if (template.User.Name.Show) if (template.User.Name.Show)
{ {
@@ -909,7 +911,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
Origin = new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8) Origin = new(template.User.Name.Pos.X, template.User.Name.Pos.Y + 8)
}, },
"@" + username, "@" + username,
template.User.Name.Color); Brushes.Solid(template.User.Name.Color),
outlinePen);
}); });
} }
@@ -929,7 +932,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
Origin = new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8) Origin = new(template.Club.Name.Pos.X + 50, template.Club.Name.Pos.Y - 8)
}, },
clubName, clubName,
template.Club.Name.Color)); Brushes.Solid(template.Club.Name.Color),
outlinePen));
} }
Font GetTruncatedFont( Font GetTruncatedFont(
@@ -987,7 +991,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
}); });
} }
var pen = new Pen(Color.Black, 1.25f);
var global = stats.Global; var global = stats.Global;
var guild = stats.Guild; var guild = stats.Guild;
@@ -1012,7 +1015,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
}, },
$"{global.LevelXp}/{global.RequiredXp}", $"{global.LevelXp}/{global.RequiredXp}",
Brushes.Solid(template.User.Xp.Global.Color), Brushes.Solid(template.User.Xp.Global.Color),
pen)); outlinePen));
} }
if (template.User.Xp.Guild.Show) if (template.User.Xp.Guild.Show)
@@ -1026,7 +1029,7 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
}, },
$"{guild.LevelXp}/{guild.RequiredXp}", $"{guild.LevelXp}/{guild.RequiredXp}",
Brushes.Solid(template.User.Xp.Guild.Color), Brushes.Solid(template.User.Xp.Guild.Color),
pen)); outlinePen));
} }
if (stats.FullGuildStats.AwardedXp != 0 && template.User.Xp.Awarded.Show) if (stats.FullGuildStats.AwardedXp != 0 && template.User.Xp.Awarded.Show)
@@ -1038,10 +1041,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
img.Mutate(x => x.DrawText($"({sign}{stats.FullGuildStats.AwardedXp})", img.Mutate(x => x.DrawText($"({sign}{stats.FullGuildStats.AwardedXp})",
_fonts.NotoSans.CreateFont(template.User.Xp.Awarded.FontSize, FontStyle.Bold), _fonts.NotoSans.CreateFont(template.User.Xp.Awarded.FontSize, FontStyle.Bold),
Brushes.Solid(template.User.Xp.Awarded.Color), Brushes.Solid(template.User.Xp.Awarded.Color),
pen, outlinePen,
new(awX, awY))); new(awX, awY)));
} }
var rankPen = new Pen(Color.White, 1);
//ranking //ranking
if (template.User.GlobalRank.Show) if (template.User.GlobalRank.Show)
{ {
@@ -1054,10 +1058,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
globalRankStr, globalRankStr,
68); 68);
img.Mutate(x => x.DrawText(globalRankStr, img.Mutate(x => x.DrawText(
globalRankFont, new TextOptions(globalRankFont)
template.User.GlobalRank.Color, {
new(template.User.GlobalRank.Pos.X, template.User.GlobalRank.Pos.Y))); Origin = new(template.User.GlobalRank.Pos.X, template.User.GlobalRank.Pos.Y)
},
globalRankStr,
Brushes.Solid(template.User.GlobalRank.Color),
rankPen
));
} }
if (template.User.GuildRank.Show) if (template.User.GuildRank.Show)
@@ -1071,10 +1080,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
guildRankStr, guildRankStr,
43); 43);
img.Mutate(x => x.DrawText(guildRankStr, img.Mutate(x => x.DrawText(
guildRankFont, new TextOptions(guildRankFont)
template.User.GuildRank.Color, {
new(template.User.GuildRank.Pos.X, template.User.GuildRank.Pos.Y))); Origin = new(template.User.GuildRank.Pos.X, template.User.GuildRank.Pos.Y)
},
guildRankStr,
Brushes.Solid(template.User.GuildRank.Color),
rankPen
));
} }
//avatar //avatar
@@ -1337,11 +1351,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
if (!conf.Shop.IsEnabled) if (!conf.Shop.IsEnabled)
return BuyResult.UnknownItem; return BuyResult.UnknownItem;
if (conf.Shop.TierRequirement != PatronTier.None) var req = type == XpShopItemType.Background
? conf.Shop.BgsTierRequirement
: conf.Shop.FramesTierRequirement;
if (req != PatronTier.None && !_creds.IsOwner(userId))
{ {
var patron = await _ps.GetPatronAsync(userId); var patron = await _ps.GetPatronAsync(userId);
if ((int)patron.Tier < (int)conf.Shop.TierRequirement) if ((int)patron.Tier < (int)req)
return BuyResult.InsufficientPatronTier; return BuyResult.InsufficientPatronTier;
} }
@@ -1468,8 +1486,12 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
return false; return false;
} }
public PatronTier GetXpShopTierRequirement() public PatronTier GetXpShopTierRequirement(Xp.XpShopInputType type)
=> _xpConfig.Data.Shop.TierRequirement; => type switch
{
Xp.XpShopInputType.F => _xpConfig.Data.Shop.FramesTierRequirement,
_ => _xpConfig.Data.Shop.BgsTierRequirement,
};
public bool IsShopEnabled() public bool IsShopEnabled()
=> _xpConfig.Data.Shop.IsEnabled; => _xpConfig.Data.Shop.IsEnabled;

View File

@@ -7,7 +7,7 @@ namespace NadekoBot.Services;
public sealed class StatsService : IStatsService, IReadyExecutor, INService public sealed class StatsService : IStatsService, IReadyExecutor, INService
{ {
public const string BOT_VERSION = "4.3.2"; public const string BOT_VERSION = "4.3.3";
public string Author public string Author
=> "Kwoth#2452"; => "Kwoth#2452";

View File

@@ -1064,6 +1064,10 @@ xpadd:
- xpadd - xpadd
xpshop: xpshop:
- xpshop - xpshop
xpshopbuy:
- xpshopbuy
xpshopuse:
- xpshopuse
clubcreate: clubcreate:
- clubcreate - clubcreate
clubtransfer: clubtransfer:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -2128,6 +2128,16 @@ xpshop:
- "bgs" - "bgs"
- "frames" - "frames"
- "bgs 3" - "bgs 3"
xpshopbuy:
desc: "Buy an item from the xp shop by specifying the type and the key of the item."
args:
- "bg open_sea"
- "fr gold"
xpshopuse:
desc: "Use a previously purchased item from the xp shop by specifying the type and the key of the item."
args:
- "bg synth"
- "fr default"
bible: bible:
desc: "Shows bible verse. You need to supply book name and chapter:verse" desc: "Shows bible verse. You need to supply book name and chapter:verse"
args: args:

View File

@@ -1003,7 +1003,7 @@
"feature_limit_reached_you": "You've reached the limit of {0} for the {1} feature. You may be able to increase this limit by upgrading your patron tier.", "feature_limit_reached_you": "You've reached the limit of {0} for the {1} feature. You may be able to increase this limit by upgrading your patron tier.",
"feature_limit_reached_owner": "Server owner has reached the limit of {0} for the {1} feature. Server owner may be able to upgrade this limit by upgrading patron tier.", "feature_limit_reached_owner": "Server owner has reached the limit of {0} for the {1} feature. Server owner may be able to upgrade this limit by upgrading patron tier.",
"feature_limit_reached_either": "The limit of {0} for the {1} feature has been reached. Either you or the server owner may able to upgrade this limit by upgrading the patron tier.", "feature_limit_reached_either": "The limit of {0} for the {1} feature has been reached. Either you or the server owner may able to upgrade this limit by upgrading the patron tier.",
"xp_shop_buy_required_tier": "Buying items from the shop requires Patron Tier {0} or higher.", "xp_shop_buy_required_tier": "Buying items from this shop requires Patron Tier {0} or higher.",
"available_commands": "Available Commands", "available_commands": "Available Commands",
"tier": "Tier", "tier": "Tier",
"pledge": "Pledge", "pledge": "Pledge",
@@ -1017,5 +1017,10 @@
"patron_not_enabled": "Patron system is disabled.", "patron_not_enabled": "Patron system is disabled.",
"results_in": "{0} results in {1}s", "results_in": "{0} results in {1}s",
"patron_msg_sent": "Done sending messages to patrons at and above tier {1}. {1} successfully sent and {2} failed.", "patron_msg_sent": "Done sending messages to patrons at and above tier {1}. {1} successfully sent and {2} failed.",
"xpadd_users": "Added {0} server XP to {1} users." "xpadd_users": "Added {0} server XP to {1} users.",
"xpshop_buy_success": "Successfully purchased `{0}/{1}`",
"patron_insuff_tier": "Your Patron Tier insufficient to perform this action.",
"xpshop_already_owned": "You already own this item.",
"xpshop_item_not_found": "An item with that key doesn't exist.",
"xpshop_website": "You can see the list of all Xp Shop items here: <https://xpshop.nadeko.bot>"
} }

View File

@@ -1,5 +1,5 @@
# DO NOT CHANGE # DO NOT CHANGE
version: 3 version: 5
# How much XP will the users receive per message # How much XP will the users receive per message
xpPerMessage: 3 xpPerMessage: 3
# How often can the users receive XP in minutes # How often can the users receive XP in minutes
@@ -16,9 +16,12 @@ shop:
# True -> Users can access the xp shop using .xpshop command # True -> Users can access the xp shop using .xpshop command
# False -> Users can't access the xp shop # False -> Users can't access the xp shop
isEnabled: false isEnabled: false
# Which patron tier do users need in order to use the .xpshop command # Which patron tier do users need in order to use the .xpshop bgs command
# Leave at 'None' if patron system is disabled or you don't want any restrictions # Leave at 'None' if patron system is disabled or you don't want any restrictions
tierRequirement: None bgsTierRequirement: None
# Which patron tier do users need in order to use the .xpshop frames command
# Leave at 'None' if patron system is disabled or you don't want any restrictions
framesTierRequirement: None
# Frames available for sale. Keys are unique IDs. # Frames available for sale. Keys are unique IDs.
# Do not change keys as they are not publicly visible. Only change properties (name, price, id) # Do not change keys as they are not publicly visible. Only change properties (name, price, id)
# Removing a key which previously existed means that all previous purchases will also be unusable. # Removing a key which previously existed means that all previous purchases will also be unusable.
@@ -31,6 +34,8 @@ shop:
price: 0 price: 0
# Direct url to the .png image which will be applied to the user's XP card # Direct url to the .png image which will be applied to the user's XP card
url: '' url: ''
# Optional preview url which will show instead of the real URL in the shop
preview:
# Optional description of the item # Optional description of the item
desc: desc:
# Backgrounds available for sale. Keys are unique IDs. # Backgrounds available for sale. Keys are unique IDs.
@@ -45,5 +50,7 @@ shop:
price: 0 price: 0
# Direct url to the .png image which will be applied to the user's XP card # Direct url to the .png image which will be applied to the user's XP card
url: '' url: ''
# Optional preview url which will show instead of the real URL in the shop
preview:
# Optional description of the item # Optional description of the item
desc: desc:

View File

@@ -10,8 +10,8 @@
"Show": true, "Show": true,
"FontSize": 50, "FontSize": 50,
"Pos": { "Pos": {
"X": 130, "X": 105,
"Y": 17 "Y": 25
} }
}, },
"Icon": { "Icon": {
@@ -65,7 +65,7 @@
"Bar": { "Bar": {
"Show": true, "Show": true,
"Global": { "Global": {
"Color": "00000066", "Color": "00000095",
"PointA": { "PointA": {
"X": 321, "X": 321,
"Y": 104 "Y": 104
@@ -78,7 +78,7 @@
"Direction": 3 "Direction": 3
}, },
"Guild": { "Guild": {
"Color": "00000066", "Color": "00000095",
"PointA": { "PointA": {
"X": 282, "X": 282,
"Y": 248 "Y": 248
@@ -114,7 +114,7 @@
"Show": true, "Show": true,
"FontSize": 25, "FontSize": 25,
"Pos": { "Pos": {
"X": 490, "X": 450,
"Y": 345 "Y": 345
} }
} }
@@ -138,7 +138,7 @@
"FontSize": 35, "FontSize": 35,
"Pos": { "Pos": {
"X": 650, "X": 650,
"Y": 49 "Y": 55
} }
} }
} }