Compare commits
No commits in common. "v5" and "5.1.15" have entirely different histories.
114 changed files with 787 additions and 32016 deletions
129
CHANGELOG.md
129
CHANGELOG.md
|
@ -2,96 +2,6 @@
|
|||
|
||||
Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except date format. a-c-f-r-o
|
||||
|
||||
## [5.1.20] - 13.11.2024
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.rakeback` command, get a % of house edge back as claimable currency
|
||||
- Added `.snipe` command to quickly get a copy of a posted message as an embed
|
||||
- You can reply to a message to snipe that message
|
||||
- Or just type .snipe and the bot will snipe the last message in the channel with content or image
|
||||
- Added `.betstatsreset` / `.bsreset` command to reset your stats for a fee
|
||||
- Added `.gamblestatsreset` / `.gsreset` owner-only command to reset bot stats for all games
|
||||
- Added `.waifuclaims` command which lists all of your claimed waifus
|
||||
- Added and changed `%bot.time%` and `%bot.date%` placeholders. They use timestamp tags now
|
||||
|
||||
### Changed
|
||||
|
||||
- `.divorce` no longer has a cooldown
|
||||
- `.betroll` has a 2% better payout
|
||||
- `.slot` payout balanced out (less volatile), reduced jackpot win but increased other wins,
|
||||
- now has a new symbol, wheat
|
||||
- worse around 1% in total (now shares the top spot with .bf)
|
||||
|
||||
## [5.1.19] - 05.11.2024
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.betstats`
|
||||
- See your own stats with .betstats
|
||||
- Target someone else: .betstats @mai_lanfiel
|
||||
- You can also specify a game .betstats lula
|
||||
- Or both! .betstats mai_lanfiel br
|
||||
- `.timely` can now have a server boost bonus
|
||||
- Configure server ids and reward amount in data/gambling.yml
|
||||
- anyone who boosts one of the sepcified servers gets the amount as base timely bonus
|
||||
|
||||
### Changed
|
||||
|
||||
- `.plant/pick` password font size will be slightly bigger
|
||||
- `.race` will now have 82-94% payout rate based on the number of players playing (1-12, x0.01 per player).
|
||||
- Any player over 12 won't increase payout
|
||||
|
||||
### Fixed
|
||||
|
||||
- `.xplb` and `.xpglb` now have proper ranks after page 1
|
||||
- Fixed boost bonus on shards different than the specified servers' shard
|
||||
|
||||
## [5.1.18] - 04.11.2024
|
||||
|
||||
### Added
|
||||
|
||||
- Added `.translateflags` / `.trfl` command.
|
||||
- Enable on a per-channel basis.
|
||||
- Reacting on any message in that channel with a flag emoji will post the translation of that message in the
|
||||
language of that country
|
||||
- 5 second cooldown per user
|
||||
- The message can only be translated once per language (counter resets every 24h)
|
||||
- `.timely` now has a button. Togglable via `.conf gambling` it's called pass because previously it was a captcha, but captchas are too annoying
|
||||
|
||||
## Changed
|
||||
|
||||
- [public bot] Patreon reward bonus for flowers reduced. Timely bonuses stay the same
|
||||
- discriminators removed from the databases. All users who had ???? as discriminator have been renamed to ??username.
|
||||
- all new unknown users will have ??Unknown as their name
|
||||
- Flower currency generation will now have a strikeout to try combat the pickbots. This is the weakest but easiest protection to implement. There may be more options in the future
|
||||
|
||||
## Fixed
|
||||
|
||||
- nunchi join game message is now ok color instead of error color
|
||||
|
||||
## [5.1.17] - 29.10.2024
|
||||
|
||||
### Fixed
|
||||
|
||||
- fix: Bot will now not accept .aar Role if that Role is higher than or equal to bot's role. Previously bot would just
|
||||
fail silently, now there is a proper error message.
|
||||
|
||||
## [5.1.16] - 28.10.2024
|
||||
|
||||
## Added
|
||||
|
||||
- Added .ncanvas and related commands.
|
||||
- You can set pixel colors (and text) on a 500x350 canvas, pepega version of r/place
|
||||
- You use currency to set pixels.
|
||||
- Commands:
|
||||
- see the entire canvas: `.nc`
|
||||
- zoom: `.ncz <pos>` or `.ncz x y`
|
||||
- set pixel: `.ncsp <pos> <color> <text?>`
|
||||
- get pixel: `.ncp <pos>`
|
||||
- Owners can use .ncsetimg to set a starting image, use `.h .setimg` for instructions
|
||||
- Owners can reset the whole canvas via `.ncreset`
|
||||
|
||||
## [5.1.15] - 21.10.2024
|
||||
|
||||
## Added
|
||||
|
@ -145,8 +55,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
|
||||
### Added
|
||||
|
||||
- Added `%user.displayname%` placeholder. It will show users nickname, if there is one, otherwise it will show the
|
||||
username.
|
||||
- Added `%user.displayname%` placeholder. It will show users nickname, if there is one, otherwise it will show the username.
|
||||
- Nickname won't be shown in bye messages.
|
||||
- Added initial version of grpc api. Beta
|
||||
|
||||
|
@ -179,13 +88,11 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- Fixed `.greettest`, and other `.*test` commands if you didn't have them enabled.
|
||||
- Fixed `.greetdmtest` sending messages twice.
|
||||
- Fixed a serious bug which caused greet messages to be jumbled up, and wrong ones to be sent for the wrong events.
|
||||
- There is no database issue, all greet messages are safe, the cache was caching any setting every 3 seconds with no
|
||||
regard for the type of the event
|
||||
- There is no database issue, all greet messages are safe, the cache was caching any setting every 3 seconds with no regard for the type of the event
|
||||
- This also caused `.greetdm` messages to not be sent if `.greet` is enabled
|
||||
- This bug was introduced in 5.1.8. PLEASE UPDATE if you are on 5.1.8
|
||||
- Selfhosters only: Fixed marmalade dependency loading
|
||||
- Note: Make sure to not publish any other DLLs besides the ones you are sure you will need, as there can be version
|
||||
conflicts which didn't happen before.
|
||||
- Note: Make sure to not publish any other DLLs besides the ones you are sure you will need, as there can be version conflicts which didn't happen before.
|
||||
|
||||
## [5.1.8] - 20.09.2024
|
||||
|
||||
|
@ -244,7 +151,6 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- Possible fix for `.remind` timestamp
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed old bloat / semi broken / dumb commands
|
||||
- `.memelist` / `.memegen` (too inconvenient to use)
|
||||
- `.activity` (useless owner-only command)
|
||||
|
@ -252,7 +158,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- `.rollduel` (we had this command?)
|
||||
- You can no longer bet on `.connect4`
|
||||
- `.economy` Removed.
|
||||
- Was buggy and didn't really show the real state of the economy.
|
||||
- Was buggy and didn.t really show the real state of the economy.
|
||||
- It might come back improved in the future
|
||||
- `.mal` Removed. Useless information / semi broken
|
||||
|
||||
|
@ -271,7 +177,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- Updated some bet descriptions to include 'all' 'half' usage instructions
|
||||
- Updated some command strings
|
||||
- dev: Vastly simplified marmalade creation using dotnet templates, docs updated
|
||||
- Slight refactor of .wiki, time, .catfact, .wikia, .define, .bible and .quran commands, no significant change in functionality
|
||||
- Slight refactor of .wiki, .time, .catfact, .wikia, .define, .bible and .quran commands, no significant change in functionality
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -292,8 +198,6 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- You can now send multiple waifu gifts at once to waifus. For example `.waifugift 3xRose @user` will give that user 3 roses
|
||||
- The format is `<NUMBER>x<ITEM>`, no spaces
|
||||
- Added `.boosttest` command
|
||||
- Added support for any openai compatible api for the chatterbot feature change:
|
||||
- Changed games.yml to allow input of the apiUrl (needs to be openai compatible) and modelName as a string.
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -351,6 +255,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
- Added support for `gpt-4o` in `data/games.yml`
|
||||
- Added EllieAiToken to `creds.yml`
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- Remind will now show a timestamp tag for durations
|
||||
|
@ -363,8 +268,8 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
|
||||
- Fixed xp bg buy button not working, and possibly some other buttons too
|
||||
- Fixed shopbuy %user% placeholders and updated help text
|
||||
- All .feed overloads should now work"
|
||||
- `.xpexclude` should will now work with forums too. If you exclude a forum you won't be able to gain xp in any of the threads.
|
||||
- All 'feed overloads should now work"
|
||||
- `'xpexclude` should will now work with forums too. If you exclude a forum you won't be able to gain xp in any of the threads.
|
||||
- Fixed remind not showing correct time
|
||||
|
||||
### Removed
|
||||
|
@ -376,12 +281,10 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
|
||||
### Added
|
||||
|
||||
- Added `.setserverbanner` and `.setservericon` commands
|
||||
- Added overloads section to `.h command` which will show you all versions of command usage with param names
|
||||
- You can now check commands for submodules, for example `.cmds SelfAssignedRoles` will show brief help for each of the
|
||||
commands in that submodule
|
||||
- Added dropdown menus for .mdls and .cmds (both module and group versions) which will give you the option to see more
|
||||
detailed help for each specific module, group or command respectively
|
||||
- Added `'setserverbanner` and `'setservericon` commands
|
||||
- Added overloads section to `'h command` which will show you all versions of command usage with param names
|
||||
- You can now check commands for submodules, for example `'cmds SelfAssignedRoles` will show brief help for each of the commands in that submodule
|
||||
- Added dropdown menus for 'mdls and 'cmds (both module and group versions) which will give you the option to see more detailed help for each specific module, group or command respectively
|
||||
- Self-Hosters only:
|
||||
- Added a dangerous cleanup command that you don't have to know about
|
||||
|
||||
|
@ -391,7 +294,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
|
|||
|
||||
### Fixed
|
||||
|
||||
- `.verbose` will now be respected for expression errors
|
||||
- Using `.pick` will now correctly show the name of the user who picked the currency
|
||||
- Fixed `.h` not working on some commands
|
||||
- `.langset` and `.langsetd` should no longer allow unsupported languages and nonsense to be typed in
|
||||
- `'verbose` will now be respected for expression errors
|
||||
- Using `'pick` will now correctly show the name of the user who picked the currency
|
||||
- Fixed `'h` not working on some commands
|
||||
- `'langset` and `'langsetd` should no longer allow unsupported languages and nonsense to be typed in
|
|
@ -11,7 +11,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
Dockerfile = Dockerfile
|
||||
ellie-menu.ps1 = ellie-menu.ps1
|
||||
LICENSE = LICENSE
|
||||
migrate.ps1 = migrate.ps1
|
||||
README.md = README.md
|
||||
remove-migrations.ps1 = remove-migrations.ps1
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot", "src\EllieBot\EllieBot.csproj", "{4D9001F7-B3E8-48FE-97AA-CFD36DA65A64}"
|
||||
|
@ -28,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ellie.Marmalade", "src\Elli
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot.Voice", "src\EllieBot.Voice\EllieBot.Voice.csproj", "{1D93CE3C-80B4-49C7-A9A2-99988920AAEC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EllieBot.GrpcApiBase", "src\EllieBot.GrpcApiBase\EllieBot.GrpcApiBase.csproj", "{3B71F0BF-AE6C-480C-AB88-FCE23EDC7D91}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EllieBot.GrpcApiBase", "src\EllieBot.GrpcApiBase\EllieBot.GrpcApiBase.csproj", "{3B71F0BF-AE6C-480C-AB88-FCE23EDC7D91}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
|
8
migrate.ps1
Normal file
8
migrate.ps1
Normal file
|
@ -0,0 +1,8 @@
|
|||
if ($args.Length -eq 0) {
|
||||
Write-Host "Please provide a migration name." -ForegroundColor Red
|
||||
}
|
||||
else {
|
||||
$migrationName = $args[0]
|
||||
dotnet ef migrations add $migrationName -o Migrations/Mysql -c SqliteContext -p src/EllieBot/EllieBot.csproj
|
||||
dotnet ef migrations add $migrationName -o Migrations/PostgreSql -c PostgreSqlContext -p src/EllieBot/EllieBot.csproj
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "EllieBot.GrpcApi";
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
package ncanvas;
|
||||
|
||||
service GrpcNCanvas {
|
||||
rpc GetCanvas(google.protobuf.Empty) returns (CanvasReply);
|
||||
rpc GetPixel(GetPixelRequest) returns (GetPixelReply);
|
||||
rpc SetPixel(SetPixelRequest) returns (SetPixelReply);
|
||||
}
|
||||
|
||||
message CanvasReply {
|
||||
repeated uint32 pixels = 1;
|
||||
int32 width = 2;
|
||||
int32 height = 3;
|
||||
}
|
||||
|
||||
message GetPixelRequest {
|
||||
int32 x = 1;
|
||||
int32 y = 2;
|
||||
}
|
||||
|
||||
message GetPixelReply {
|
||||
string color = 1;
|
||||
uint32 packedColor = 2;
|
||||
int32 positionX = 3;
|
||||
int32 positionY = 4;
|
||||
int64 price = 5;
|
||||
string text = 6;
|
||||
string position = 7;
|
||||
}
|
||||
|
||||
message SetPixelRequest {
|
||||
string position = 1;
|
||||
string color = 2;
|
||||
string text = 3;
|
||||
int64 price = 4;
|
||||
}
|
||||
|
||||
message SetPixelReply {
|
||||
string error = 1;
|
||||
bool success = 2;
|
||||
optional GetPixelReply pixel = 3;
|
||||
}
|
26
src/EllieBot.GrpcApiBase/protos/econ.proto
Normal file
26
src/EllieBot.GrpcApiBase/protos/econ.proto
Normal file
|
@ -0,0 +1,26 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "EllieBot.GrpcApi";
|
||||
|
||||
package econ;
|
||||
|
||||
service GrpcEcon {
|
||||
rpc GetEconomy(EconomyRequest) returns (EconomyReply);
|
||||
}
|
||||
|
||||
message EconomyRequest {
|
||||
string guildId = 1;
|
||||
}
|
||||
|
||||
message EconomyReply {
|
||||
uint64 totalOwned = 1;
|
||||
uint64 byTopOnePercent = 2;
|
||||
uint64 plantedAmount = 3;
|
||||
uint64 ownedByTheBot = 4;
|
||||
uint64 inTheBank = 5;
|
||||
uint64 totalEconomy = 6;
|
||||
}
|
||||
|
||||
message CurrencyLbRequest {
|
||||
int32 page = 1;
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "EllieBot.GrpcApi";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
package fin;
|
||||
|
||||
service GrpcFin {
|
||||
rpc GetTransactions(GetTransactionsRequest) returns (GetTransactionsReply);
|
||||
rpc GetHoldings(GetHoldingsRequest) returns (GetHoldingsReply);
|
||||
rpc Withdraw(WithdrawRequest) returns (WithdrawReply);
|
||||
rpc Deposit(DepositRequest) returns (DepositReply);
|
||||
}
|
||||
|
||||
message GetTransactionsRequest {
|
||||
int32 page = 1;
|
||||
uint64 userId = 2;
|
||||
}
|
||||
|
||||
message GetTransactionsReply {
|
||||
repeated TransactionReply transactions = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
message TransactionReply {
|
||||
int64 amount = 1;
|
||||
string note = 2;
|
||||
string type = 3;
|
||||
string extra = 4;
|
||||
google.protobuf.Timestamp timestamp = 5;
|
||||
string id = 6;
|
||||
}
|
||||
|
||||
message GetHoldingsRequest {
|
||||
uint64 userId = 1;
|
||||
}
|
||||
|
||||
message GetHoldingsReply {
|
||||
int64 cash = 1;
|
||||
int64 bank = 2;
|
||||
}
|
||||
|
||||
message WithdrawRequest {
|
||||
uint64 userId = 1;
|
||||
int64 amount = 2;
|
||||
}
|
||||
|
||||
message WithdrawReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message DepositRequest {
|
||||
uint64 userId = 1;
|
||||
int64 amount = 2;
|
||||
}
|
||||
|
||||
message DepositReply {
|
||||
bool success = 1;
|
||||
}
|
|
@ -3,11 +3,13 @@
|
|||
option csharp_namespace = "EllieBot.GrpcApi";
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
package other;
|
||||
|
||||
service GrpcOther {
|
||||
rpc BotOnGuild(BotOnGuildRequest) returns (BotOnGuildReply);
|
||||
rpc GetGuilds(google.protobuf.Empty) returns (GetGuildsReply);
|
||||
rpc GetTextChannels(GetTextChannelsRequest) returns (GetTextChannelsReply);
|
||||
rpc GetRoles(GetRolesRequest) returns (GetRolesReply);
|
||||
|
||||
|
@ -15,15 +17,10 @@ service GrpcOther {
|
|||
rpc GetXpLb(GetLbRequest) returns (XpLbReply);
|
||||
rpc GetWaifuLb(GetLbRequest) returns (WaifuLbReply);
|
||||
|
||||
rpc GetShardStats(google.protobuf.Empty) returns (stream ShardStatsReply);
|
||||
rpc GetCommandFeed(google.protobuf.Empty) returns (stream CommandFeedEntry);
|
||||
rpc GetShardStatuses(google.protobuf.Empty) returns (GetShardStatusesReply);
|
||||
rpc GetServerInfo(ServerInfoRequest) returns (GetServerInfoReply);
|
||||
}
|
||||
|
||||
message CommandFeedEntry {
|
||||
string command = 1;
|
||||
}
|
||||
|
||||
message GetRolesRequest {
|
||||
uint64 guildId = 1;
|
||||
}
|
||||
|
@ -40,13 +37,26 @@ message BotOnGuildReply {
|
|||
bool success = 1;
|
||||
}
|
||||
|
||||
message ShardStatsReply {
|
||||
message GetGuildsReply {
|
||||
repeated GuildReply guilds = 1;
|
||||
}
|
||||
|
||||
message GuildReply {
|
||||
uint64 id = 1;
|
||||
string name = 2;
|
||||
string iconUrl = 3;
|
||||
}
|
||||
|
||||
message GetShardStatusesReply {
|
||||
repeated ShardStatusReply shards = 1;
|
||||
}
|
||||
|
||||
message ShardStatusReply {
|
||||
int32 id = 1;
|
||||
string status = 2;
|
||||
|
||||
int32 guildCount = 3;
|
||||
string uptime = 4;
|
||||
int64 commands = 5;
|
||||
google.protobuf.Timestamp lastUpdate = 4;
|
||||
}
|
||||
|
||||
message GetTextChannelsRequest{
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "EllieBot.GrpcApi";
|
||||
|
||||
package xp;
|
||||
|
||||
service GrpcXp {
|
||||
rpc GetXpLb(GetXpLbRequest) returns (GetXpLbReply);
|
||||
rpc ResetUserXp(ResetUserXpRequest) returns (ResetUserXpReply);
|
||||
|
||||
rpc GetXpSettings(GetXpSettingsRequest) returns (GetXpSettingsReply);
|
||||
|
||||
rpc AddExclusion(AddExclusionRequest) returns (AddExclusionReply);
|
||||
rpc DeleteExclusion(DeleteExclusionRequest) returns (DeleteExclusionReply);
|
||||
|
||||
rpc AddReward(AddRewardRequest) returns (AddRewardReply);
|
||||
rpc DeleteReward(DeleteRewardRequest) returns (DeleteRewardReply);
|
||||
|
||||
rpc SetServerExclusion(SetServerExclusionRequest) returns (SetServerExclusionReply);
|
||||
}
|
||||
|
||||
message SetServerExclusionRequest {
|
||||
uint64 guildId = 1;
|
||||
bool serverExcluded = 2;
|
||||
}
|
||||
|
||||
message SetServerExclusionReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message GetXpLbRequest {
|
||||
uint64 guildId = 1;
|
||||
int32 page = 2;
|
||||
}
|
||||
|
||||
message GetXpLbReply {
|
||||
repeated XpLbUserReply users = 1;
|
||||
int32 total = 2;
|
||||
}
|
||||
|
||||
message XpLbUserReply {
|
||||
uint64 userId = 1;
|
||||
string username = 2;
|
||||
int64 xp = 3;
|
||||
int64 level = 4;
|
||||
int64 levelPercent = 5;
|
||||
string avatar = 6;
|
||||
}
|
||||
|
||||
message ResetUserXpRequest {
|
||||
uint64 guildId = 1;
|
||||
uint64 userId = 2;
|
||||
}
|
||||
|
||||
message ResetUserXpReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message GetXpSettingsReply {
|
||||
repeated ExclItemReply exclusions = 1;
|
||||
repeated RewItemReply rewards = 2;
|
||||
bool serverExcluded = 3;
|
||||
}
|
||||
|
||||
message GetXpSettingsRequest {
|
||||
uint64 guildId = 1;
|
||||
}
|
||||
|
||||
message ExclItemReply {
|
||||
string type = 1;
|
||||
uint64 id = 2;
|
||||
string name = 3;
|
||||
}
|
||||
|
||||
message RewItemReply {
|
||||
int32 level = 1;
|
||||
string type = 2;
|
||||
string value = 3;
|
||||
}
|
||||
|
||||
message AddExclusionRequest {
|
||||
uint64 guildId = 1;
|
||||
string type = 2;
|
||||
uint64 id = 3;
|
||||
}
|
||||
|
||||
message AddExclusionReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message DeleteExclusionRequest {
|
||||
uint64 guildId = 1;
|
||||
string type = 2;
|
||||
uint64 id = 3;
|
||||
}
|
||||
|
||||
message DeleteExclusionReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message AddRewardRequest {
|
||||
uint64 guildId = 1;
|
||||
int32 level = 2;
|
||||
string type = 3;
|
||||
string value = 4;
|
||||
}
|
||||
|
||||
message AddRewardReply {
|
||||
bool success = 1;
|
||||
}
|
||||
|
||||
message DeleteRewardRequest {
|
||||
uint64 guildId = 1;
|
||||
int32 level = 2;
|
||||
string type = 3;
|
||||
}
|
||||
|
||||
message DeleteRewardReply {
|
||||
bool success = 1;
|
||||
}
|
|
@ -62,7 +62,6 @@ public abstract class EllieContext : DbContext
|
|||
public DbSet<ArchivedTodoListModel> TodosArchive { get; set; }
|
||||
public DbSet<HoneypotChannel> HoneyPotChannels { get; set; }
|
||||
|
||||
|
||||
// public DbSet<GuildColors> GuildColors { get; set; }
|
||||
|
||||
|
||||
|
@ -74,40 +73,6 @@ public abstract class EllieContext : DbContext
|
|||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
#region Rakeback
|
||||
|
||||
modelBuilder.Entity<Rakeback>()
|
||||
.HasKey(x => x.UserId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region UserBetStats
|
||||
|
||||
modelBuilder.Entity<UserBetStats>()
|
||||
.HasIndex(x => new { x.UserId, x.Game })
|
||||
.IsUnique();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Flag Translate
|
||||
|
||||
modelBuilder.Entity<FlagTranslateChannel>()
|
||||
.HasIndex(x => new { x.GuildId, x.ChannelId })
|
||||
.IsUnique();
|
||||
|
||||
#endregion
|
||||
|
||||
#region NCanvas
|
||||
|
||||
modelBuilder.Entity<NCPixel>()
|
||||
.HasAlternateKey(x => x.Position);
|
||||
|
||||
modelBuilder.Entity<NCPixel>()
|
||||
.HasIndex(x => x.OwnerId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region QUOTES
|
||||
|
||||
var quoteEntity = modelBuilder.Entity<Quote>();
|
||||
|
|
|
@ -25,6 +25,7 @@ public static class DiscordUserExtensions
|
|||
{
|
||||
UserId = userId,
|
||||
Username = username,
|
||||
Discriminator = discrim,
|
||||
AvatarId = avatarId,
|
||||
TotalXp = 0,
|
||||
CurrencyAmount = 0
|
||||
|
@ -32,6 +33,7 @@ public static class DiscordUserExtensions
|
|||
old => new()
|
||||
{
|
||||
Username = username,
|
||||
Discriminator = discrim,
|
||||
AvatarId = avatarId
|
||||
},
|
||||
() => new()
|
||||
|
@ -47,7 +49,8 @@ public static class DiscordUserExtensions
|
|||
() => new()
|
||||
{
|
||||
UserId = userId,
|
||||
Username = "??Unknown",
|
||||
Username = "Unknown",
|
||||
Discriminator = "????",
|
||||
AvatarId = string.Empty,
|
||||
TotalXp = 0,
|
||||
CurrencyAmount = 0
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EllieBot.Db.Models;
|
||||
|
||||
namespace EllieBot.Db;
|
||||
|
@ -16,8 +17,6 @@ public static class SelfAssignableRolesExtensions
|
|||
return true;
|
||||
}
|
||||
|
||||
public static IReadOnlyCollection<SelfAssignedRole> GetFromGuild(
|
||||
this DbSet<SelfAssignedRole> roles,
|
||||
ulong guildId)
|
||||
public static IReadOnlyCollection<SelfAssignedRole> GetFromGuild(this DbSet<SelfAssignedRole> roles, ulong guildId)
|
||||
=> roles.AsQueryable().Where(s => s.GuildId == guildId).ToArray();
|
||||
}
|
|
@ -44,6 +44,9 @@ public static class UserXpExtensions
|
|||
.CountAsyncLinqToDB()
|
||||
+ 1;
|
||||
|
||||
public static void ResetGuildUserXp(this DbSet<UserXpStats> xps, ulong userId, ulong guildId)
|
||||
=> xps.Delete(x => x.UserId == userId && x.GuildId == guildId);
|
||||
|
||||
public static void ResetGuildXp(this DbSet<UserXpStats> xps, ulong guildId)
|
||||
=> xps.Delete(x => x.GuildId == guildId);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ public class DiscordUser : DbEntity
|
|||
{
|
||||
public ulong UserId { get; set; }
|
||||
public string Username { get; set; }
|
||||
// public string Discriminator { get; set; }
|
||||
public string Discriminator { get; set; }
|
||||
public string AvatarId { get; set; }
|
||||
|
||||
public int? ClubId { get; set; }
|
||||
|
@ -26,6 +26,9 @@ public class DiscordUser : DbEntity
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000")
|
||||
return Username;
|
||||
|
||||
return Username + "#" + Discriminator;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
#nullable disable
|
||||
namespace EllieBot.Db.Models;
|
||||
|
||||
public class FlagTranslateChannel : DbEntity
|
||||
{
|
||||
public ulong GuildId { get; set; }
|
||||
public ulong ChannelId { get; set; }
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EllieBot.Db.Models;
|
||||
|
||||
public class NCPixel
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public required int Position { get; init; }
|
||||
|
||||
public required long Price { get; init; }
|
||||
|
||||
public required ulong OwnerId { get; init; }
|
||||
public required uint Color { get; init; }
|
||||
|
||||
[MaxLength(256)]
|
||||
public required string Text { get; init; }
|
||||
}
|
|
@ -1,12 +1,8 @@
|
|||
#nullable disable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EllieBot.Db.Models;
|
||||
|
||||
public class PatronUser
|
||||
{
|
||||
// [Key]
|
||||
// public int Id { get; set; }
|
||||
public string UniquePlatformUserId { get; set; }
|
||||
public ulong UserId { get; set; }
|
||||
public int AmountCents { get; set; }
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
<Version>5.1.20</Version>
|
||||
<Version>5.1.15</Version>
|
||||
|
||||
<!-- Output/build -->
|
||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||
|
|
|
@ -5,11 +5,6 @@ namespace EllieBot.Migrations;
|
|||
|
||||
public static class MigrationQueries
|
||||
{
|
||||
public static void UpdateUsernames(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("UPDATE DiscordUser SET Username = '??' || Username WHERE Discriminator = '????';");
|
||||
}
|
||||
|
||||
public static void MigrateRero(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
if (migrationBuilder.IsSqlite())
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,54 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations.PostgreSql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ncanvas : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ncpixel",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
position = table.Column<int>(type: "integer", nullable: false),
|
||||
price = table.Column<long>(type: "bigint", nullable: false),
|
||||
ownerid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
color = table.Column<long>(type: "bigint", nullable: false),
|
||||
text = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_ncpixel", x => x.id);
|
||||
table.UniqueConstraint("ak_ncpixel_position", x => x.position);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_discorduser_username",
|
||||
table: "discorduser",
|
||||
column: "username");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_ncpixel_ownerid",
|
||||
table: "ncpixel",
|
||||
column: "ownerid");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ncpixel");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_discorduser_username",
|
||||
table: "discorduser");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,56 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations.PostgreSql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class nodiscrimandflagtranslate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
MigrationQueries.UpdateUsernames(migrationBuilder);
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "discriminator",
|
||||
table: "discorduser");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "flagtranslatechannel",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
guildid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
channelid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
dateadded = table.Column<DateTime>(type: "timestamp without time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_flagtranslatechannel", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_flagtranslatechannel_guildid_channelid",
|
||||
table: "flagtranslatechannel",
|
||||
columns: new[] { "guildid", "channelid" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "flagtranslatechannel");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "discriminator",
|
||||
table: "discorduser",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,48 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations.PostgreSql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class betstats : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "userbetstats",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
userid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
game = table.Column<int>(type: "integer", nullable: false),
|
||||
wincount = table.Column<long>(type: "bigint", nullable: false),
|
||||
losecount = table.Column<long>(type: "bigint", nullable: false),
|
||||
totalbet = table.Column<decimal>(type: "numeric", nullable: false),
|
||||
paidout = table.Column<decimal>(type: "numeric", nullable: false),
|
||||
maxwin = table.Column<long>(type: "bigint", nullable: false),
|
||||
maxbet = table.Column<long>(type: "bigint", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_userbetstats", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_userbetstats_userid_game",
|
||||
table: "userbetstats",
|
||||
columns: new[] { "userid", "game" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "userbetstats");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,33 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations.PostgreSql
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class rakeback : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "rakeback",
|
||||
columns: table => new
|
||||
{
|
||||
userid = table.Column<decimal>(type: "numeric(20,0)", nullable: false),
|
||||
amount = table.Column<decimal>(type: "numeric", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_rakeback", x => x.userid);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "rakeback");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using EllieBot.Db;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using EllieBot.Db;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
@ -751,6 +751,10 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
.HasColumnType("timestamp without time zone")
|
||||
.HasColumnName("dateadded");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("discriminator");
|
||||
|
||||
b.Property<bool>("IsClubAdmin")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("boolean")
|
||||
|
@ -795,63 +799,9 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_discorduser_userid");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.HasDatabaseName("ix_discorduser_username");
|
||||
|
||||
b.ToTable("discorduser", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.EllieExpression", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<bool>("AllowTarget")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allowtarget");
|
||||
|
||||
b.Property<bool>("AutoDeleteTrigger")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("autodeletetrigger");
|
||||
|
||||
b.Property<bool>("ContainsAnywhere")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("containsanywhere");
|
||||
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("timestamp without time zone")
|
||||
.HasColumnName("dateadded");
|
||||
|
||||
b.Property<bool>("DmResponse")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("dmresponse");
|
||||
|
||||
b.Property<decimal?>("GuildId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("guildid");
|
||||
|
||||
b.Property<string>("Reactions")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reactions");
|
||||
|
||||
b.Property<string>("Response")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("response");
|
||||
|
||||
b.Property<string>("Trigger")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("trigger");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_expressions");
|
||||
|
||||
b.ToTable("expressions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.ExcludedItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -1045,37 +995,6 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
b.ToTable("filteredword", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.FlagTranslateChannel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<decimal>("ChannelId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("channelid");
|
||||
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("timestamp without time zone")
|
||||
.HasColumnName("dateadded");
|
||||
|
||||
b.Property<decimal>("GuildId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("guildid");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_flagtranslatechannel");
|
||||
|
||||
b.HasIndex("GuildId", "ChannelId")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_flagtranslatechannel_guildid_channelid");
|
||||
|
||||
b.ToTable("flagtranslatechannel", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.FollowedStream", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -1708,7 +1627,7 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
b.ToTable("muteduserid", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.NCPixel", b =>
|
||||
modelBuilder.Entity("EllieBot.Db.Models.EllieExpression", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
|
@ -1717,38 +1636,46 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<long>("Color")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("color");
|
||||
b.Property<bool>("AllowTarget")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("allowtarget");
|
||||
|
||||
b.Property<decimal>("OwnerId")
|
||||
b.Property<bool>("AutoDeleteTrigger")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("autodeletetrigger");
|
||||
|
||||
b.Property<bool>("ContainsAnywhere")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("containsanywhere");
|
||||
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("timestamp without time zone")
|
||||
.HasColumnName("dateadded");
|
||||
|
||||
b.Property<bool>("DmResponse")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("dmresponse");
|
||||
|
||||
b.Property<decimal?>("GuildId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("ownerid");
|
||||
.HasColumnName("guildid");
|
||||
|
||||
b.Property<int>("Position")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("position");
|
||||
b.Property<string>("Reactions")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("reactions");
|
||||
|
||||
b.Property<long>("Price")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("price");
|
||||
b.Property<string>("Response")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("response");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("text");
|
||||
b.Property<string>("Trigger")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("trigger");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_ncpixel");
|
||||
.HasName("pk_expressions");
|
||||
|
||||
b.HasAlternateKey("Position")
|
||||
.HasName("ak_ncpixel_position");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_ncpixel_ownerid");
|
||||
|
||||
b.ToTable("ncpixel", (string)null);
|
||||
b.ToTable("expressions", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.PatronUser", b =>
|
||||
|
@ -3227,74 +3154,6 @@ namespace EllieBot.Migrations.PostgreSql
|
|||
b.ToTable("greetsettings", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Services.Rakeback", b =>
|
||||
{
|
||||
b.Property<decimal>("UserId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("userid");
|
||||
|
||||
b.Property<decimal>("Amount")
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("amount");
|
||||
|
||||
b.HasKey("UserId")
|
||||
.HasName("pk_rakeback");
|
||||
|
||||
b.ToTable("rakeback", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Services.UserBetStats", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Game")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("game");
|
||||
|
||||
b.Property<long>("LoseCount")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("losecount");
|
||||
|
||||
b.Property<long>("MaxBet")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("maxbet");
|
||||
|
||||
b.Property<long>("MaxWin")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("maxwin");
|
||||
|
||||
b.Property<decimal>("PaidOut")
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("paidout");
|
||||
|
||||
b.Property<decimal>("TotalBet")
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("totalbet");
|
||||
|
||||
b.Property<decimal>("UserId")
|
||||
.HasColumnType("numeric(20,0)")
|
||||
.HasColumnName("userid");
|
||||
|
||||
b.Property<long>("WinCount")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("wincount");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_userbetstats");
|
||||
|
||||
b.HasIndex("UserId", "Game")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_userbetstats_userid_game");
|
||||
|
||||
b.ToTable("userbetstats", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.AntiAltSetting", b =>
|
||||
{
|
||||
b.HasOne("EllieBot.Db.Models.GuildConfig", null)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,53 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ncanvas : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "NCPixel",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Position = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
Price = table.Column<long>(type: "INTEGER", nullable: false),
|
||||
OwnerId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
Color = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||
Text = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_NCPixel", x => x.Id);
|
||||
table.UniqueConstraint("AK_NCPixel_Position", x => x.Position);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_DiscordUser_Username",
|
||||
table: "DiscordUser",
|
||||
column: "Username");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_NCPixel_OwnerId",
|
||||
table: "NCPixel",
|
||||
column: "OwnerId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "NCPixel");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_DiscordUser_Username",
|
||||
table: "DiscordUser");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,55 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class nodiscrimandflagtranslate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
MigrationQueries.UpdateUsernames(migrationBuilder);
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Discriminator",
|
||||
table: "DiscordUser");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FlagTranslateChannel",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
GuildId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
ChannelId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
DateAdded = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FlagTranslateChannel", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FlagTranslateChannel_GuildId_ChannelId",
|
||||
table: "FlagTranslateChannel",
|
||||
columns: new[] { "GuildId", "ChannelId" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "FlagTranslateChannel");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Discriminator",
|
||||
table: "DiscordUser",
|
||||
type: "TEXT",
|
||||
nullable: true);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,47 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class betstats : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "UserBetStats",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
UserId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
Game = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
WinCount = table.Column<long>(type: "INTEGER", nullable: false),
|
||||
LoseCount = table.Column<long>(type: "INTEGER", nullable: false),
|
||||
TotalBet = table.Column<decimal>(type: "TEXT", nullable: false),
|
||||
PaidOut = table.Column<decimal>(type: "TEXT", nullable: false),
|
||||
MaxWin = table.Column<long>(type: "INTEGER", nullable: false),
|
||||
MaxBet = table.Column<long>(type: "INTEGER", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_UserBetStats", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserBetStats_UserId_Game",
|
||||
table: "UserBetStats",
|
||||
columns: new[] { "UserId", "Game" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "UserBetStats");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,34 +0,0 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EllieBot.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class rakeback : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Rakeback",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<ulong>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Amount = table.Column<decimal>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Rakeback", x => x.UserId);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Rakeback");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
// <auto-generated />
|
||||
using System;
|
||||
using EllieBot.Db;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using EllieBot.Db;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
@ -560,6 +560,9 @@ namespace EllieBot.Migrations
|
|||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsClubAdmin")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
|
@ -593,49 +596,9 @@ namespace EllieBot.Migrations
|
|||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.HasIndex("Username");
|
||||
|
||||
b.ToTable("DiscordUser");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.EllieExpression", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AllowTarget")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("AutoDeleteTrigger")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("ContainsAnywhere")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("DmResponse")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong?>("GuildId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Reactions")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Response")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Trigger")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Expressions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.ExcludedItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -778,29 +741,6 @@ namespace EllieBot.Migrations
|
|||
b.ToTable("FilteredWord");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.FlagTranslateChannel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("ChannelId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<ulong>("GuildId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("GuildId", "ChannelId")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("FlagTranslateChannel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.FollowedStream", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -1273,36 +1213,42 @@ namespace EllieBot.Migrations
|
|||
b.ToTable("MutedUserId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.NCPixel", b =>
|
||||
modelBuilder.Entity("EllieBot.Db.Models.EllieExpression", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<uint>("Color")
|
||||
b.Property<bool>("AllowTarget")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("OwnerId")
|
||||
b.Property<bool>("AutoDeleteTrigger")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Position")
|
||||
b.Property<bool>("ContainsAnywhere")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("Price")
|
||||
b.Property<DateTime?>("DateAdded")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("DmResponse")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
b.Property<ulong?>("GuildId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Reactions")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Response")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Trigger")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasAlternateKey("Position");
|
||||
|
||||
b.HasIndex("OwnerId");
|
||||
|
||||
b.ToTable("NCPixel");
|
||||
b.ToTable("Expressions");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.PatronUser", b =>
|
||||
|
@ -2399,58 +2345,6 @@ namespace EllieBot.Migrations
|
|||
b.ToTable("GreetSettings");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Services.Rakeback", b =>
|
||||
{
|
||||
b.Property<ulong>("UserId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<decimal>("Amount")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("UserId");
|
||||
|
||||
b.ToTable("Rakeback");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Services.UserBetStats", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Game")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("LoseCount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("MaxBet")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("MaxWin")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<decimal>("PaidOut")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<decimal>("TotalBet")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<ulong>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<long>("WinCount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId", "Game")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("UserBetStats");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EllieBot.Db.Models.AntiAltSetting", b =>
|
||||
{
|
||||
b.HasOne("EllieBot.Db.Models.GuildConfig", null)
|
||||
|
|
|
@ -25,13 +25,6 @@ public partial class Administration
|
|||
return;
|
||||
}
|
||||
|
||||
// the user can't aar the role which is greater or equal to the bot's highest role
|
||||
if (role.Position >= ((SocketGuild)ctx.Guild).CurrentUser.GetRoles().Max(x => x.Position))
|
||||
{
|
||||
await Response().Error(strs.hierarchy).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var roles = await _service.ToggleAarAsync(ctx.Guild.Id, role.Id);
|
||||
if (roles.Count == 0)
|
||||
await Response().Confirm(strs.aar_disabled).SendAsync();
|
||||
|
|
|
@ -339,7 +339,7 @@ public class GreetService : IEService, IReadyExecutor
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Unable to send Greet DM. Probably the user has closed DMs");
|
||||
Log.Error(ex, "Error sending greet dm");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, IEService
|
|||
if (server.OwnerId != _client.CurrentUser.Id)
|
||||
{
|
||||
await server.LeaveAsync();
|
||||
Log.Information("Left server {Name} [{Id}]", server.Name, server.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -452,6 +453,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, IEService
|
|||
{
|
||||
x.UserId,
|
||||
x.Username,
|
||||
x.Discriminator
|
||||
})
|
||||
.Where(x => users.Select(y => y.Id).Contains(x.UserId))
|
||||
.ToArrayAsyncEF();
|
||||
|
@ -463,11 +465,12 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, IEService
|
|||
UserId = x.Id,
|
||||
AvatarId = x.AvatarId,
|
||||
Username = x.Username,
|
||||
Discriminator = x.Discriminator
|
||||
});
|
||||
|
||||
var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied;
|
||||
var toUpdateUserIds = presentDbUsers
|
||||
.Where(x => x.Username.StartsWith("??"))
|
||||
.Where(x => x.Username == "Unknown" && x.Discriminator == "????")
|
||||
.Select(x => x.UserId)
|
||||
.ToArray();
|
||||
|
||||
|
@ -478,6 +481,7 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, IEService
|
|||
.UpdateAsync(x => new DiscordUser()
|
||||
{
|
||||
Username = user.Username,
|
||||
Discriminator = user.Discriminator,
|
||||
|
||||
// .award tends to set AvatarId and DateAdded to NULL, so account for that.
|
||||
AvatarId = user.AvatarId,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Common.TypeReaders.Models;
|
||||
using EllieBot.Modules.Permissions.Services;
|
||||
using EllieBot.Db.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
@ -6,10 +6,6 @@ namespace EllieBot.Modules.Gambling.Common.AnimalRacing;
|
|||
|
||||
public sealed class AnimalRace : IDisposable
|
||||
{
|
||||
public const double BASE_MULTIPLIER = 0.82;
|
||||
public const double MAX_MULTIPLIER = 0.94;
|
||||
public const double MULTI_PER_USER = 0.01;
|
||||
|
||||
public enum Phase
|
||||
{
|
||||
WaitingForPlayers,
|
||||
|
@ -104,7 +100,7 @@ public sealed class AnimalRace : IDisposable
|
|||
foreach (var user in _users)
|
||||
{
|
||||
if (user.Bet > 0)
|
||||
await _currency.AddAsync(user.UserId, (long)(user.Bet + BASE_MULTIPLIER), new("animalrace", "refund"));
|
||||
await _currency.AddAsync(user.UserId, user.Bet, new("animalrace", "refund"));
|
||||
}
|
||||
|
||||
_ = OnStartingFailed?.Invoke(this);
|
||||
|
@ -120,7 +116,7 @@ public sealed class AnimalRace : IDisposable
|
|||
{
|
||||
foreach (var user in _users)
|
||||
{
|
||||
user.Progress += rng.Next(1, 10);
|
||||
user.Progress += rng.Next(1, 11);
|
||||
if (user.Progress >= 60)
|
||||
user.Progress = 60;
|
||||
}
|
||||
|
@ -130,15 +126,13 @@ public sealed class AnimalRace : IDisposable
|
|||
FinishedUsers.AddRange(finished);
|
||||
|
||||
_ = OnStateUpdate?.Invoke(this);
|
||||
await Task.Delay(1750);
|
||||
await Task.Delay(2500);
|
||||
}
|
||||
|
||||
if (FinishedUsers[0].Bet > 0)
|
||||
{
|
||||
Multi = FinishedUsers.Count
|
||||
* Math.Min(MAX_MULTIPLIER, BASE_MULTIPLIER + (MULTI_PER_USER * FinishedUsers.Count));
|
||||
await _currency.AddAsync(FinishedUsers[0].UserId,
|
||||
(long)(FinishedUsers[0].Bet * Multi),
|
||||
FinishedUsers[0].Bet * (_users.Count - 1),
|
||||
new("animalrace", "win"));
|
||||
}
|
||||
|
||||
|
@ -146,8 +140,6 @@ public sealed class AnimalRace : IDisposable
|
|||
});
|
||||
}
|
||||
|
||||
public double Multi { get; set; } = BASE_MULTIPLIER;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
CurrentPhase = Phase.Ended;
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class AnimalRacingCommands : GamblingModule<AnimalRaceService>
|
||||
public partial class AnimalRacingCommands : GamblingSubmodule<AnimalRaceService>
|
||||
{
|
||||
private readonly ICurrencyService _cs;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
@ -74,14 +74,10 @@ public partial class Gambling
|
|||
if (race.FinishedUsers[0].Bet > 0)
|
||||
{
|
||||
return Response()
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.animal_race))
|
||||
.WithDescription(GetText(strs.animal_race_won_money(
|
||||
Format.Bold(winner.Username),
|
||||
.Confirm(GetText(strs.animal_race),
|
||||
GetText(strs.animal_race_won_money(Format.Bold(winner.Username),
|
||||
winner.Animal.Icon,
|
||||
N(race.FinishedUsers[0].Bet * race.Multi))))
|
||||
.WithFooter($"x{race.Multi:F2}"))
|
||||
(race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign)))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
|
@ -117,14 +113,14 @@ public partial class Gambling
|
|||
|
||||
private async Task Ar_OnStateUpdate(AnimalRace race)
|
||||
{
|
||||
var text = $@"|🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁🔚|
|
||||
var text = $@"|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|
|
||||
{string.Join("\n", race.Users.Select(p =>
|
||||
{
|
||||
var index = race.FinishedUsers.IndexOf(p);
|
||||
var extra = index == -1 ? "" : $"#{index + 1} {(index == 0 ? "🏆" : "")}";
|
||||
return $"{(int)(p.Progress / 60f * 100),-2}%|{new string('‣', p.Progress) + p.Animal.Icon + extra}";
|
||||
}))}
|
||||
|🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁🔚|";
|
||||
|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|";
|
||||
|
||||
var msg = raceMessage;
|
||||
|
||||
|
|
|
@ -1,175 +0,0 @@
|
|||
#nullable disable
|
||||
using EllieBot.Modules.Gambling.Common;
|
||||
using EllieBot.Modules.Gambling.Services;
|
||||
|
||||
namespace EllieBot.Modules.Gambling;
|
||||
|
||||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public sealed class BetStatsCommands : GamblingModule<UserBetStatsService>
|
||||
{
|
||||
private readonly GamblingTxTracker _gamblingTxTracker;
|
||||
|
||||
public BetStatsCommands(
|
||||
GamblingTxTracker gamblingTxTracker,
|
||||
GamblingConfigService gcs)
|
||||
: base(gcs)
|
||||
{
|
||||
_gamblingTxTracker = gamblingTxTracker;
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task BetStatsReset(GamblingGame? game = null)
|
||||
{
|
||||
var price = await _service.GetResetStatsPriceAsync(ctx.User.Id, game);
|
||||
|
||||
var result = await PromptUserConfirmAsync(_sender.CreateEmbed()
|
||||
.WithDescription(
|
||||
$"""
|
||||
Are you sure you want to reset your bet stats for **{GetGameName(game)}**?
|
||||
|
||||
It will cost you {N(price)}
|
||||
"""));
|
||||
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
var success = await _service.ResetStatsAsync(ctx.User.Id, game);
|
||||
|
||||
if (success)
|
||||
{
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Response()
|
||||
.Error(strs.not_enough(CurrencySign))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetGameName(GamblingGame? game)
|
||||
{
|
||||
if (game is null)
|
||||
return "all games";
|
||||
|
||||
return game.ToString();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[Priority(3)]
|
||||
public async Task BetStats()
|
||||
=> await BetStats(ctx.User, null);
|
||||
|
||||
[Cmd]
|
||||
[Priority(2)]
|
||||
public async Task BetStats(GamblingGame game)
|
||||
=> await BetStats(ctx.User, game);
|
||||
|
||||
[Cmd]
|
||||
[Priority(1)]
|
||||
public async Task BetStats([Leftover] IUser user)
|
||||
=> await BetStats(user, null);
|
||||
|
||||
[Cmd]
|
||||
[Priority(0)]
|
||||
public async Task BetStats(IUser user, GamblingGame? game)
|
||||
{
|
||||
var stats = await _gamblingTxTracker.GetUserStatsAsync(user.Id, game);
|
||||
|
||||
if (stats.Count == 0)
|
||||
stats = new()
|
||||
{
|
||||
new()
|
||||
{
|
||||
TotalBet = 1
|
||||
}
|
||||
};
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithAuthor(user)
|
||||
.AddField("Total Won", N(stats.Sum(x => x.PaidOut)), true)
|
||||
.AddField("Biggest Win", N(stats.Max(x => x.MaxWin)), true)
|
||||
.AddField("Biggest Bet", N(stats.Max(x => x.MaxBet)), true)
|
||||
.AddField("# Bets", stats.Sum(x => x.WinCount + x.LoseCount), true)
|
||||
.AddField("Payout",
|
||||
(stats.Sum(x => x.PaidOut) / stats.Sum(x => x.TotalBet)).ToString("P2", Culture),
|
||||
true);
|
||||
if (game == null)
|
||||
{
|
||||
var favGame = stats.MaxBy(x => x.WinCount + x.LoseCount);
|
||||
eb.AddField("Favorite Game",
|
||||
favGame.Game + "\n" + Format.Italics((favGame.WinCount + favGame.LoseCount) + " plays"),
|
||||
true);
|
||||
}
|
||||
else
|
||||
{
|
||||
eb.WithDescription(game.ToString())
|
||||
.AddField("# Wins", stats.Sum(x => x.WinCount), true);
|
||||
}
|
||||
|
||||
await Response()
|
||||
.Embed(eb)
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task GambleStats()
|
||||
{
|
||||
var stats = await _gamblingTxTracker.GetAllAsync();
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor();
|
||||
|
||||
var str = "` Feature `|` Bet `|`Paid Out`|` RoI `\n";
|
||||
str += "――――――――――――――――――――\n";
|
||||
foreach (var stat in stats)
|
||||
{
|
||||
var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture);
|
||||
str += $"`{stat.Feature.PadBoth(9)}`"
|
||||
+ $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`"
|
||||
+ $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`"
|
||||
+ $"|`{perc.PadLeft(6, ' ')}`\n";
|
||||
}
|
||||
|
||||
var bet = stats.Sum(x => x.Bet);
|
||||
var paidOut = stats.Sum(x => x.PaidOut);
|
||||
|
||||
if (bet == 0)
|
||||
bet = 1;
|
||||
|
||||
var tPerc = (paidOut / bet).ToString("P2", Culture);
|
||||
str += "――――――――――――――――――――\n";
|
||||
str += $"` {("TOTAL").PadBoth(7)}` "
|
||||
+ $"|**{N(bet).PadLeft(8, ' ')}**"
|
||||
+ $"|**{N(paidOut).PadLeft(8, ' ')}**"
|
||||
+ $"|`{tPerc.PadLeft(6, ' ')}`";
|
||||
|
||||
eb.WithDescription(str);
|
||||
|
||||
await Response().Embed(eb).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task GambleStatsReset()
|
||||
{
|
||||
if (!await PromptUserConfirmAsync(_sender.CreateEmbed()
|
||||
.WithDescription(
|
||||
"""
|
||||
Are you sure?
|
||||
This will completely reset Gambling Stats.
|
||||
|
||||
This action is irreversible.
|
||||
""")))
|
||||
return;
|
||||
|
||||
await GambleStats();
|
||||
await _service.ResetGamblingStatsAsync();
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
|
||||
public partial class Gambling
|
||||
{
|
||||
public partial class BlackJackCommands : GamblingModule<BlackJackService>
|
||||
public partial class BlackJackCommands : GamblingSubmodule<BlackJackService>
|
||||
{
|
||||
public enum BjAction
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class Connect4Commands : GamblingModule<GamblingService>
|
||||
public partial class Connect4Commands : GamblingSubmodule<GamblingService>
|
||||
{
|
||||
private static readonly string[] _numbers =
|
||||
[
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class DrawCommands : GamblingModule<IGamblingService>
|
||||
public partial class DrawCommands : GamblingSubmodule<IGamblingService>
|
||||
{
|
||||
private static readonly ConcurrentDictionary<IGuild, Deck> _allDecks = new();
|
||||
private readonly IImageCache _images;
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class CurrencyEventsCommands : GamblingModule<CurrencyEventsService>
|
||||
public partial class CurrencyEventsCommands : GamblingSubmodule<CurrencyEventsService>
|
||||
{
|
||||
public CurrencyEventsCommands(GamblingConfigService gamblingConf)
|
||||
: base(gamblingConf)
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class FlipCoinCommands : GamblingModule<IGamblingService>
|
||||
public partial class FlipCoinCommands : GamblingSubmodule<IGamblingService>
|
||||
{
|
||||
public enum BetFlipGuess : byte
|
||||
{
|
||||
|
|
|
@ -14,13 +14,6 @@ using System.Text;
|
|||
using EllieBot.Modules.Gambling.Rps;
|
||||
using EllieBot.Common.TypeReaders;
|
||||
using EllieBot.Modules.Patronage;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.Fonts.Unicode;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Color = SixLabors.ImageSharp.Color;
|
||||
|
||||
namespace EllieBot.Modules.Gambling;
|
||||
|
||||
|
@ -33,12 +26,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
private readonly NumberFormatInfo _enUsCulture;
|
||||
private readonly DownloadTracker _tracker;
|
||||
private readonly GamblingConfigService _configService;
|
||||
private readonly FontProvider _fonts;
|
||||
private readonly IBankService _bank;
|
||||
private readonly IRemindService _remind;
|
||||
private readonly GamblingTxTracker _gamblingTxTracker;
|
||||
private readonly IPatronageService _ps;
|
||||
private readonly RakebackService _rb;
|
||||
|
||||
public Gambling(
|
||||
IGamblingService gs,
|
||||
|
@ -47,12 +38,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
DiscordSocketClient client,
|
||||
DownloadTracker tracker,
|
||||
GamblingConfigService configService,
|
||||
FontProvider fonts,
|
||||
IBankService bank,
|
||||
IRemindService remind,
|
||||
IPatronageService patronage,
|
||||
GamblingTxTracker gamblingTxTracker,
|
||||
RakebackService rb)
|
||||
GamblingTxTracker gamblingTxTracker)
|
||||
: base(configService)
|
||||
{
|
||||
_gs = gs;
|
||||
|
@ -62,16 +51,13 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
_bank = bank;
|
||||
_remind = remind;
|
||||
_gamblingTxTracker = gamblingTxTracker;
|
||||
_rb = rb;
|
||||
_ps = patronage;
|
||||
_rng = new EllieRandom();
|
||||
|
||||
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
||||
_enUsCulture.NumberDecimalDigits = 0;
|
||||
_enUsCulture.NumberGroupSeparator = " ";
|
||||
_tracker = tracker;
|
||||
_configService = configService;
|
||||
_fonts = fonts;
|
||||
}
|
||||
|
||||
public async Task<string> GetBalanceStringAsync(ulong userId)
|
||||
|
@ -80,6 +66,42 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
return N(bal);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task BetStats()
|
||||
{
|
||||
var stats = await _gamblingTxTracker.GetAllAsync();
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor();
|
||||
|
||||
var str = "` Feature `|` Bet `|`Paid Out`|` RoI `\n";
|
||||
str += "――――――――――――――――――――\n";
|
||||
foreach (var stat in stats)
|
||||
{
|
||||
var perc = (stat.PaidOut / stat.Bet).ToString("P2", Culture);
|
||||
str += $"`{stat.Feature.PadBoth(9)}`"
|
||||
+ $"|`{stat.Bet.ToString("N0").PadLeft(8, ' ')}`"
|
||||
+ $"|`{stat.PaidOut.ToString("N0").PadLeft(8, ' ')}`"
|
||||
+ $"|`{perc.PadLeft(6, ' ')}`\n";
|
||||
}
|
||||
|
||||
var bet = stats.Sum(x => x.Bet);
|
||||
var paidOut = stats.Sum(x => x.PaidOut);
|
||||
|
||||
if (bet == 0)
|
||||
bet = 1;
|
||||
|
||||
var tPerc = (paidOut / bet).ToString("P2", Culture);
|
||||
str += "――――――――――――――――――――\n";
|
||||
str += $"` {("TOTAL").PadBoth(7)}` "
|
||||
+ $"|**{N(bet).PadLeft(8, ' ')}**"
|
||||
+ $"|**{N(paidOut).PadLeft(8, ' ')}**"
|
||||
+ $"|`{tPerc.PadLeft(6, ' ')}`";
|
||||
|
||||
eb.WithDescription(str);
|
||||
|
||||
await Response().Embed(eb).SendAsync();
|
||||
}
|
||||
|
||||
private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when)
|
||||
{
|
||||
|
@ -118,21 +140,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms)))
|
||||
);
|
||||
|
||||
private EllieInteractionBase CreateTimelyInteraction()
|
||||
=> _inter
|
||||
.Create(ctx.User.Id,
|
||||
new ButtonBuilder(
|
||||
label: "Timely",
|
||||
emote: Emoji.Parse("💰"),
|
||||
customId: "timely:" + _rng.Next(123456, 999999)),
|
||||
async (smc) =>
|
||||
{
|
||||
await smc.DeferAsync();
|
||||
await ClaimTimely();
|
||||
});
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Timely()
|
||||
{
|
||||
var val = Config.Timely.Amount;
|
||||
|
@ -143,71 +151,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
return;
|
||||
}
|
||||
|
||||
if (Config.Timely.ProtType == TimelyProt.Button)
|
||||
{
|
||||
var interaction = CreateTimelyInteraction();
|
||||
var msg = await Response().Pending(strs.timely_button).Interaction(interaction).SendAsync();
|
||||
await msg.DeleteAsync();
|
||||
return;
|
||||
}
|
||||
else if (Config.Timely.ProtType == TimelyProt.Captcha)
|
||||
{
|
||||
var password = _service.GeneratePassword();
|
||||
|
||||
var img = new Image<Rgba32>(70, 35);
|
||||
|
||||
var font = _fonts.NotoSans.CreateFont(30);
|
||||
var outlinePen = new SolidPen(Color.Black, 1f);
|
||||
var strikeoutRun = new RichTextRun
|
||||
{
|
||||
Start = 0,
|
||||
End = password.GetGraphemeCount(),
|
||||
Font = font,
|
||||
StrikeoutPen = new SolidPen(Color.White, 3),
|
||||
TextDecorations = TextDecorations.Strikeout
|
||||
};
|
||||
// draw password on the image
|
||||
img.Mutate(x =>
|
||||
{
|
||||
x.DrawText(new RichTextOptions(font)
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FallbackFontFamilies = _fonts.FallBackFonts,
|
||||
Origin = new(35, 17),
|
||||
TextRuns = [strikeoutRun]
|
||||
},
|
||||
password,
|
||||
Brushes.Solid(Color.White),
|
||||
outlinePen);
|
||||
});
|
||||
using var stream = await img.ToStreamAsync();
|
||||
var captcha = await Response()
|
||||
// .Embed(_sender.CreateEmbed()
|
||||
// .WithOkColor()
|
||||
// .WithImageUrl("attachment://timely.png"))
|
||||
.File(stream, "timely.png")
|
||||
.SendAsync();
|
||||
try
|
||||
{
|
||||
var userInput = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id);
|
||||
if (userInput?.ToLowerInvariant() != password?.ToLowerInvariant())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ = captcha.DeleteAsync();
|
||||
}
|
||||
}
|
||||
|
||||
await ClaimTimely();
|
||||
}
|
||||
|
||||
private async Task ClaimTimely()
|
||||
{
|
||||
var period = Config.Timely.Cooldown;
|
||||
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
|
||||
{
|
||||
// Get correct time form remainder
|
||||
|
@ -226,30 +169,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
}
|
||||
|
||||
|
||||
var val = Config.Timely.Amount;
|
||||
var boostGuilds = Config.BoostBonus.GuildIds ?? new();
|
||||
var guildUsers = await boostGuilds
|
||||
.Select(async gid =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var guild = await _client.Rest.GetGuildAsync(gid, false);
|
||||
var user = await _client.Rest.GetGuildUserAsync(gid, ctx.User.Id);
|
||||
return (guild, user);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return default;
|
||||
}
|
||||
})
|
||||
.WhenAll();
|
||||
|
||||
var userInfo = guildUsers.FirstOrDefault(x => x.user?.PremiumSince is not null);
|
||||
var booster = userInfo != default;
|
||||
|
||||
if (booster)
|
||||
val += Config.BoostBonus.BaseTimelyBonus;
|
||||
|
||||
var patron = await _ps.GetPatronAsync(ctx.User.Id);
|
||||
|
||||
var percentBonus = (_ps.PercentBonus(patron) / 100f);
|
||||
|
@ -260,20 +179,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
|
||||
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
||||
|
||||
var msg = GetText(strs.timely(N(val), period));
|
||||
if (booster || percentBonus > float.Epsilon)
|
||||
{
|
||||
msg += "\n\n";
|
||||
if (booster)
|
||||
msg += $"*+{N(Config.BoostBonus.BaseTimelyBonus)} bonus for boosting {userInfo.guild}!*\n";
|
||||
|
||||
if (percentBonus > float.Epsilon)
|
||||
msg +=
|
||||
$"*+{percentBonus:P0} bonus for the [Patreon](https://patreon.com/elliebot) pledge! <:hart:746995901758832712>*";
|
||||
|
||||
await Response().Confirm(msg).Interaction(inter).SendAsync();
|
||||
}
|
||||
else
|
||||
await Response().Confirm(strs.timely(N(val), period)).Interaction(inter).SendAsync();
|
||||
}
|
||||
|
||||
|
@ -385,8 +290,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
}
|
||||
|
||||
var embed = _sender.CreateEmbed()
|
||||
.WithTitle(GetText(strs.transactions(
|
||||
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
||||
.WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
||||
?? $"{userId}")))
|
||||
.WithOkColor();
|
||||
|
||||
|
@ -643,9 +547,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
}
|
||||
else
|
||||
{
|
||||
await Response()
|
||||
.Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign))
|
||||
.SendAsync();
|
||||
await Response().Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign)).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,9 +568,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
}
|
||||
else
|
||||
{
|
||||
await Response()
|
||||
.Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign))
|
||||
.SendAsync();
|
||||
await Response().Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign)).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -862,8 +762,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
private static readonly ImmutableArray<string> _emojis =
|
||||
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
||||
|
||||
private readonly EllieRandom _rng;
|
||||
|
||||
|
||||
[Cmd]
|
||||
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
||||
|
@ -1002,45 +900,4 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
private EllieInteractionBase CreateRakebackInteraction()
|
||||
=> _inter.Create(ctx.User.Id,
|
||||
new ButtonBuilder(
|
||||
customId: "cash:rakeback",
|
||||
emote: new Emoji("💸")),
|
||||
RakebackAction);
|
||||
|
||||
private async Task RakebackAction(SocketMessageComponent arg)
|
||||
{
|
||||
var rb = await _rb.ClaimRakebackAsync(ctx.User.Id);
|
||||
|
||||
if (rb == 0)
|
||||
{
|
||||
await arg.DeferAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await arg.RespondAsync(_sender, GetText(strs.rakeback_claimed(N(rb))), MsgType.Ok);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task Rakeback()
|
||||
{
|
||||
var rb = await _rb.GetRakebackAsync(ctx.User.Id);
|
||||
|
||||
if (rb < 1)
|
||||
{
|
||||
await Response()
|
||||
.Error(strs.rakeback_none)
|
||||
.SendAsync();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var inter = CreateRakebackInteraction();
|
||||
await Response()
|
||||
.Pending(strs.rakeback_available(N(rb)))
|
||||
.Interaction(inter)
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ namespace EllieBot.Modules.Gambling.Common;
|
|||
public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
||||
{
|
||||
[Comment("""DO NOT CHANGE""")]
|
||||
public int Version { get; set; } = 12;
|
||||
public int Version { get; set; } = 8;
|
||||
|
||||
[Comment("""Currency settings""")]
|
||||
public CurrencyConfig Currency { get; set; }
|
||||
|
@ -67,11 +67,6 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
|||
[Comment("""Slot config""")]
|
||||
public SlotsConfig Slots { get; set; }
|
||||
|
||||
[Comment("""
|
||||
Bonus config for server boosts
|
||||
""")]
|
||||
public BoostBonusConfig BoostBonus { get; set; }
|
||||
|
||||
public GamblingConfig()
|
||||
{
|
||||
BetRoll = new();
|
||||
|
@ -84,7 +79,6 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
|||
Slots = new();
|
||||
LuckyLadder = new();
|
||||
BotCuts = new();
|
||||
BoostBonus = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,26 +104,13 @@ public partial class TimelyConfig
|
|||
How much currency will the users get every time they run .timely command
|
||||
setting to 0 or less will disable this feature
|
||||
""")]
|
||||
public long Amount { get; set; } = 0;
|
||||
public int Amount { get; set; } = 0;
|
||||
|
||||
[Comment("""
|
||||
How often (in hours) can users claim currency with .timely command
|
||||
setting to 0 or less will disable this feature
|
||||
""")]
|
||||
public int Cooldown { get; set; } = 24;
|
||||
|
||||
[Comment("""
|
||||
How will timely be protected?
|
||||
None, Button (users have to click the button) or Captcha (users have to type the captcha from an image)
|
||||
""")]
|
||||
public TimelyProt ProtType { get; set; } = TimelyProt.Button;
|
||||
}
|
||||
|
||||
public enum TimelyProt
|
||||
{
|
||||
None,
|
||||
Button,
|
||||
Captcha
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
|
@ -164,7 +145,7 @@ public partial class BetRollConfig
|
|||
},
|
||||
new()
|
||||
{
|
||||
WhenAbove = 65,
|
||||
WhenAbove = 66,
|
||||
MultiplyBy = 2
|
||||
}
|
||||
];
|
||||
|
@ -226,7 +207,7 @@ public partial class LuckyLadderSettings
|
|||
public decimal[] Multipliers { get; set; }
|
||||
|
||||
public LuckyLadderSettings()
|
||||
=> Multipliers = [2.4M, 1.7M, 1.5M, 1.1M, 0.5M, 0.3M, 0.2M, 0.1M];
|
||||
=> Multipliers = [2.4M, 1.7M, 1.5M, 1.2M, 0.5M, 0.3M, 0.2M, 0.1M];
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
|
@ -428,14 +409,3 @@ public sealed partial class BotCutConfig
|
|||
""")]
|
||||
public decimal ShopSaleCut { get; set; } = 0.1m;
|
||||
}
|
||||
|
||||
[Cloneable]
|
||||
public sealed partial class BoostBonusConfig
|
||||
{
|
||||
[Comment("Users will receive a bonus if they boost any of these servers")]
|
||||
public List<ulong> GuildIds { get; set; } = new();
|
||||
|
||||
[Comment("This bonus will be added before any other multiplier is applied to the .timely command")]
|
||||
|
||||
public long BaseTimelyBonus { get; set; } = 50;
|
||||
}
|
|
@ -144,11 +144,6 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||
ConfigPrinters.ToString,
|
||||
val => val >= 0);
|
||||
|
||||
AddParsedProp("timely.prot",
|
||||
gs => gs.Timely.ProtType,
|
||||
ConfigParsers.InsensitiveEnum,
|
||||
ConfigPrinters.ToString);
|
||||
|
||||
Migrate();
|
||||
}
|
||||
|
||||
|
@ -172,6 +167,22 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||
});
|
||||
}
|
||||
|
||||
if (data.Version < 5)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 5;
|
||||
});
|
||||
}
|
||||
|
||||
if (data.Version < 6)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 6;
|
||||
});
|
||||
}
|
||||
|
||||
if (data.Version < 7)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
|
@ -188,18 +199,5 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||
c.Waifu.Decay.UnclaimedDecayPercent = 0;
|
||||
});
|
||||
}
|
||||
|
||||
if (data.Version < 12)
|
||||
{
|
||||
ModifyConfig(c =>
|
||||
{
|
||||
c.Version = 12;
|
||||
|
||||
if (c.BetRoll.Pairs.Length == 3 && c.BetRoll.Pairs[2].WhenAbove == 66)
|
||||
{
|
||||
c.BetRoll.Pairs[2].WhenAbove = 65;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ public class GamblingService : IEService, IReadyExecutor
|
|||
private readonly DiscordSocketClient _client;
|
||||
private readonly IBotCache _cache;
|
||||
private readonly GamblingConfigService _gss;
|
||||
private readonly EllieRandom _rng;
|
||||
|
||||
private static readonly TypedKey<long> _curDecayKey = new("currency:last_decay");
|
||||
|
||||
|
@ -30,19 +29,11 @@ public class GamblingService : IEService, IReadyExecutor
|
|||
_client = client;
|
||||
_cache = cache;
|
||||
_gss = gss;
|
||||
_rng = new EllieRandom();
|
||||
}
|
||||
|
||||
public Task OnReadyAsync()
|
||||
=> Task.WhenAll(CurrencyDecayLoopAsync(), TransactionClearLoopAsync());
|
||||
|
||||
|
||||
public string GeneratePassword()
|
||||
{
|
||||
var num = _rng.Next((int)Math.Pow(31, 2), (int)Math.Pow(32, 3));
|
||||
return new kwum(num).ToString();
|
||||
}
|
||||
|
||||
private async Task TransactionClearLoopAsync()
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
|
@ -187,8 +178,7 @@ public class GamblingService : IEService, IReadyExecutor
|
|||
public bool UserHasTimelyReminder(ulong userId)
|
||||
{
|
||||
var db = _db.GetDbContext();
|
||||
return db.GetTable<Reminder>()
|
||||
.Any(x => x.UserId == userId
|
||||
return db.GetTable<Reminder>().Any(x => x.UserId == userId
|
||||
&& x.Type == ReminderType.Timely);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,3 +58,11 @@ public abstract class GamblingModule<TService> : EllieModule<TService>
|
|||
return InternalCheckBet(amount);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class GamblingSubmodule<TService> : GamblingModule<TService>
|
||||
{
|
||||
protected GamblingSubmodule(GamblingConfigService gamblingConfService)
|
||||
: base(gamblingConfService)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class PlantPickCommands : GamblingModule<PlantPickService>
|
||||
public partial class PlantPickCommands : GamblingSubmodule<PlantPickService>
|
||||
{
|
||||
private readonly ILogCommandService _logService;
|
||||
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#nullable disable
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Db.Models;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.Fonts.Unicode;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
@ -28,7 +25,6 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
private readonly EllieRandom _rng;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly GamblingConfigService _gss;
|
||||
private readonly GamblingService _gs;
|
||||
|
||||
private readonly ConcurrentHashSet<ulong> _generationChannels;
|
||||
private readonly SemaphoreSlim _pickLock = new(1, 1);
|
||||
|
@ -41,8 +37,7 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
ICurrencyService cs,
|
||||
CommandHandler cmdHandler,
|
||||
DiscordSocketClient client,
|
||||
GamblingConfigService gss,
|
||||
GamblingService gs)
|
||||
GamblingConfigService gss)
|
||||
{
|
||||
_db = db;
|
||||
_strings = strings;
|
||||
|
@ -53,7 +48,6 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
_rng = new();
|
||||
_client = client;
|
||||
_gss = gss;
|
||||
_gs = gs;
|
||||
|
||||
using var uow = db.GetDbContext();
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
|
@ -93,7 +87,6 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
|
||||
if (toDelete is not null)
|
||||
uow.Remove(toDelete);
|
||||
|
||||
_generationChannels.TryRemove(cid);
|
||||
enabled = false;
|
||||
}
|
||||
|
@ -147,7 +140,7 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
pass = pass.TrimTo(10, true).ToLowerInvariant();
|
||||
using var img = Image.Load<Rgba32>(curImg);
|
||||
// choose font size based on the image height, so that it's visible
|
||||
var font = _fonts.NotoSans.CreateFont(img.Height / 11.0f, FontStyle.Bold);
|
||||
var font = _fonts.NotoSans.CreateFont(img.Height / 12.0f, FontStyle.Bold);
|
||||
img.Mutate(x =>
|
||||
{
|
||||
// measure the size of the text to be drawing
|
||||
|
@ -159,31 +152,13 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
|
||||
// fill the background with black, add 5 pixels on each side to make it look better
|
||||
x.FillPolygon(Color.ParseHex("00000080"),
|
||||
new PointF(1, 1),
|
||||
new PointF(0, 0),
|
||||
new PointF(size.Width + 5, 0),
|
||||
new PointF(size.Width + 5, size.Height + 10),
|
||||
new PointF(0, size.Height + 10));
|
||||
|
||||
var strikeoutRun = new RichTextRun
|
||||
{
|
||||
Start = 0,
|
||||
End = pass.GetGraphemeCount(),
|
||||
Font = font,
|
||||
StrikeoutPen = new SolidPen(Color.White, 2),
|
||||
TextDecorations = TextDecorations.Strikeout
|
||||
};
|
||||
|
||||
// draw the password over the background
|
||||
x.DrawText(new RichTextOptions(font)
|
||||
{
|
||||
Origin = new(0, 0),
|
||||
TextRuns =
|
||||
[
|
||||
strikeoutRun
|
||||
]
|
||||
},
|
||||
pass,
|
||||
new SolidBrush(Color.White));
|
||||
x.DrawText(pass, font, Color.White, new(0, 0));
|
||||
});
|
||||
// return image as a stream for easy sending
|
||||
var format = img.Metadata.DecodedImageFormat;
|
||||
|
@ -233,7 +208,7 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
+ " "
|
||||
+ GetText(channel.GuildId, strs.pick_pl(prefix));
|
||||
|
||||
var pw = config.Generation.HasPassword ? _gs.GeneratePassword().ToUpperInvariant() : null;
|
||||
var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null;
|
||||
|
||||
IUserMessage sent;
|
||||
var (stream, ext) = await GetRandomCurrencyImageAsync(pw);
|
||||
|
@ -257,11 +232,26 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a hexadecimal string from 1000 to ffff.
|
||||
/// </summary>
|
||||
/// <returns>A hexadecimal string from 1000 to ffff</returns>
|
||||
private string GenerateCurrencyPassword()
|
||||
{
|
||||
// generate a number from 1000 to ffff
|
||||
var num = _rng.Next(4096, 65536);
|
||||
// convert it to hexadecimal
|
||||
return num.ToString("x4");
|
||||
}
|
||||
|
||||
public async Task<long> PickAsync(
|
||||
ulong gid,
|
||||
ITextChannel ch,
|
||||
ulong uid,
|
||||
string pass)
|
||||
{
|
||||
await _pickLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
long amount;
|
||||
ulong[] ids;
|
||||
|
@ -270,25 +260,28 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
// this method will sum all plants with that password,
|
||||
// remove them, and get messageids of the removed plants
|
||||
|
||||
pass = pass?.Trim().TrimTo(10, true)?.ToUpperInvariant();
|
||||
pass = pass?.Trim().TrimTo(10, true).ToUpperInvariant();
|
||||
// gets all plants in this channel with the same password
|
||||
var entries = await uow.GetTable<PlantedCurrency>()
|
||||
var entries = uow.Set<PlantedCurrency>()
|
||||
.AsQueryable()
|
||||
.Where(x => x.ChannelId == ch.Id && pass == x.Password)
|
||||
.DeleteWithOutputAsync();
|
||||
|
||||
if (!entries.Any())
|
||||
return 0;
|
||||
|
||||
.ToList();
|
||||
// sum how much currency that is, and get all of the message ids (so that i can delete them)
|
||||
amount = entries.Sum(x => x.Amount);
|
||||
ids = entries.Select(x => x.MessageId).ToArray();
|
||||
}
|
||||
// remove them from the database
|
||||
uow.RemoveRange(entries);
|
||||
|
||||
|
||||
if (amount > 0)
|
||||
// give the picked currency to the user
|
||||
await _cs.AddAsync(uid, amount, new("currency", "collect"));
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// delete all of the plant messages which have just been picked
|
||||
_ = ch.DeleteMessagesAsync(ids);
|
||||
}
|
||||
catch { }
|
||||
|
@ -296,6 +289,11 @@ public class PlantPickService : IEService, IExecNoCommand
|
|||
// return the amount of currency the user picked
|
||||
return amount;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_pickLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ulong?> SendPlantMessageAsync(
|
||||
ulong gid,
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class ShopCommands : GamblingModule<IShopService>
|
||||
public partial class ShopCommands : GamblingSubmodule<IShopService>
|
||||
{
|
||||
public enum List
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@ public enum GamblingError
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class SlotCommands : GamblingModule<IGamblingService>
|
||||
public partial class SlotCommands : GamblingSubmodule<IGamblingService>
|
||||
{
|
||||
private readonly IImageCache _images;
|
||||
private readonly FontProvider _fonts;
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#nullable disable
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Db.Models;
|
||||
|
||||
namespace EllieBot.Modules.Gambling.Services;
|
||||
|
||||
public sealed class UserBetStatsService : IEService
|
||||
{
|
||||
private const long RESET_MIN_PRICE = 1000;
|
||||
private const decimal RESET_TOTAL_MULTIPLIER = 0.002m;
|
||||
|
||||
private readonly DbService _db;
|
||||
private readonly ICurrencyService _cs;
|
||||
|
||||
public UserBetStatsService(DbService db, ICurrencyService cs)
|
||||
{
|
||||
_db = db;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
public async Task<long> GetResetStatsPriceAsync(ulong userId, GamblingGame? game)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var totalBet = await ctx.GetTable<UserBetStats>()
|
||||
.Where(x => x.UserId == userId && (game == null || x.Game == game))
|
||||
.SumAsyncLinqToDB(x => x.TotalBet);
|
||||
|
||||
return Math.Max(RESET_MIN_PRICE, (long)Math.Ceiling(totalBet * RESET_TOTAL_MULTIPLIER));
|
||||
}
|
||||
|
||||
public async Task<bool> ResetStatsAsync(ulong userId, GamblingGame? game)
|
||||
{
|
||||
var price = await GetResetStatsPriceAsync(userId, game);
|
||||
|
||||
if (!await _cs.RemoveAsync(userId, price, new("betstats", "reset")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
await using var ctx = _db.GetDbContext();
|
||||
await ctx.GetTable<UserBetStats>()
|
||||
.DeleteAsync(x => x.UserId == userId && (game == null || x.Game == game));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task ResetGamblingStatsAsync()
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
await ctx.GetTable<GamblingStats>()
|
||||
.DeleteAsync();
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ namespace EllieBot.Modules.Gambling;
|
|||
public partial class Gambling
|
||||
{
|
||||
[Group]
|
||||
public partial class WaifuClaimCommands : GamblingModule<WaifuService>
|
||||
public partial class WaifuClaimCommands : GamblingSubmodule<WaifuService>
|
||||
{
|
||||
public WaifuClaimCommands(GamblingConfigService gamblingConfService)
|
||||
: base(gamblingConfService)
|
||||
|
@ -37,45 +37,6 @@ public partial class Gambling
|
|||
await Response().Error(strs.waifu_reset_fail).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task WaifuClaims()
|
||||
{
|
||||
await Response()
|
||||
.Paginated()
|
||||
.PageItems(async (page) => await _service.GetClaimsAsync(ctx.User.Id, page))
|
||||
.Page((items, page) =>
|
||||
{
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle("Waifus");
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
eb
|
||||
.WithPendingColor()
|
||||
.WithDescription(GetText(strs.empty_page));
|
||||
|
||||
return eb;
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
{
|
||||
var item = items[i];
|
||||
eb.AddField($"`#{(page * 9) + 1 + i}` {N(item.Price)}",
|
||||
$"""
|
||||
{item.Username}
|
||||
||{item.UserId}||
|
||||
""",
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
return eb;
|
||||
})
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task WaifuClaim(long amount, [Leftover] IUser target)
|
||||
|
@ -183,7 +144,7 @@ public partial class Gambling
|
|||
if (targetId == ctx.User.Id)
|
||||
return;
|
||||
|
||||
var (w, result, amount) = await _service.DivorceWaifuAsync(ctx.User, targetId);
|
||||
var (w, result, amount, remaining) = await _service.DivorceWaifuAsync(ctx.User, targetId);
|
||||
|
||||
if (result == DivorceResult.SucessWithPenalty)
|
||||
{
|
||||
|
@ -196,6 +157,14 @@ public partial class Gambling
|
|||
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
|
||||
else if (result == DivorceResult.NotYourWife)
|
||||
await Response().Error(strs.waifu_not_yours).SendAsync();
|
||||
else if (remaining is { } rem)
|
||||
{
|
||||
await Response()
|
||||
.Error(strs.waifu_recent_divorce(
|
||||
Format.Bold(((int)rem.TotalHours).ToString()),
|
||||
Format.Bold(rem.Minutes.ToString())))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
|
|
@ -318,20 +318,25 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
private static TypedKey<long> GetAffinityKey(ulong userId)
|
||||
=> new($"waifu:affinity:{userId}");
|
||||
|
||||
public async Task<(WaifuInfo, DivorceResult, long)> DivorceWaifuAsync(IUser user, ulong targetId)
|
||||
public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId)
|
||||
{
|
||||
DivorceResult result;
|
||||
TimeSpan? remaining = null;
|
||||
long amount = 0;
|
||||
WaifuInfo w;
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
w = uow.Set<WaifuInfo>().ByWaifuUserId(targetId);
|
||||
if (w?.Claimer is null || w.Claimer.UserId != user.Id)
|
||||
{
|
||||
result = DivorceResult.NotYourWife;
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining = await _cache.GetRatelimitAsync(GetDivorceKey(user.Id), 6.Hours());
|
||||
if (remaining is TimeSpan rem)
|
||||
{
|
||||
result = DivorceResult.Cooldown;
|
||||
return (w, result, amount, rem);
|
||||
}
|
||||
|
||||
amount = w.Price / 2;
|
||||
|
||||
|
@ -364,7 +369,7 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
return (w, result, amount);
|
||||
return (w, result, amount, remaining);
|
||||
}
|
||||
|
||||
public async Task<bool> GiftWaifuAsync(
|
||||
|
@ -598,7 +603,7 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
.Where(wi => wi.ClaimerId == waifuId)
|
||||
.Select(wi => wi.WaifuId)
|
||||
.Contains(x.Id))
|
||||
.Select(x => x.Username)
|
||||
.Select(x => $"{x.Username}#{x.Discriminator}")
|
||||
.ToListAsyncEF();
|
||||
}
|
||||
|
||||
|
@ -610,7 +615,7 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
.Where(wi => wi.AffinityId == waifuId)
|
||||
.Select(wi => wi.WaifuId)
|
||||
.Contains(x.Id))
|
||||
.Select(x => x.Username)
|
||||
.Select(x => $"{x.Username}#{x.Discriminator}")
|
||||
.ToListAsyncEF();
|
||||
}
|
||||
|
||||
|
@ -625,38 +630,4 @@ public class WaifuService : IEService, IReadyExecutor
|
|||
.FirstOrDefault())
|
||||
.ToListAsyncEF();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<WaifuClaimsResult>> GetClaimsAsync(ulong userId, int page)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
|
||||
var wid = ctx.GetTable<DiscordUser>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.Select(x => x.Id)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (wid == 0)
|
||||
return [];
|
||||
|
||||
return await ctx.GetTable<WaifuInfo>()
|
||||
.Where(x => x.ClaimerId == wid)
|
||||
.LeftJoin(ctx.GetTable<DiscordUser>(),
|
||||
(wi, du) => wi.WaifuId == du.Id,
|
||||
(wi, du) => new WaifuClaimsResult(
|
||||
du.Username,
|
||||
du.UserId,
|
||||
wi.Price
|
||||
))
|
||||
.OrderByDescending(x => x.Price)
|
||||
.Skip(page * 9)
|
||||
.Take(9)
|
||||
.ToListAsyncLinqToDB();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class WaifuClaimsResult(string username, ulong userId, long price)
|
||||
{
|
||||
public string Username { get; } = username;
|
||||
public ulong UserId { get; } = userId;
|
||||
public long Price { get; } = price;
|
||||
}
|
|
@ -42,12 +42,15 @@ public static class WaifuExtensions
|
|||
{
|
||||
Affinity = x.Affinity == null
|
||||
? null
|
||||
: x.Affinity.Username,
|
||||
: x.Affinity.Username
|
||||
+ (x.Affinity.Discriminator != "0000" ? "#" + x.Affinity.Discriminator : ""),
|
||||
ClaimerName =
|
||||
x.Claimer == null
|
||||
? null
|
||||
: x.Claimer.Username,
|
||||
WaifuName = x.Waifu.Username,
|
||||
: x.Claimer.Username
|
||||
+ (x.Claimer.Discriminator != "0000" ? "#" + x.Claimer.Discriminator : ""),
|
||||
WaifuName = x.Waifu.Username
|
||||
+ (x.Waifu.Discriminator != "0000" ? "#" + x.Waifu.Discriminator : ""),
|
||||
Price = x.Price
|
||||
})
|
||||
.ToListAsyncEF();
|
||||
|
@ -59,7 +62,7 @@ public static class WaifuExtensions
|
|||
public static ulong GetWaifuUserId(this DbSet<WaifuInfo> waifus, ulong ownerId, string name)
|
||||
=> waifus.AsQueryable()
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Claimer.UserId == ownerId && x.Waifu.Username == name)
|
||||
.Where(x => x.Claimer.UserId == ownerId && x.Waifu.Username + "#" + x.Waifu.Discriminator == name)
|
||||
.Select(x => x.Waifu.UserId)
|
||||
.FirstOrDefault();
|
||||
|
||||
|
@ -97,7 +100,7 @@ public static class WaifuExtensions
|
|||
ctx.Set<DiscordUser>()
|
||||
.AsQueryable()
|
||||
.Where(u => u.UserId == userId)
|
||||
.Select(u => u.Username)
|
||||
.Select(u => u.Username + "#" + u.Discriminator)
|
||||
.FirstOrDefault(),
|
||||
AffinityCount =
|
||||
ctx.Set<WaifuUpdate>()
|
||||
|
@ -109,14 +112,14 @@ public static class WaifuExtensions
|
|||
ctx.Set<DiscordUser>()
|
||||
.AsQueryable()
|
||||
.Where(u => u.Id == w.AffinityId)
|
||||
.Select(u => u.Username)
|
||||
.Select(u => u.Username + "#" + u.Discriminator)
|
||||
.FirstOrDefault(),
|
||||
ClaimCount = ctx.Set<WaifuInfo>().AsQueryable().Count(x => x.ClaimerId == w.WaifuId),
|
||||
ClaimerName =
|
||||
ctx.Set<DiscordUser>()
|
||||
.AsQueryable()
|
||||
.Where(u => u.Id == w.ClaimerId)
|
||||
.Select(u => u.Username)
|
||||
.Select(u => u.Username + "#" + u.Discriminator)
|
||||
.FirstOrDefault(),
|
||||
DivorceCount =
|
||||
ctx.Set<WaifuUpdate>()
|
||||
|
|
|
@ -13,10 +13,5 @@ public interface IGamblingService
|
|||
Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount);
|
||||
Task<FlipResult[]> FlipAsync(int count);
|
||||
Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick);
|
||||
|
||||
Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(
|
||||
ulong userId,
|
||||
long amount,
|
||||
byte? maybeGuessValue,
|
||||
byte? maybeGuessColor);
|
||||
Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? maybeGuessValue, byte? maybeGuessColor);
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
#nullable disable
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Modules.Gambling.Betdraw;
|
||||
using EllieBot.Modules.Gambling.Rps;
|
||||
using EllieBot.Modules.Gambling.Services;
|
||||
|
@ -10,12 +8,12 @@ namespace EllieBot.Modules.Gambling;
|
|||
|
||||
public sealed class NewGamblingService : IGamblingService, IEService
|
||||
{
|
||||
private readonly GamblingConfigService _gcs;
|
||||
private readonly GamblingConfigService _bcs;
|
||||
private readonly ICurrencyService _cs;
|
||||
|
||||
public NewGamblingService(GamblingConfigService gcs, ICurrencyService cs)
|
||||
public NewGamblingService(GamblingConfigService bcs, ICurrencyService cs)
|
||||
{
|
||||
_gcs = gcs;
|
||||
_bcs = bcs;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
|
@ -33,13 +31,13 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
}
|
||||
}
|
||||
|
||||
var game = new LulaGame(_gcs.Data.LuckyLadder.Multipliers);
|
||||
var game = new LulaGame(_bcs.Data.LuckyLadder.Multipliers);
|
||||
var result = game.Spin(amount);
|
||||
|
||||
var won = (long)result.Won;
|
||||
if (won > 0)
|
||||
{
|
||||
await _cs.AddAsync(userId, won, new("lula", result.Multiplier >= 1 ? "win" : "lose"));
|
||||
await _cs.AddAsync(userId, won, new("lula", "win"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -59,7 +57,7 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
}
|
||||
}
|
||||
|
||||
var game = new BetrollGame(_gcs.Data.BetRoll.Pairs
|
||||
var game = new BetrollGame(_bcs.Data.BetRoll.Pairs
|
||||
.Select(x => (x.WhenAbove, (decimal)x.MultiplyBy))
|
||||
.ToList());
|
||||
|
||||
|
@ -90,7 +88,7 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
}
|
||||
}
|
||||
|
||||
var game = new BetflipGame(_gcs.Data.BetFlip.Multiplier);
|
||||
var game = new BetflipGame(_bcs.Data.BetFlip.Multiplier);
|
||||
var result = game.Flip(guess, amount);
|
||||
|
||||
var won = (long)result.Won;
|
||||
|
@ -102,11 +100,7 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
return result;
|
||||
}
|
||||
|
||||
public async Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(
|
||||
ulong userId,
|
||||
long amount,
|
||||
byte? maybeGuessValue,
|
||||
byte? maybeGuessColor)
|
||||
public async Task<OneOf<BetdrawResult, GamblingError>> BetDrawAsync(ulong userId, long amount, byte? maybeGuessValue, byte? maybeGuessColor)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
||||
|
||||
|
@ -161,7 +155,7 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
var won = (long)result.Won;
|
||||
if (won > 0)
|
||||
{
|
||||
await _cs.AddAsync(userId, won, new("slot", "win"));
|
||||
await _cs.AddAsync(userId, won, new("slot", "won"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -272,45 +266,3 @@ public sealed class NewGamblingService : IGamblingService, IEService
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RakebackService : IEService
|
||||
{
|
||||
private readonly DbService _db;
|
||||
private readonly ICurrencyService _cs;
|
||||
|
||||
public RakebackService(DbService db, ICurrencyService cs)
|
||||
{
|
||||
_db = db;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
public async Task<long> GetRakebackAsync(ulong userId)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var rb = uow.GetTable<Rakeback>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.Select(x => x.Amount)
|
||||
.FirstOrDefault();
|
||||
|
||||
return (long)rb;
|
||||
}
|
||||
|
||||
public async Task<long> ClaimRakebackAsync(ulong userId)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var rbs = await uow.GetTable<Rakeback>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.DeleteWithOutputAsync((x) => x.Amount);
|
||||
|
||||
if (rbs.Length == 0)
|
||||
return 0;
|
||||
|
||||
var rb = (long)rbs[0];
|
||||
|
||||
await _cs.AddAsync(userId, rb, new("rakeback", "claim"));
|
||||
|
||||
return rb;
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
using EllieBot.Db.Models;
|
||||
|
||||
namespace EllieBot.Modules.Games;
|
||||
|
||||
public interface INCanvasService
|
||||
{
|
||||
Task<uint[]> GetCanvas();
|
||||
Task<NCPixel[]> GetPixelGroup(int position);
|
||||
|
||||
Task<SetPixelResult> SetPixel(
|
||||
int position,
|
||||
uint color,
|
||||
string text,
|
||||
ulong userId,
|
||||
long price);
|
||||
|
||||
Task<bool> SetImage(uint[] img);
|
||||
|
||||
Task<NCPixel?> GetPixel(int x, int y);
|
||||
Task<NCPixel?> GetPixel(int position);
|
||||
int GetHeight();
|
||||
int GetWidth();
|
||||
Task ResetAsync();
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
using EllieBot.Modules.Gambling.Services;
|
||||
using SixLabors.Fonts;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Advanced;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace EllieBot.Modules.Games;
|
||||
|
||||
public partial class Games
|
||||
{
|
||||
public sealed class NCanvasCommands : EllieModule
|
||||
{
|
||||
private readonly INCanvasService _service;
|
||||
private readonly IHttpClientFactory _http;
|
||||
private readonly FontProvider _fonts;
|
||||
private readonly GamblingConfigService _gcs;
|
||||
|
||||
public NCanvasCommands(
|
||||
INCanvasService service,
|
||||
IHttpClientFactory http,
|
||||
FontProvider fonts,
|
||||
GamblingConfigService gcs)
|
||||
{
|
||||
_service = service;
|
||||
_http = http;
|
||||
_fonts = fonts;
|
||||
_gcs = gcs;
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task NCanvas()
|
||||
{
|
||||
var pixels = await _service.GetCanvas();
|
||||
var image = new Image<Rgba32>(_service.GetWidth(), _service.GetHeight());
|
||||
|
||||
Parallel.For(0,
|
||||
image.Height,
|
||||
y =>
|
||||
{
|
||||
var pixelAccessor = image.DangerousGetPixelRowMemory(y);
|
||||
var row = pixelAccessor.Span;
|
||||
for (int x = 0; x < image.Width; x++)
|
||||
{
|
||||
row[x] = new Rgba32(pixels[(y * image.Width) + x]);
|
||||
}
|
||||
});
|
||||
|
||||
await using var stream = await image.ToStreamAsync();
|
||||
|
||||
var hint = GetText(strs.nc_hint(prefix, _service.GetWidth(), _service.GetHeight()));
|
||||
await Response()
|
||||
.File(stream, "ncanvas.png")
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
#if GLOBAL_ELLIE
|
||||
.WithDescription("This is not available yet.")
|
||||
#endif
|
||||
.WithFooter(hint)
|
||||
.WithImageUrl("attachment://ncanvas.png"))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public Task NCzoom(int row, int col)
|
||||
=> NCzoom((col * _service.GetWidth()) + row);
|
||||
|
||||
[Cmd]
|
||||
public async Task NCzoom(kwum position)
|
||||
{
|
||||
var w = _service.GetWidth();
|
||||
var h = _service.GetHeight();
|
||||
|
||||
if (position < 0 || position >= w * h)
|
||||
{
|
||||
await Response().Error(strs.invalid_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
using var img = await GetZoomImage(position);
|
||||
await using var stream = await img.ToStreamAsync();
|
||||
await ctx.Channel.SendFileAsync(stream, $"zoom_{position}.png");
|
||||
}
|
||||
|
||||
private async Task<Image<Rgba32>> GetZoomImage(kwum position)
|
||||
{
|
||||
var w = _service.GetWidth();
|
||||
var pixels = await _service.GetPixelGroup(position);
|
||||
|
||||
var origX = ((position % w) - 2) * 100;
|
||||
var origY = ((position / w) - 2) * 100;
|
||||
|
||||
var image = new Image<Rgba32>(500, 500);
|
||||
|
||||
const float fontSize = 30;
|
||||
|
||||
var posFont = _fonts.NotoSans.CreateFont(fontSize, FontStyle.Bold);
|
||||
var size = TextMeasurer.MeasureSize("wwww", new TextOptions(posFont));
|
||||
var scale = 100f / size.Width;
|
||||
if (scale < 1)
|
||||
posFont = _fonts.NotoSans.CreateFont(fontSize * scale, FontStyle.Bold);
|
||||
var outlinePen = new SolidPen(SixLabors.ImageSharp.Color.Black, 1f);
|
||||
|
||||
Parallel.For(0,
|
||||
pixels.Length,
|
||||
i =>
|
||||
{
|
||||
var pix = pixels[i];
|
||||
var startX = pix.Position % w * 100 - origX;
|
||||
var startY = pix.Position / w * 100 - origY;
|
||||
|
||||
var color = new Rgba32(pix.Color);
|
||||
image.Mutate(x => FillRectangleExtensions.Fill(x,
|
||||
new SolidBrush(color),
|
||||
new RectangleF(startX, startY, 100, 100)));
|
||||
|
||||
image.Mutate(x =>
|
||||
{
|
||||
x.DrawText(new RichTextOptions(posFont)
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Origin = new(startX + 50, startY + 50)
|
||||
},
|
||||
((kwum)pix.Position).ToString().PadLeft(2, '2'),
|
||||
Brushes.Solid(SixLabors.ImageSharp.Color.White),
|
||||
outlinePen);
|
||||
});
|
||||
});
|
||||
|
||||
// write the position on each section of the image
|
||||
return image;
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task NcSetPixel(kwum position, string colorHex, [Leftover] string text = "")
|
||||
{
|
||||
if (position < 0 || position >= _service.GetWidth() * _service.GetHeight())
|
||||
{
|
||||
await Response().Error(strs.invalid_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (colorHex.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
|
||||
colorHex = colorHex[2..];
|
||||
|
||||
if (!Rgba32.TryParseHex(colorHex, out var clr))
|
||||
{
|
||||
await Response().Error(strs.invalid_color).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var pixel = await _service.GetPixel(position);
|
||||
if (pixel is null)
|
||||
{
|
||||
await Response().Error(strs.nc_pixel_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var prompt = GetText(strs.nc_pixel_set_confirm(Format.Code(position.ToString()),
|
||||
Format.Bold(CurrencyHelper.N(pixel.Price,
|
||||
Culture,
|
||||
_gcs.Data.Currency.Sign))));
|
||||
|
||||
if (!await PromptUserConfirmAsync(_sender.CreateEmbed()
|
||||
.WithPendingColor()
|
||||
.WithDescription(prompt)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await _service.SetPixel(position, clr.PackedValue, text, ctx.User.Id, pixel.Price);
|
||||
|
||||
if (result == SetPixelResult.NotEnoughMoney)
|
||||
{
|
||||
await Response().Error(strs.not_enough(_gcs.Data.Currency.Sign)).SendAsync();
|
||||
return;
|
||||
}
|
||||
else if (result == SetPixelResult.InsufficientPayment)
|
||||
{
|
||||
await Response().Error(strs.nc_insuff_payment).SendAsync();
|
||||
return;
|
||||
}
|
||||
else if (result == SetPixelResult.InvalidInput)
|
||||
{
|
||||
await Response().Error(strs.invalid_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
using var img = await GetZoomImage(position);
|
||||
await using var stream = await img.ToStreamAsync();
|
||||
|
||||
await Response()
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(GetText(strs.nc_pixel_set(Format.Code(position.ToString()))))
|
||||
.WithImageUrl($"attachment://zoom_{position}.png"))
|
||||
.File(stream, $"zoom_{position}.png")
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task NcPixel(int x, int y)
|
||||
=> await NcPixel((y * _service.GetWidth()) + x);
|
||||
|
||||
[Cmd]
|
||||
public async Task NcPixel(kwum position)
|
||||
{
|
||||
if (position < 0 || position >= _service.GetWidth() * _service.GetHeight())
|
||||
{
|
||||
await Response().Error(strs.invalid_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var pixel = await _service.GetPixel(position);
|
||||
if (pixel is null)
|
||||
{
|
||||
await Response().Error(strs.nc_pixel_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var image = new Image<Rgba32>(100, 100);
|
||||
image.Mutate(x
|
||||
=> x.Fill(new SolidBrush(new Rgba32(pixel.Color)),
|
||||
new RectangleF(0, 0, 100, 100)));
|
||||
|
||||
await using var stream = await image.ToStreamAsync();
|
||||
|
||||
var pos = new kwum(pixel.Position);
|
||||
await Response()
|
||||
.File(stream, $"{pixel.Position}.png")
|
||||
.Embed(_sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(string.IsNullOrWhiteSpace(pixel.Text) ? string.Empty : pixel.Text)
|
||||
.WithTitle(GetText(strs.nc_pixel(pos)))
|
||||
.AddField(GetText(strs.nc_position),
|
||||
$"{pixel.Position % _service.GetWidth()} {pixel.Position / _service.GetWidth()}",
|
||||
true)
|
||||
.AddField(GetText(strs.price), pixel.Price.ToString(), true)
|
||||
.AddField(GetText(strs.color), "#" + new Rgba32(pixel.Color).ToHex())
|
||||
.WithImageUrl($"attachment://{pixel.Position}.png"))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task NcSetImg()
|
||||
{
|
||||
var attach = ctx.Message.Attachments.FirstOrDefault();
|
||||
if (attach is null)
|
||||
{
|
||||
await Response().Error(strs.no_attach_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var w = _service.GetWidth();
|
||||
var h = _service.GetHeight();
|
||||
if (attach.Width != w || attach.Height != h)
|
||||
{
|
||||
await Response().Error(strs.invalid_img_size(w, h)).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await PromptUserConfirmAsync(_sender.CreateEmbed()
|
||||
.WithDescription(
|
||||
"This will reset the canvas to the specified image. All prices, text and colors will be reset.\n\n"
|
||||
+ "Are you sure you want to continue?")))
|
||||
return;
|
||||
|
||||
using var http = _http.CreateClient();
|
||||
await using var stream = await http.GetStreamAsync(attach.Url);
|
||||
using var img = await Image.LoadAsync<Rgba32>(stream);
|
||||
|
||||
var pixels = new uint[_service.GetWidth() * _service.GetHeight()];
|
||||
|
||||
Parallel.For(0,
|
||||
_service.GetWidth() * _service.GetHeight(),
|
||||
i => pixels[i] = img[i % _service.GetWidth(), i / _service.GetWidth()].PackedValue);
|
||||
|
||||
// for (var y = 0; y < _service.GetHeight(); y++)
|
||||
// for (var x = 0; x < _service.GetWidth(); x++)
|
||||
// pixels[(y * _service.GetWidth()) + x] = img[x, y].PackedValue;
|
||||
|
||||
await _service.SetImage(pixels);
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[OwnerOnly]
|
||||
public async Task NcReset()
|
||||
{
|
||||
await _service.ResetAsync();
|
||||
|
||||
if (!await PromptUserConfirmAsync(_sender.CreateEmbed()
|
||||
.WithDescription(
|
||||
"This will delete all pixels and reset the canvas.\n\n"
|
||||
+ "Are you sure you want to continue?")))
|
||||
return;
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,206 +0,0 @@
|
|||
using LinqToDB;
|
||||
using LinqToDB.Data;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Db.Models;
|
||||
using SixLabors.ImageSharp.ColorSpaces;
|
||||
using SixLabors.ImageSharp.ColorSpaces.Conversion;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace EllieBot.Modules.Games;
|
||||
|
||||
public sealed class NCanvasService : INCanvasService, IReadyExecutor, IEService
|
||||
{
|
||||
private readonly TypedKey<uint[]> _canvasKey = new("ncanvas");
|
||||
|
||||
private readonly DbService _db;
|
||||
private readonly IBotCache _cache;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly ICurrencyService _cs;
|
||||
|
||||
public const int CANVAS_WIDTH = 500;
|
||||
public const int CANVAS_HEIGHT = 350;
|
||||
public const int INITIAL_PRICE = 3;
|
||||
|
||||
public NCanvasService(
|
||||
DbService db,
|
||||
IBotCache cache,
|
||||
DiscordSocketClient client,
|
||||
ICurrencyService cs)
|
||||
{
|
||||
_db = db;
|
||||
_cache = cache;
|
||||
_client = client;
|
||||
_cs = cs;
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
return;
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
if (await uow.GetTable<NCPixel>().CountAsyncLinqToDB() > 0)
|
||||
return;
|
||||
|
||||
await ResetAsync();
|
||||
}
|
||||
|
||||
public async Task ResetAsync()
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<NCPixel>().DeleteAsync();
|
||||
|
||||
var toAdd = new List<int>();
|
||||
for (var i = 0; i < CANVAS_WIDTH * CANVAS_HEIGHT; i++)
|
||||
{
|
||||
toAdd.Add(i);
|
||||
}
|
||||
|
||||
await uow.GetTable<NCPixel>()
|
||||
.BulkCopyAsync(toAdd.Select(x =>
|
||||
{
|
||||
var clr = ColorSpaceConverter.ToRgb(new Hsv(((float)Random.Shared.NextDouble() * 360),
|
||||
(float)(0.5 + (Random.Shared.NextDouble() * 0.49)),
|
||||
(float)(0.4 + (Random.Shared.NextDouble() / 5 + (x % 100 * 0.2)))))
|
||||
.ToVector3();
|
||||
|
||||
var packed = new Rgba32(clr).PackedValue;
|
||||
return new NCPixel()
|
||||
{
|
||||
Color = packed,
|
||||
Price = 1,
|
||||
Position = x,
|
||||
Text = "",
|
||||
OwnerId = 0
|
||||
};
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private async Task<uint[]> InternalGetCanvas()
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var colors = await uow.GetTable<NCPixel>()
|
||||
.OrderBy(x => x.Position)
|
||||
.Select(x => x.Color)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public async Task<uint[]> GetCanvas()
|
||||
{
|
||||
return await _cache.GetOrAddAsync(_canvasKey,
|
||||
async () => await InternalGetCanvas(),
|
||||
TimeSpan.FromSeconds(15))
|
||||
?? [];
|
||||
}
|
||||
|
||||
public async Task<SetPixelResult> SetPixel(
|
||||
int position,
|
||||
uint color,
|
||||
string text,
|
||||
ulong userId,
|
||||
long price)
|
||||
{
|
||||
if (position < 0 || position >= CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
return SetPixelResult.InvalidInput;
|
||||
|
||||
var wallet = await _cs.GetWalletAsync(userId);
|
||||
|
||||
var paid = await wallet.Take(price, new("canvas", "pixel-buy", $"Bought pixel {new kwum(position)}"));
|
||||
if (!paid)
|
||||
{
|
||||
return SetPixelResult.NotEnoughMoney;
|
||||
}
|
||||
|
||||
var success = false;
|
||||
try
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var updates = await uow.GetTable<NCPixel>()
|
||||
.Where(x => x.Position == position && x.Price <= price)
|
||||
.UpdateAsync(old => new NCPixel()
|
||||
{
|
||||
Position = position,
|
||||
Color = color,
|
||||
Text = text,
|
||||
OwnerId = userId,
|
||||
Price = price + 1
|
||||
});
|
||||
success = updates > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
await wallet.Add(price, new("canvas", "pixel-refund", $"Refund pixel {new kwum(position)} purchase"));
|
||||
}
|
||||
|
||||
return success ? SetPixelResult.Success : SetPixelResult.InsufficientPayment;
|
||||
}
|
||||
|
||||
public async Task<bool> SetImage(uint[] colors)
|
||||
{
|
||||
if (colors.Length != CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
return false;
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<NCPixel>().DeleteAsync();
|
||||
await uow.GetTable<NCPixel>()
|
||||
.BulkCopyAsync(colors.Select((x, i) => new NCPixel()
|
||||
{
|
||||
Color = x,
|
||||
Price = INITIAL_PRICE,
|
||||
Position = i,
|
||||
Text = "",
|
||||
OwnerId = 0
|
||||
}));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Task<NCPixel?> GetPixel(int x, int y)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(x);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(y);
|
||||
|
||||
if (x >= CANVAS_WIDTH || y >= CANVAS_HEIGHT)
|
||||
return Task.FromResult<NCPixel?>(null);
|
||||
|
||||
return GetPixel(x + (y * CANVAS_WIDTH));
|
||||
}
|
||||
|
||||
public async Task<NCPixel?> GetPixel(int position)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(position);
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.GetTable<NCPixel>().FirstOrDefaultAsync(x => x.Position == position);
|
||||
}
|
||||
|
||||
public async Task<NCPixel[]> GetPixelGroup(int position)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(position);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(position, CANVAS_WIDTH * CANVAS_HEIGHT);
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.GetTable<NCPixel>()
|
||||
.Where(x => x.Position % CANVAS_WIDTH >= (position % CANVAS_WIDTH) - 2
|
||||
&& x.Position % CANVAS_WIDTH <= (position % CANVAS_WIDTH) + 2
|
||||
&& x.Position / CANVAS_WIDTH >= (position / CANVAS_WIDTH) - 2
|
||||
&& x.Position / CANVAS_WIDTH <= (position / CANVAS_WIDTH) + 2)
|
||||
.OrderBy(x => x.Position)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public int GetHeight()
|
||||
=> CANVAS_HEIGHT;
|
||||
|
||||
public int GetWidth()
|
||||
=> CANVAS_WIDTH;
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
namespace EllieBot.Modules.Games;
|
||||
|
||||
public enum SetPixelResult
|
||||
{
|
||||
Success,
|
||||
InsufficientPayment,
|
||||
NotEnoughMoney,
|
||||
InvalidInput
|
||||
}
|
|
@ -29,7 +29,7 @@ public partial class Games
|
|||
if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString()))
|
||||
return;
|
||||
|
||||
await Response().Confirm(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync();
|
||||
await Response().Error(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,9 +122,9 @@ public sealed class CurrencyRewardService : IEService, IReadyExecutor
|
|||
var dollarValue = pledgeCents / 100;
|
||||
percentBonus = dollarValue switch
|
||||
{
|
||||
>= 100 => 25,
|
||||
>= 50 => 20,
|
||||
>= 20 => 15,
|
||||
>= 100 => 100,
|
||||
>= 50 => 50,
|
||||
>= 20 => 20,
|
||||
>= 10 => 10,
|
||||
>= 5 => 5,
|
||||
_ => 0
|
||||
|
|
|
@ -404,9 +404,9 @@ public sealed class PatronageService
|
|||
{
|
||||
>= 10_000 => 100,
|
||||
>= 5000 => 50,
|
||||
>= 2000 => 30,
|
||||
>= 1000 => 20,
|
||||
>= 500 => 10,
|
||||
>= 2000 => 20,
|
||||
>= 1000 => 10,
|
||||
>= 500 => 5,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@ public partial class Permissions
|
|||
{
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(page);
|
||||
|
||||
var list = await _service.GetBlacklist(type);
|
||||
var allItems = await list
|
||||
var list = _service.GetBlacklist();
|
||||
var allItems = await list.Where(x => x.Type == type)
|
||||
.Select(i =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return Task.FromResult(type switch
|
||||
return Task.FromResult(i.Type switch
|
||||
{
|
||||
BlacklistType.Channel => Format.Code(i.ItemId.ToString())
|
||||
+ " "
|
||||
|
@ -67,7 +67,7 @@ public partial class Permissions
|
|||
|
||||
return _sender.CreateEmbed()
|
||||
.WithTitle(title)
|
||||
.WithDescription(pageItems.Join('\n'))
|
||||
.WithDescription(allItems.Join('\n'))
|
||||
.WithOkColor();
|
||||
})
|
||||
.SendAsync();
|
||||
|
|
|
@ -18,9 +18,6 @@ public sealed class YoutubeDataApiSearchService : IYoutubeSearchService, IEServi
|
|||
if (results.Count == 0)
|
||||
return null;
|
||||
|
||||
return results.Map(r => new VideoInfo()
|
||||
{
|
||||
Url = r
|
||||
});
|
||||
return results.Map(r => new VideoInfo(r));
|
||||
}
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
#nullable disable
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Db.Models;
|
||||
using System.Collections.Frozen;
|
||||
|
||||
namespace EllieBot.Modules.Searches;
|
||||
|
||||
public sealed partial class FlagTranslateService : IReadyExecutor, IEService
|
||||
{
|
||||
private readonly IBotCreds _creds;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly TranslateService _ts;
|
||||
private readonly IMessageSenderService _sender;
|
||||
private IReadOnlyDictionary<string, string> _supportedFlags;
|
||||
private readonly DbService _db;
|
||||
private ConcurrentHashSet<ulong> _enabledChannels;
|
||||
private readonly IBotCache _cache;
|
||||
|
||||
// disallow same message being translated multiple times to the same language
|
||||
private readonly ConcurrentHashSet<(ulong, string)> _msgLangs = new();
|
||||
|
||||
public FlagTranslateService(
|
||||
IBotCreds creds,
|
||||
DiscordSocketClient client,
|
||||
TranslateService ts,
|
||||
IMessageSenderService sender,
|
||||
DbService db,
|
||||
IBotCache cache)
|
||||
{
|
||||
_creds = creds;
|
||||
_client = client;
|
||||
_ts = ts;
|
||||
_sender = sender;
|
||||
_db = db;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
_supportedFlags = COUNTRIES
|
||||
.Split('\n')
|
||||
.Select(x => x.Split(' '))
|
||||
.ToDictionary(x => x[0], x => x[1].TrimEnd())
|
||||
.ToFrozenDictionary();
|
||||
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
_enabledChannels = (await uow.GetTable<FlagTranslateChannel>()
|
||||
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId,
|
||||
_creds.TotalShards,
|
||||
_client.ShardId))
|
||||
.Select(x => new
|
||||
{
|
||||
x.ChannelId,
|
||||
x.GuildId
|
||||
})
|
||||
.ToListAsyncLinqToDB())
|
||||
.Select(x => x.ChannelId)
|
||||
.ToHashSet()
|
||||
.ToConcurrentSet();
|
||||
}
|
||||
|
||||
_client.ReactionAdded += OnReactionAdded;
|
||||
|
||||
var periodicCleanup = new PeriodicTimer(TimeSpan.FromHours(24));
|
||||
|
||||
while (await periodicCleanup.WaitForNextTickAsync())
|
||||
{
|
||||
_msgLangs.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private const int FLAG_START = 127462;
|
||||
|
||||
private static TypedKey<bool> CdKey(ulong userId)
|
||||
=> new($"flagtranslate:{userId}");
|
||||
|
||||
private Task OnReactionAdded(
|
||||
Cacheable<IUserMessage, ulong> arg1,
|
||||
Cacheable<IMessageChannel, ulong> arg2,
|
||||
SocketReaction reaction)
|
||||
{
|
||||
if (!_enabledChannels.Contains(reaction.Channel.Id))
|
||||
return Task.CompletedTask;
|
||||
|
||||
var runes = reaction.Emote.Name.EnumerateRunes();
|
||||
if (!runes.MoveNext()
|
||||
|| runes.Current is not { Value: >= 127462 and <= 127487 } l1
|
||||
|| !runes.MoveNext()
|
||||
|| runes.Current is not { Value: >= 127462 and <= 127487 } l2)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
if (reaction.Channel is not SocketTextChannel tc)
|
||||
return;
|
||||
|
||||
var user = await ((IGuild)tc.Guild).GetUserAsync(reaction.UserId);
|
||||
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
if (!user.GetPermissions(tc).SendMessages)
|
||||
return;
|
||||
|
||||
if (!tc.Guild.CurrentUser.GetPermissions(tc).SendMessages
|
||||
|| !tc.Guild.CurrentUser.GetPermissions(tc).EmbedLinks)
|
||||
{
|
||||
await Disable(tc.Guild.Id, tc.Id);
|
||||
return;
|
||||
}
|
||||
|
||||
var c1 = (char)(l1.Value - FLAG_START + 65);
|
||||
var c2 = (char)(l2.Value - FLAG_START + 65);
|
||||
|
||||
var code = $"{c1}{c2}".ToUpper();
|
||||
|
||||
if (!_supportedFlags.TryGetValue(code, out var lang))
|
||||
return;
|
||||
|
||||
if (!_msgLangs.Add((reaction.MessageId, lang)))
|
||||
return;
|
||||
|
||||
var result = await _cache.GetAsync(CdKey(reaction.UserId));
|
||||
if (result.TryPickT0(out _, out _))
|
||||
return;
|
||||
|
||||
await _cache.AddAsync(CdKey(reaction.UserId), true, TimeSpan.FromSeconds(5));
|
||||
|
||||
var msg = await arg1.GetOrDownloadAsync();
|
||||
|
||||
var response = await _ts.Translate("", lang, msg.Content).ConfigureAwait(false);
|
||||
|
||||
await msg.ReplyAsync(embed: _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithFooter(user.ToString() ?? reaction.UserId.ToString(),
|
||||
user.RealAvatarUrl().ToString())
|
||||
.WithDescription(response)
|
||||
.WithAuthor(reaction.Emote.ToString())
|
||||
.Build(),
|
||||
allowedMentions: AllowedMentions.None
|
||||
);
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task Disable(ulong guildId, ulong tcId)
|
||||
{
|
||||
if (!_enabledChannels.TryRemove(tcId))
|
||||
return;
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<FlagTranslateChannel>()
|
||||
.Where(x => x.GuildId == guildId
|
||||
&& x.ChannelId == tcId)
|
||||
.DeleteAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> Toggle(ulong guildId, ulong tcId)
|
||||
{
|
||||
if (_enabledChannels.Contains(tcId))
|
||||
{
|
||||
await Disable(guildId, tcId);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
await Enable(guildId, tcId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task Enable(ulong guildId, ulong tcId)
|
||||
{
|
||||
if (!_enabledChannels.Add(tcId))
|
||||
return;
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<FlagTranslateChannel>()
|
||||
.InsertAsync(() => new FlagTranslateChannel
|
||||
{
|
||||
GuildId = guildId,
|
||||
ChannelId = tcId
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
namespace EllieBot.Modules.Searches;
|
||||
|
||||
public partial class FlagTranslateService
|
||||
{
|
||||
private const string COUNTRIES = """
|
||||
CN zh
|
||||
IN hi
|
||||
US en
|
||||
ID id
|
||||
PK ur
|
||||
BR pt
|
||||
NG ha
|
||||
BD bn
|
||||
RU ru
|
||||
JP ja
|
||||
MX es
|
||||
PH tl
|
||||
VN vi
|
||||
EG ar
|
||||
ET am
|
||||
DE de
|
||||
IR fa
|
||||
TR tr
|
||||
TH th
|
||||
FR fr
|
||||
CD fr
|
||||
MM my
|
||||
UG en
|
||||
MZ pt
|
||||
ZA zu
|
||||
CO es
|
||||
BG bg
|
||||
HR hr
|
||||
MY ms
|
||||
NL nl
|
||||
RO ro
|
||||
CZ cs
|
||||
GR el
|
||||
SK sk
|
||||
PT pt
|
||||
KR ko
|
||||
IT it
|
||||
ES es
|
||||
RS sr
|
||||
TN ar
|
||||
PL pl
|
||||
SD ar
|
||||
CM fr
|
||||
SN fr
|
||||
ML fr
|
||||
NE ha
|
||||
BI fr
|
||||
AO pt
|
||||
AF ps
|
||||
MA ar
|
||||
DZ ar
|
||||
GB en
|
||||
AR es
|
||||
ZW ny
|
||||
KE sw
|
||||
GH en
|
||||
SA ar
|
||||
IL he
|
||||
IQ ar
|
||||
UA ua
|
||||
LY ar
|
||||
KW ar
|
||||
OM ar
|
||||
YE ar
|
||||
AL sq
|
||||
AE ar
|
||||
AU en
|
||||
NZ en
|
||||
KZ kz
|
||||
NO no
|
||||
SE sv
|
||||
DK da
|
||||
FI fi
|
||||
HU hu
|
||||
""";
|
||||
}
|
|
@ -44,10 +44,12 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
|
|||
foreach (var c in cs)
|
||||
{
|
||||
_atcs[c.ChannelId] = c.AutoDelete;
|
||||
_users[c.ChannelId] = new(c.Users.ToDictionary(x => x.UserId, x => (x.Source.ToLower(), x.Target.ToLower())));
|
||||
_users[c.ChannelId] =
|
||||
new(c.Users.ToDictionary(x => x.UserId, x => (x.Source.ToLower(), x.Target.ToLower())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(msg.Content))
|
||||
|
@ -93,7 +95,7 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<string> Translate(string source, string target, string text)
|
||||
public async Task<string> Translate(string source, string target, string text = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
throw new ArgumentException("Text is empty or null", nameof(text));
|
||||
|
|
|
@ -6,14 +6,6 @@ public partial class Searches
|
|||
[Group]
|
||||
public partial class TranslateCommands : EllieModule<ITranslateService>
|
||||
{
|
||||
private readonly FlagTranslateService _flagSvc;
|
||||
|
||||
public TranslateCommands(FlagTranslateService flagSvc)
|
||||
{
|
||||
_flagSvc = flagSvc;
|
||||
}
|
||||
|
||||
|
||||
public enum AutoDeleteAutoTranslate
|
||||
{
|
||||
Del,
|
||||
|
@ -99,18 +91,5 @@ public partial class Searches
|
|||
|
||||
await Response().Embed(eb).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(ChannelPermission.ManageChannels)]
|
||||
[BotPerm(ChannelPermission.SendMessages | ChannelPermission.EmbedLinks)]
|
||||
public async Task TranslateFlags()
|
||||
{
|
||||
var enabled = await _flagSvc.Toggle(ctx.Guild.Id, ctx.Channel.Id);
|
||||
if (enabled)
|
||||
await Response().Confirm(strs.trfl_enabled).SendAsync();
|
||||
else
|
||||
await Response().Confirm(strs.trfl_disabled).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -783,28 +783,4 @@ public partial class Utility : EllieModule
|
|||
await Response().Error(ex.Message).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task Snipe()
|
||||
{
|
||||
if (ctx.Message.ReferencedMessage is not { } msg)
|
||||
{
|
||||
var msgs = await ctx.Channel.GetMessagesAsync(ctx.Message, Direction.Before, 3).FlattenAsync();
|
||||
msg = msgs.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x.Content) || (x.Attachments.FirstOrDefault()?.Width is not null)) as IUserMessage;
|
||||
|
||||
if (msg is null)
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _sender.CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithDescription(msg.Content)
|
||||
.WithAuthor(msg.Author)
|
||||
.WithTimestamp(msg.Timestamp)
|
||||
.WithImageUrl(msg.Attachments.FirstOrDefault()?.Url)
|
||||
.WithFooter(GetText(strs.sniped_by(ctx.User.ToString())), ctx.User.GetDisplayAvatarUrl());
|
||||
|
||||
ctx.Message.DeleteAfter(1);
|
||||
await Response().Embed(eb).SendAsync();
|
||||
}
|
||||
}
|
|
@ -225,7 +225,7 @@ public partial class Xp : EllieModule<XpService>
|
|||
else if (userXpData.AwardedXp < 0)
|
||||
awardStr = $"({userXpData.AwardedXp})";
|
||||
|
||||
embed.AddField($"#{i + 1 + (curPage * 10)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||
$"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}");
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ public partial class Xp : EllieModule<XpService>
|
|||
for (var i = 0; i < users.Count; i++)
|
||||
{
|
||||
var user = users[i];
|
||||
embed.AddField($"#{i + 1 + (curPage * 10)} {user}",
|
||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user}",
|
||||
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ public partial class Xp : EllieModule<XpService>
|
|||
if (!await PromptUserConfirmAsync(embed))
|
||||
return;
|
||||
|
||||
await _service.XpReset(ctx.Guild.Id, userId);
|
||||
_service.XpReset(ctx.Guild.Id, userId);
|
||||
|
||||
await Response().Confirm(strs.reset_user(userId)).SendAsync();
|
||||
}
|
||||
|
|
|
@ -20,31 +20,6 @@ using Image = SixLabors.ImageSharp.Image;
|
|||
|
||||
namespace EllieBot.Modules.Xp.Services;
|
||||
|
||||
public interface IUserService
|
||||
{
|
||||
Task<DiscordUser?> GetUserAsync(ulong userId);
|
||||
}
|
||||
|
||||
public sealed class UserService : IUserService, IEService
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
||||
public UserService(DbService db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<DiscordUser> GetUserAsync(ulong userId)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var user = await uow
|
||||
.GetTable<DiscordUser>()
|
||||
.FirstOrDefaultAsyncLinqToDB(u => u.UserId == userId);
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
||||
{
|
||||
private readonly DbService _db;
|
||||
|
@ -1462,11 +1437,11 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
}
|
||||
}
|
||||
|
||||
public async Task XpReset(ulong guildId, ulong userId)
|
||||
public void XpReset(ulong guildId, ulong userId)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<UserXpStats>()
|
||||
.DeleteAsync(x => x.UserId == userId && x.GuildId == guildId);
|
||||
using var uow = _db.GetDbContext();
|
||||
uow.Set<UserXpStats>().ResetGuildUserXp(userId, guildId);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
public void XpReset(ulong guildId)
|
||||
|
@ -1662,15 +1637,6 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
|
||||
public bool IsShopEnabled()
|
||||
=> _xpConfig.Data.Shop.IsEnabled;
|
||||
|
||||
public async Task<int> GetTotalGuildUsers(ulong requestGuildId, List<ulong>? guildUsers = null)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
return await ctx.GetTable<UserXpStats>()
|
||||
.Where(x => x.GuildId == requestGuildId
|
||||
&& (guildUsers == null || guildUsers.Contains(x.UserId)))
|
||||
.CountAsyncLinqToDB();
|
||||
}
|
||||
}
|
||||
|
||||
public enum BuyResult
|
||||
|
|
|
@ -22,6 +22,9 @@ public class ExprsSvc : GrpcExprs.GrpcExprsBase, IGrpcSvc, IEService
|
|||
public ServerServiceDefinition Bind()
|
||||
=> GrpcExprs.BindService(this);
|
||||
|
||||
private ulong GetUserId(Metadata meta)
|
||||
=> ulong.Parse(meta.FirstOrDefault(x => x.Key == "userid")!.Value);
|
||||
|
||||
public override async Task<AddExprReply> AddExpr(AddExprRequest request, ServerCallContext context)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Expr.Trigger) || string.IsNullOrWhiteSpace(request.Expr.Response))
|
||||
|
@ -106,7 +109,7 @@ public class ExprsSvc : GrpcExprs.GrpcExprsBase, IGrpcSvc, IEService
|
|||
|
||||
public override async Task<AddQuoteReply> AddQuote(AddQuoteRequest request, ServerCallContext context)
|
||||
{
|
||||
var userId = context.RequestHeaders.GetUserId();
|
||||
var userId = GetUserId(context.RequestHeaders);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(request.Quote.Trigger) || string.IsNullOrWhiteSpace(request.Quote.Response))
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Trigger and response are required"));
|
||||
|
@ -143,7 +146,7 @@ public class ExprsSvc : GrpcExprs.GrpcExprsBase, IGrpcSvc, IEService
|
|||
|
||||
public override async Task<Empty> DeleteQuote(DeleteQuoteRequest request, ServerCallContext context)
|
||||
{
|
||||
await _qs.DeleteQuoteAsync(request.GuildId, context.RequestHeaders.GetUserId(), true, new kwum(request.Id));
|
||||
await _qs.DeleteQuoteAsync(request.GuildId, GetUserId(context.RequestHeaders), true, new kwum(request.Id));
|
||||
return new Empty();
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using EllieBot.Db.Models;
|
||||
using EllieBot.Modules.Gambling.Bank;
|
||||
using EllieBot.Modules.EllieExpressions;
|
||||
using EllieBot.Modules.Utility;
|
||||
|
||||
namespace EllieBot.GrpcApi;
|
||||
|
||||
public class FinSvc : GrpcFin.GrpcFinBase, IGrpcSvc, IEService
|
||||
{
|
||||
private readonly ICurrencyService _cs;
|
||||
private readonly IBankService _bank;
|
||||
|
||||
public FinSvc(ICurrencyService cs, IBankService bank)
|
||||
{
|
||||
_cs = cs;
|
||||
_bank = bank;
|
||||
}
|
||||
|
||||
public ServerServiceDefinition Bind()
|
||||
=> GrpcFin.BindService(this);
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<DepositReply> Deposit(DepositRequest request, ServerCallContext context)
|
||||
{
|
||||
if (request.Amount <= 0)
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Amount must be greater than 0"));
|
||||
|
||||
var succ = await _bank.DepositAsync(request.UserId, request.Amount);
|
||||
|
||||
return new DepositReply
|
||||
{
|
||||
Success = succ
|
||||
};
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<WithdrawReply> Withdraw(WithdrawRequest request, ServerCallContext context)
|
||||
{
|
||||
if (request.Amount <= 0)
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Amount must be greater than 0"));
|
||||
|
||||
var succ = await _bank.WithdrawAsync(request.UserId, request.Amount);
|
||||
|
||||
return new WithdrawReply
|
||||
{
|
||||
Success = succ
|
||||
};
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<GetHoldingsReply> GetHoldings(GetHoldingsRequest request, ServerCallContext context)
|
||||
{
|
||||
return new GetHoldingsReply
|
||||
{
|
||||
Bank = await _bank.GetBalanceAsync(request.UserId),
|
||||
Cash = await _cs.GetBalanceAsync(request.UserId)
|
||||
};
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<GetTransactionsReply> GetTransactions(
|
||||
GetTransactionsRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
if (request.Page < 1)
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Page must be greater than 0"));
|
||||
|
||||
var trs = await _cs.GetTransactionsAsync(request.UserId, request.Page - 1);
|
||||
|
||||
var reply = new GetTransactionsReply
|
||||
{
|
||||
Total = await _cs.GetTransactionsCountAsync(request.UserId)
|
||||
};
|
||||
|
||||
reply.Transactions.AddRange(trs.Select(x => new TransactionReply()
|
||||
{
|
||||
Id = new kwum(x.Id).ToString(),
|
||||
Timestamp = Timestamp.FromDateTime(DateTime.UtcNow),
|
||||
Amount = x.Amount,
|
||||
Extra = x.Extra ?? string.Empty,
|
||||
Note = x.Note ?? string.Empty,
|
||||
Type = x.Type ?? string.Empty,
|
||||
}));
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
|
@ -17,13 +17,10 @@ public sealed class GreetByeSvc : GrpcGreet.GrpcGreetBase, IGrpcSvc, IEService
|
|||
public ServerServiceDefinition Bind()
|
||||
=> GrpcGreet.BindService(this);
|
||||
|
||||
private static GrpcGreetSettings ToConf(GreetSettings? conf, GreetType type)
|
||||
private static GrpcGreetSettings ToConf(GreetSettings? conf)
|
||||
{
|
||||
if (conf is null)
|
||||
return new GrpcGreetSettings()
|
||||
{
|
||||
Type = (GrpcGreetType)type
|
||||
};
|
||||
return new GrpcGreetSettings();
|
||||
|
||||
return new GrpcGreetSettings()
|
||||
{
|
||||
|
@ -38,10 +35,9 @@ public sealed class GreetByeSvc : GrpcGreet.GrpcGreetBase, IGrpcSvc, IEService
|
|||
{
|
||||
var guildId = request.GuildId;
|
||||
|
||||
var type = (GreetType)request.Type;
|
||||
var conf = await _gs.GetGreetSettingsAsync(guildId, type);
|
||||
var conf = await _gs.GetGreetSettingsAsync(guildId, (GreetType)request.Type);
|
||||
|
||||
return ToConf(conf, type);
|
||||
return ToConf(conf);
|
||||
}
|
||||
|
||||
public override async Task<UpdateGreetReply> UpdateGreet(UpdateGreetRequest request, ServerCallContext context)
|
||||
|
|
|
@ -1,95 +0,0 @@
|
|||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using EllieBot.Db.Models;
|
||||
using EllieBot.Modules.Games;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace EllieBot.GrpcApi;
|
||||
|
||||
public class NCanvasSvc : GrpcNCanvas.GrpcNCanvasBase, IGrpcSvc, IEService
|
||||
{
|
||||
private readonly INCanvasService _nCanvas;
|
||||
private readonly DiscordSocketClient _client;
|
||||
|
||||
public NCanvasSvc(INCanvasService nCanvas, DiscordSocketClient client)
|
||||
{
|
||||
_nCanvas = nCanvas;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public ServerServiceDefinition Bind()
|
||||
=> GrpcNCanvas.BindService(this);
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<CanvasReply> GetCanvas(Empty request, ServerCallContext context)
|
||||
{
|
||||
var pixels = await _nCanvas.GetCanvas();
|
||||
var reply = new CanvasReply()
|
||||
{
|
||||
Width = _nCanvas.GetWidth(),
|
||||
Height = _nCanvas.GetHeight()
|
||||
};
|
||||
reply.Pixels.AddRange(pixels);
|
||||
return reply;
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<GetPixelReply> GetPixel(GetPixelRequest request, ServerCallContext context)
|
||||
{
|
||||
var pixel = await _nCanvas.GetPixel(request.X, request.Y);
|
||||
if (pixel is null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "Pixel not found"));
|
||||
|
||||
var reply = MapPixelToGrpcPixel(pixel);
|
||||
return reply;
|
||||
}
|
||||
|
||||
private GetPixelReply MapPixelToGrpcPixel(NCPixel pixel)
|
||||
{
|
||||
var reply = new GetPixelReply
|
||||
{
|
||||
Color = "#" + new Rgba32(pixel.Color).ToHex(),
|
||||
PackedColor = pixel.Color,
|
||||
Position = new kwum(pixel.Position).ToString(),
|
||||
PositionX = pixel.Position % _nCanvas.GetWidth(),
|
||||
PositionY = pixel.Position / _nCanvas.GetWidth(),
|
||||
// Owner = await ((IDiscordClient)_client).GetUserAsync(pixel.OwnerId)?.ToString() ?? string.Empty,
|
||||
// OwnerId = pixel.OwnerId.ToString(),
|
||||
Price = pixel.Price,
|
||||
Text = pixel.Text
|
||||
};
|
||||
return reply;
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<SetPixelReply> SetPixel(SetPixelRequest request, ServerCallContext context)
|
||||
{
|
||||
if (!kwum.TryParse(request.Position, out var pos))
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Position is invalid"));
|
||||
|
||||
if (!Rgba32.TryParseHex(request.Color, out var clr))
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Color is invalid"));
|
||||
|
||||
var userId = context.RequestHeaders.GetUserId();
|
||||
var result = await _nCanvas.SetPixel(pos, clr.PackedValue, request.Text, userId, request.Price);
|
||||
var reply = new SetPixelReply()
|
||||
{
|
||||
Success = result == SetPixelResult.Success,
|
||||
Error = result switch
|
||||
{
|
||||
SetPixelResult.Success => string.Empty,
|
||||
SetPixelResult.InsufficientPayment => "You have to pay equal or more than the price.",
|
||||
SetPixelResult.NotEnoughMoney => "You don't have enough currency. ",
|
||||
SetPixelResult.InvalidInput =>
|
||||
$"Invalid input. Position has to be >= 0 and < {_nCanvas.GetWidth()}x{_nCanvas.GetHeight()}",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}
|
||||
};
|
||||
|
||||
var pixel = await _nCanvas.GetPixel(pos);
|
||||
if (pixel is not null)
|
||||
reply.Pixel = MapPixelToGrpcPixel(pixel);
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
|
@ -13,48 +13,51 @@ public static class GrpcApiExtensions
|
|||
|
||||
public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IGrpcSvc, IEService
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IDiscordClient _client;
|
||||
private readonly XpService _xp;
|
||||
private readonly ICurrencyService _cur;
|
||||
private readonly WaifuService _waifus;
|
||||
private readonly ICoordinator _coord;
|
||||
private readonly IStatsService _stats;
|
||||
private readonly CommandHandler _cmdHandler;
|
||||
private readonly IBotCache _cache;
|
||||
|
||||
public OtherSvc(
|
||||
DiscordSocketClient client,
|
||||
XpService xp,
|
||||
ICurrencyService cur,
|
||||
WaifuService waifus,
|
||||
ICoordinator coord,
|
||||
IStatsService stats,
|
||||
CommandHandler cmdHandler)
|
||||
IBotCache cache)
|
||||
{
|
||||
_client = client;
|
||||
_xp = xp;
|
||||
_cur = cur;
|
||||
_waifus = waifus;
|
||||
_coord = coord;
|
||||
_stats = stats;
|
||||
_cmdHandler = cmdHandler;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
public ServerServiceDefinition Bind()
|
||||
=> GrpcOther.BindService(this);
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override Task<BotOnGuildReply> BotOnGuild(BotOnGuildRequest request, ServerCallContext context)
|
||||
public override async Task<BotOnGuildReply> BotOnGuild(BotOnGuildRequest request, ServerCallContext context)
|
||||
{
|
||||
var guild = _client.GetGuild(request.GuildId);
|
||||
var guild = await _client.GetGuildAsync(request.GuildId);
|
||||
|
||||
var reply = new BotOnGuildReply
|
||||
{
|
||||
Success = guild is not null
|
||||
};
|
||||
|
||||
return Task.FromResult(reply);
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override Task<GetRolesReply> GetRoles(GetRolesRequest request, ServerCallContext context)
|
||||
public override async Task<GetRolesReply> GetRoles(GetRolesRequest request, ServerCallContext context)
|
||||
{
|
||||
var g = _client.GetGuild(request.GuildId);
|
||||
var g = await _client.GetGuildAsync(request.GuildId);
|
||||
var roles = g?.Roles;
|
||||
var reply = new GetRolesReply();
|
||||
reply.Roles.AddRange(roles?.Select(x => new RoleReply()
|
||||
|
@ -63,17 +66,16 @@ public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IGrpcSvc, IEService
|
|||
Name = x.Name,
|
||||
Color = x.Color.ToString(),
|
||||
IconUrl = x.GetIconUrl() ?? string.Empty,
|
||||
})
|
||||
?? new List<RoleReply>());
|
||||
}) ?? new List<RoleReply>());
|
||||
|
||||
return Task.FromResult(reply);
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override async Task<GetTextChannelsReply> GetTextChannels(
|
||||
GetTextChannelsRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
IGuild g = _client.GetGuild(request.GuildId);
|
||||
var g = await _client.GetGuildAsync(request.GuildId);
|
||||
var reply = new GetTextChannelsReply();
|
||||
|
||||
var chs = await g.GetTextChannelsAsync();
|
||||
|
@ -87,6 +89,33 @@ public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IGrpcSvc, IEService
|
|||
return reply;
|
||||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<GetGuildsReply> GetGuilds(Empty request, ServerCallContext context)
|
||||
{
|
||||
var guilds = await _client.GetGuildsAsync(CacheMode.CacheOnly);
|
||||
|
||||
var reply = new GetGuildsReply();
|
||||
var userId = context.GetUserId();
|
||||
|
||||
var toReturn = new List<IGuild>();
|
||||
foreach (var g in guilds)
|
||||
{
|
||||
var user = await g.GetUserAsync(userId);
|
||||
if (user is not null && user.GuildPermissions.Has(GuildPermission.Administrator))
|
||||
toReturn.Add(g);
|
||||
}
|
||||
|
||||
reply.Guilds.AddRange(toReturn
|
||||
.Select(x => new GuildReply()
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
IconUrl = x.IconUrl
|
||||
}));
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task<CurrencyLbReply> GetCurrencyLb(GetLbRequest request, ServerCallContext context)
|
||||
|
@ -94,16 +123,16 @@ public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IGrpcSvc, IEService
|
|||
var users = await _cur.GetTopRichest(_client.CurrentUser.Id, request.Page, request.PerPage);
|
||||
|
||||
var reply = new CurrencyLbReply();
|
||||
var entries = users.Select(x =>
|
||||
var entries = users.Select(async x =>
|
||||
{
|
||||
var user = _client.GetUser(x.UserId);
|
||||
return Task.FromResult(new CurrencyLbEntryReply()
|
||||
var user = await _client.GetUserAsync(x.UserId, CacheMode.CacheOnly);
|
||||
return new CurrencyLbEntryReply()
|
||||
{
|
||||
Amount = x.CurrencyAmount,
|
||||
User = user?.ToString() ?? x.Username,
|
||||
UserId = x.UserId,
|
||||
Avatar = user?.RealAvatarUrl().ToString() ?? x.RealAvatarUrl()?.ToString()
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
reply.Entries.AddRange(await entries.WhenAll());
|
||||
|
@ -153,66 +182,26 @@ public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IGrpcSvc, IEService
|
|||
}
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task GetShardStats(
|
||||
Empty request,
|
||||
IServerStreamWriter<ShardStatsReply> responseStream,
|
||||
ServerCallContext context)
|
||||
public override async Task<GetShardStatusesReply> GetShardStatuses(Empty request, ServerCallContext context)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var stats = new ShardStatsReply()
|
||||
{
|
||||
Id = _client.ShardId,
|
||||
Commands = _stats.CommandsRan,
|
||||
Uptime = _stats.GetUptimeString(),
|
||||
Status = GetConnectionState(_client.ConnectionState),
|
||||
GuildCount = _client.Guilds.Count,
|
||||
};
|
||||
var reply = new GetShardStatusesReply();
|
||||
|
||||
await responseStream.WriteAsync(stats);
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
await _cache.GetOrAddAsync<List<ShardStatus>>("coord:statuses",
|
||||
() => Task.FromResult(_coord.GetAllShardStatuses().ToList())!,
|
||||
TimeSpan.FromMinutes(1));
|
||||
|
||||
[GrpcNoAuthRequired]
|
||||
public override async Task GetCommandFeed(
|
||||
Empty request,
|
||||
IServerStreamWriter<CommandFeedEntry> responseStream,
|
||||
ServerCallContext context)
|
||||
{
|
||||
var taskCompletion = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var shards = _coord.GetAllShardStatuses();
|
||||
|
||||
Task OnCommandExecuted(IUserMessage userMessage, CommandInfo commandInfo)
|
||||
reply.Shards.AddRange(shards.Select(x => new ShardStatusReply()
|
||||
{
|
||||
try
|
||||
{
|
||||
responseStream.WriteAsync(new()
|
||||
{
|
||||
Command = commandInfo.Name
|
||||
});
|
||||
}
|
||||
catch
|
||||
{
|
||||
_cmdHandler.CommandExecuted -= OnCommandExecuted;
|
||||
taskCompletion.TrySetResult(true);
|
||||
}
|
||||
Id = x.ShardId,
|
||||
Status = x.ConnectionState.ToString(),
|
||||
GuildCount = x.GuildCount,
|
||||
LastUpdate = Timestamp.FromDateTime(x.LastUpdate),
|
||||
}));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
_cmdHandler.CommandExecuted += OnCommandExecuted;
|
||||
|
||||
await taskCompletion.Task;
|
||||
}
|
||||
|
||||
private string GetConnectionState(ConnectionState clientConnectionState)
|
||||
{
|
||||
return clientConnectionState switch
|
||||
{
|
||||
ConnectionState.Connected => "Connected",
|
||||
ConnectionState.Connecting => "Connecting",
|
||||
_ => "Disconnected"
|
||||
};
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override async Task<GetServerInfoReply> GetServerInfo(ServerInfoRequest request, ServerCallContext context)
|
||||
|
|
|
@ -1,282 +0,0 @@
|
|||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using EllieBot.Db.Models;
|
||||
using EllieBot.Modules.Gambling.Bank;
|
||||
using EllieBot.Modules.EllieExpressions;
|
||||
using EllieBot.Modules.Utility;
|
||||
using EllieBot.Modules.Xp.Services;
|
||||
|
||||
namespace EllieBot.GrpcApi;
|
||||
|
||||
public class XpSvc : GrpcXp.GrpcXpBase, IGrpcSvc, IEService
|
||||
{
|
||||
private readonly XpService _xp;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IUserService _duSvc;
|
||||
|
||||
public XpSvc(XpService xp, DiscordSocketClient client, IUserService duSvc)
|
||||
{
|
||||
_xp = xp;
|
||||
_client = client;
|
||||
_duSvc = duSvc;
|
||||
}
|
||||
|
||||
public ServerServiceDefinition Bind()
|
||||
=> GrpcXp.BindService(this);
|
||||
|
||||
public override async Task<GetXpSettingsReply> GetXpSettings(
|
||||
GetXpSettingsRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var guild = _client.GetGuild(request.GuildId);
|
||||
|
||||
if (guild is null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "Guild not found"));
|
||||
|
||||
var excludedChannels = _xp.GetExcludedChannels(request.GuildId);
|
||||
var excludedRoles = _xp.GetExcludedRoles(request.GuildId);
|
||||
var isServerExcluded = _xp.IsServerExcluded(request.GuildId);
|
||||
|
||||
var reply = new GetXpSettingsReply();
|
||||
|
||||
reply.Exclusions.AddRange(excludedChannels
|
||||
.Select(x => new ExclItemReply()
|
||||
{
|
||||
Id = x,
|
||||
Type = "Channel",
|
||||
Name = guild.GetChannel(x)?.Name ?? "????"
|
||||
})
|
||||
.Concat(excludedRoles
|
||||
.Select(x => new ExclItemReply()
|
||||
{
|
||||
Id = x,
|
||||
Type = "Role",
|
||||
Name = guild.GetRole(x)?.Name ?? "????"
|
||||
})));
|
||||
|
||||
var curRews = _xp.GetCurrencyRewards(request.GuildId);
|
||||
var roleRews = _xp.GetRoleRewards(request.GuildId);
|
||||
|
||||
var rews = curRews.Select(x => new RewItemReply()
|
||||
{
|
||||
Level = x.Level,
|
||||
Type = "Currency",
|
||||
Value = x.Amount.ToString()
|
||||
});
|
||||
|
||||
rews = rews.Concat(roleRews.Select(x => new RewItemReply()
|
||||
{
|
||||
Level = x.Level,
|
||||
Type = x.Remove ? "RemoveRole" : "AddRole",
|
||||
Value = guild.GetRole(x.RoleId)?.ToString() ?? x.RoleId.ToString()
|
||||
}))
|
||||
.OrderBy(x => x.Level);
|
||||
|
||||
reply.Rewards.AddRange(rews);
|
||||
|
||||
reply.ServerExcluded = isServerExcluded;
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override async Task<AddExclusionReply> AddExclusion(AddExclusionRequest request, ServerCallContext context)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var success = false;
|
||||
var guild = _client.GetGuild(request.GuildId);
|
||||
|
||||
if (guild is null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "Guild not found"));
|
||||
|
||||
if (request.Type == "Role")
|
||||
{
|
||||
if (guild.GetRole(request.Id) is null)
|
||||
return new()
|
||||
{
|
||||
Success = false
|
||||
};
|
||||
|
||||
success = _xp.ToggleExcludeRole(request.GuildId, request.Id);
|
||||
}
|
||||
else if (request.Type == "Channel")
|
||||
{
|
||||
if (guild.GetTextChannel(request.Id) is null)
|
||||
return new()
|
||||
{
|
||||
Success = false
|
||||
};
|
||||
|
||||
success = _xp.ToggleExcludeChannel(request.GuildId, request.Id);
|
||||
}
|
||||
|
||||
return new()
|
||||
{
|
||||
Success = success
|
||||
};
|
||||
}
|
||||
|
||||
public override Task<DeleteExclusionReply> DeleteExclusion(
|
||||
DeleteExclusionRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
var success = false;
|
||||
if (request.Type == "Role")
|
||||
success = _xp.ToggleExcludeRole(request.GuildId, request.Id);
|
||||
else
|
||||
success = _xp.ToggleExcludeChannel(request.GuildId, request.Id);
|
||||
|
||||
return Task.FromResult(new DeleteExclusionReply
|
||||
{
|
||||
Success = success
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task<AddRewardReply> AddReward(AddRewardRequest request, ServerCallContext context)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var success = false;
|
||||
var guild = _client.GetGuild(request.GuildId);
|
||||
|
||||
if (guild is null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "Guild not found"));
|
||||
|
||||
if (request.Type == "AddRole" || request.Type == "RemoveRole")
|
||||
{
|
||||
if (!ulong.TryParse(request.Value, out var rid))
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid role id"));
|
||||
|
||||
var role = guild.GetRole(rid);
|
||||
if (role is null)
|
||||
return new()
|
||||
{
|
||||
Success = false
|
||||
};
|
||||
|
||||
_xp.SetRoleReward(request.GuildId, request.Level, rid, request.Type == "RemoveRole");
|
||||
success = true;
|
||||
}
|
||||
// else if (request.Type == "Currency")
|
||||
// {
|
||||
// if (!int.TryParse(request.Value, out var amount))
|
||||
// throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid amount"));
|
||||
//
|
||||
// _xp.SetCurrencyReward(request.GuildId, request.Level, amount);
|
||||
// success = true;
|
||||
// }
|
||||
|
||||
return new()
|
||||
{
|
||||
Success = success
|
||||
};
|
||||
}
|
||||
|
||||
public override Task<DeleteRewardReply> DeleteReward(DeleteRewardRequest request, ServerCallContext context)
|
||||
{
|
||||
var success = false;
|
||||
|
||||
if (request.Type == "AddRole" || request.Type == "RemoveRole")
|
||||
{
|
||||
_xp.ResetRoleReward(request.GuildId, request.Level);
|
||||
success = true;
|
||||
}
|
||||
else if (request.Type == "Currency")
|
||||
{
|
||||
_xp.SetCurrencyReward(request.GuildId, request.Level, 0);
|
||||
success = true;
|
||||
}
|
||||
|
||||
return Task.FromResult(new DeleteRewardReply
|
||||
{
|
||||
Success = success
|
||||
});
|
||||
}
|
||||
|
||||
public override async Task<ResetUserXpReply> ResetUserXp(ResetUserXpRequest request, ServerCallContext context)
|
||||
{
|
||||
await _xp.XpReset(request.GuildId, request.UserId);
|
||||
|
||||
return new ResetUserXpReply
|
||||
{
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
|
||||
public override async Task<GetXpLbReply> GetXpLb(GetXpLbRequest request, ServerCallContext context)
|
||||
{
|
||||
if (request.Page < 1)
|
||||
throw new RpcException(new Status(StatusCode.InvalidArgument, "Page must be greater than or equal to 1"));
|
||||
|
||||
var guild = _client.GetGuild(request.GuildId);
|
||||
|
||||
if (guild is null)
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "Guild not found"));
|
||||
|
||||
var data = await _xp.GetGuildUserXps(request.GuildId, request.Page - 1);
|
||||
var total = await _xp.GetTotalGuildUsers(request.GuildId);
|
||||
|
||||
var reply = new GetXpLbReply
|
||||
{
|
||||
Total = total
|
||||
};
|
||||
|
||||
var users = await data
|
||||
.Select(async x =>
|
||||
{
|
||||
var user = guild.GetUser(x.UserId);
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
var du = await _duSvc.GetUserAsync(x.UserId);
|
||||
if (du is null)
|
||||
return new XpLbUserReply
|
||||
{
|
||||
UserId = x.UserId,
|
||||
Avatar = string.Empty,
|
||||
Username = string.Empty,
|
||||
Xp = x.Xp,
|
||||
Level = new LevelStats(x.Xp).Level
|
||||
};
|
||||
|
||||
return new XpLbUserReply()
|
||||
{
|
||||
UserId = x.UserId,
|
||||
Avatar = du.RealAvatarUrl()?.ToString() ?? string.Empty,
|
||||
Username = du.ToString() ?? string.Empty,
|
||||
Xp = x.Xp,
|
||||
Level = new LevelStats(x.Xp).Level
|
||||
};
|
||||
}
|
||||
|
||||
return new XpLbUserReply
|
||||
{
|
||||
UserId = x.UserId,
|
||||
Avatar = user?.GetAvatarUrl() ?? string.Empty,
|
||||
Username = user?.ToString() ?? string.Empty,
|
||||
Xp = x.Xp,
|
||||
Level = new LevelStats(x.Xp).Level
|
||||
};
|
||||
})
|
||||
.WhenAll();
|
||||
|
||||
reply.Users.AddRange(users);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override async Task<SetServerExclusionReply> SetServerExclusion(
|
||||
SetServerExclusionRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
await Task.Yield();
|
||||
|
||||
var newValue = _xp.ToggleExcludeServer(request.GuildId);
|
||||
return new()
|
||||
{
|
||||
Success = newValue
|
||||
};
|
||||
}
|
||||
}
|
|
@ -14,7 +14,10 @@ public sealed partial class GrpcApiPermsInterceptor : Interceptor
|
|||
_client = client;
|
||||
}
|
||||
|
||||
public async Task RequestHandler(ServerCallContext context)
|
||||
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
ServerCallContext context,
|
||||
UnaryServerMethod<TRequest, TResponse> continuation)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -39,7 +42,7 @@ public sealed partial class GrpcApiPermsInterceptor : Interceptor
|
|||
|
||||
// if the method is explicitly marked as not requiring auth
|
||||
if (_noAuthRequired.Contains(method))
|
||||
return;
|
||||
return await continuation(request, context);
|
||||
|
||||
// otherwise the method requires auth, and if it requires auth then the guildid has to be specified
|
||||
if (string.IsNullOrWhiteSpace(gidString))
|
||||
|
@ -58,6 +61,8 @@ public sealed partial class GrpcApiPermsInterceptor : Interceptor
|
|||
// if not then use the default, which is Administrator permission
|
||||
await EnsureUserHasPermission(guildId, userId, DEFAULT_PERMISSION);
|
||||
}
|
||||
|
||||
return await continuation(request, context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -78,42 +83,4 @@ public sealed partial class GrpcApiPermsInterceptor : Interceptor
|
|||
throw new RpcException(new Status(StatusCode.PermissionDenied,
|
||||
$"You need {perm} permission to use this method"));
|
||||
}
|
||||
|
||||
public override async Task<TResponse> ClientStreamingServerHandler<TRequest, TResponse>(
|
||||
IAsyncStreamReader<TRequest> requestStream,
|
||||
ServerCallContext context,
|
||||
ClientStreamingServerMethod<TRequest, TResponse> continuation)
|
||||
{
|
||||
await RequestHandler(context);
|
||||
return await continuation(requestStream, context);
|
||||
}
|
||||
|
||||
public override async Task DuplexStreamingServerHandler<TRequest, TResponse>(
|
||||
IAsyncStreamReader<TRequest> requestStream,
|
||||
IServerStreamWriter<TResponse> responseStream,
|
||||
ServerCallContext context,
|
||||
DuplexStreamingServerMethod<TRequest, TResponse> continuation)
|
||||
{
|
||||
await RequestHandler(context);
|
||||
await continuation(requestStream, responseStream, context);
|
||||
}
|
||||
|
||||
public override async Task ServerStreamingServerHandler<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
IServerStreamWriter<TResponse> responseStream,
|
||||
ServerCallContext context,
|
||||
ServerStreamingServerMethod<TRequest, TResponse> continuation)
|
||||
{
|
||||
await RequestHandler(context);
|
||||
await continuation(request, responseStream, context);
|
||||
}
|
||||
|
||||
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
|
||||
TRequest request,
|
||||
ServerCallContext context,
|
||||
UnaryServerMethod<TRequest, TResponse> continuation)
|
||||
{
|
||||
await RequestHandler(context);
|
||||
return await continuation(request, context);
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
using Grpc.Core;
|
||||
|
||||
namespace EllieBot.GrpcApi;
|
||||
|
||||
public static class SvcExtensions
|
||||
{
|
||||
public static ulong GetUserId(this Metadata meta)
|
||||
=> ulong.Parse(meta.FirstOrDefault(x => x.Key == "userid")!.Value);
|
||||
}
|
|
@ -76,9 +76,6 @@ public readonly struct kwum : IEquatable<kwum>
|
|||
|
||||
public override string ToString()
|
||||
{
|
||||
if (_value == 0)
|
||||
return VALID_CHARACTERS[0].ToString();
|
||||
|
||||
var count = VALID_CHARACTERS.Length;
|
||||
var localValue = _value;
|
||||
var arrSize = (int)Math.Log(localValue, count) + 1;
|
||||
|
|
|
@ -40,11 +40,4 @@ public interface ICurrencyService
|
|||
TxData? txData);
|
||||
|
||||
Task<IReadOnlyList<DiscordUser>> GetTopRichest(ulong ignoreId, int page = 0, int perPage = 9);
|
||||
|
||||
Task<IReadOnlyList<CurrencyTransaction>> GetTransactionsAsync(
|
||||
ulong userId,
|
||||
int page,
|
||||
int perPage = 15);
|
||||
|
||||
Task<int> GetTransactionsCountAsync(ulong userId);
|
||||
}
|
|
@ -4,6 +4,6 @@ namespace EllieBot.Services;
|
|||
|
||||
public interface ITxTracker
|
||||
{
|
||||
Task TrackAdd(ulong userId, long amount, TxData? txData);
|
||||
Task TrackRemove(ulong userId, long amount, TxData? txData);
|
||||
Task TrackAdd(long amount, TxData? txData);
|
||||
Task TrackRemove(long amount, TxData? txData);
|
||||
}
|
|
@ -11,9 +11,9 @@ public class SlotGame
|
|||
{
|
||||
var rolls = new[]
|
||||
{
|
||||
(byte)_rng.Next(0, 7),
|
||||
(byte)_rng.Next(0, 7),
|
||||
(byte)_rng.Next(0, 7)
|
||||
(byte)_rng.Next(0, 6),
|
||||
(byte)_rng.Next(0, 6),
|
||||
(byte)_rng.Next(0, 6)
|
||||
};
|
||||
|
||||
ref var a = ref rolls[0];
|
||||
|
@ -24,24 +24,24 @@ public class SlotGame
|
|||
var winType = SlotWinType.None;
|
||||
if (a == b && b == c)
|
||||
{
|
||||
if (a == 6)
|
||||
if (a == 5)
|
||||
{
|
||||
winType = SlotWinType.TrippleJoker;
|
||||
multi = 25;
|
||||
multi = 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
winType = SlotWinType.TrippleNormal;
|
||||
multi = 15;
|
||||
multi = 10;
|
||||
}
|
||||
}
|
||||
else if (a == 6 && (b == 6 || c == 6)
|
||||
|| (b == 6 && c == 6))
|
||||
else if (a == 5 && (b == 5 || c == 5)
|
||||
|| (b == 5 && c == 5))
|
||||
{
|
||||
winType = SlotWinType.DoubleJoker;
|
||||
multi = 6;
|
||||
multi = 4;
|
||||
}
|
||||
else if (a == 6 || b == 6 || c == 6)
|
||||
else if (a == 5 || b == 5 || c == 5)
|
||||
{
|
||||
winType = SlotWinType.SingleJoker;
|
||||
multi = 1;
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace EllieBot.Common;
|
|||
public partial class ImageUrls : ICloneable<ImageUrls>
|
||||
{
|
||||
[Comment("DO NOT CHANGE")]
|
||||
public int Version { get; set; } = 6;
|
||||
public int Version { get; set; } = 5;
|
||||
|
||||
public CoinData Coins { get; set; }
|
||||
public Uri[] Currency { get; set; }
|
||||
|
|
|
@ -201,12 +201,9 @@ public sealed partial class GoogleApiService : IGoogleApiService, IEService
|
|||
{
|
||||
string text;
|
||||
|
||||
if (!Languages.ContainsKey(targetLanguage))
|
||||
if (!Languages.ContainsKey(sourceLanguage) || !Languages.ContainsKey(targetLanguage))
|
||||
throw new ArgumentException(nameof(sourceLanguage) + "/" + nameof(targetLanguage));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sourceLanguage) || !Languages.ContainsKey(sourceLanguage))
|
||||
sourceLanguage = "auto";
|
||||
|
||||
|
||||
var url = new Uri(string.Format(
|
||||
"https://translate.googleapis.com/translate_a/single?client=gtx&sl={0}&tl={1}&dt=t&q={2}",
|
||||
|
@ -226,7 +223,7 @@ public sealed partial class GoogleApiService : IGoogleApiService, IEService
|
|||
private string ConvertToLanguageCode(string language)
|
||||
{
|
||||
Languages.TryGetValue(language, out var mode);
|
||||
return string.IsNullOrWhiteSpace(mode) ? language : mode;
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,6 +154,7 @@ public sealed partial class GoogleApiService
|
|||
}
|
||||
|
||||
Languages = langs;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -12,11 +12,7 @@ public sealed partial class ReplacementPatternStore
|
|||
{
|
||||
Register("%bot.time%",
|
||||
static ()
|
||||
=> TimestampTag.FromDateTime(DateTime.UtcNow, TimestampTagStyles.ShortTime).ToString());
|
||||
|
||||
Register("%bot.date%",
|
||||
static ()
|
||||
=> TimestampTag.FromDateTime(DateTime.UtcNow, TimestampTagStyles.ShortTime).ToString());
|
||||
=> DateTime.Now.ToString("HH:mm " + TimeZoneInfo.Local.StandardName.GetInitials()));
|
||||
}
|
||||
|
||||
private void WithClient()
|
||||
|
|
|
@ -165,7 +165,7 @@ public class CommandHandler : IEService, IReadyExecutor, ICommandHandler
|
|||
Log.Information("Succ | g:{GuildId} | c: {ChannelId} | u: {UserId} | msg: {Message}",
|
||||
channel?.Guild.Id.ToString() ?? "-",
|
||||
channel?.Id.ToString() ?? "-",
|
||||
usrMsg.Author.Id.ToString(),
|
||||
usrMsg.Author.Id,
|
||||
usrMsg.Content.TrimTo(10));
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ public sealed class CurrencyService : ICurrencyService, IEService
|
|||
{
|
||||
var wallet = await GetWalletAsync(userId);
|
||||
await wallet.Add(amount, txData);
|
||||
await _txTracker.TrackAdd(userId, amount, txData);
|
||||
await _txTracker.TrackAdd(amount, txData);
|
||||
}
|
||||
|
||||
public async Task AddAsync(
|
||||
|
@ -97,7 +97,7 @@ public sealed class CurrencyService : ICurrencyService, IEService
|
|||
var wallet = await GetWalletAsync(userId);
|
||||
var result = await wallet.Take(amount, txData);
|
||||
if (result)
|
||||
await _txTracker.TrackRemove(userId, amount, txData);
|
||||
await _txTracker.TrackRemove(amount, txData);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -112,29 +112,4 @@ public sealed class CurrencyService : ICurrencyService, IEService
|
|||
await using var uow = _db.GetDbContext();
|
||||
return await uow.Set<DiscordUser>().GetTopRichest(ignoreId, page, perPage);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<CurrencyTransaction>> GetTransactionsAsync(
|
||||
ulong userId,
|
||||
int page,
|
||||
int perPage = 15)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var trs = await uow.GetTable<CurrencyTransaction>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.OrderByDescending(x => x.DateAdded)
|
||||
.Skip(perPage * page)
|
||||
.Take(perPage)
|
||||
.ToListAsyncLinqToDB();
|
||||
|
||||
return trs;
|
||||
}
|
||||
|
||||
public async Task<int> GetTransactionsCountAsync(ulong userId)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.GetTable<CurrencyTransaction>()
|
||||
.Where(x => x.UserId == userId)
|
||||
.CountAsyncLinqToDB();
|
||||
}
|
||||
}
|
|
@ -77,7 +77,8 @@ public class DefaultWallet : IWallet
|
|||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
UserId = userId,
|
||||
Username = "??Unknown",
|
||||
Username = "Unknown",
|
||||
Discriminator = "????",
|
||||
CurrencyAmount = amount,
|
||||
},
|
||||
(old) => new()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue