mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
Compare commits
61 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7f5e065c4d | ||
|
86b214163a | ||
|
9dbb08d85f | ||
|
89ca56c77c | ||
|
9e96679099 | ||
|
1280d2b397 | ||
|
c731127607 | ||
|
c15930306a | ||
|
701501d678 | ||
|
fa12fcea58 | ||
|
274219c40b | ||
|
96c9b47da2 | ||
|
b5d1469df1 | ||
|
d7747bd25a | ||
|
7d162d1f04 | ||
|
704d061d46 | ||
|
c39c9061fd | ||
|
619ddba4f8 | ||
|
3acef04b32 | ||
|
83a1d959b1 | ||
|
a1632722bc | ||
|
ee0a28afab | ||
|
2b301c0aab | ||
|
b6b6b4e19e | ||
|
32fc8b6e03 | ||
|
297e2fde0e | ||
|
729f26caab | ||
|
4b12e4e923 | ||
|
12f4ce7f2a | ||
|
00944e08c3 | ||
|
569abd7194 | ||
|
474a1db41d | ||
|
0f6255947e | ||
|
f68f219a25 | ||
|
8f16b11d02 | ||
|
df5eced904 | ||
|
1dcd158f43 | ||
|
757c9b564d | ||
|
07cef3eb5e | ||
|
85c525e19b | ||
|
477581f616 | ||
|
ff30105816 | ||
|
49f04a594b | ||
|
716090a132 | ||
|
c835514c7b | ||
|
b136e7ff0e | ||
|
9dd2997b0f | ||
|
fde5309ea4 | ||
|
a8e4173e9b | ||
|
74b4c4b64d | ||
|
6cc5a160a2 | ||
|
ca8e022db6 | ||
|
cd8c14c607 | ||
|
1340533c21 | ||
|
14d86b9042 | ||
|
3a504a954f | ||
|
822ce0b8de | ||
|
40490a4656 | ||
|
0cf7909fef | ||
|
de8d4b7d9e | ||
|
0123892038 |
762
CHANGELOG.md
762
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -1,3 +0,0 @@
|
|||||||
dotnet ef migrations remove -c SqliteContext -f -p src/NadekoBot/NadekoBot.csproj
|
|
||||||
dotnet ef migrations remove -c PostgreSqlContext -f -p src/NadekoBot/NadekoBot.csproj
|
|
||||||
|
|
@@ -12,13 +12,14 @@ namespace NadekoBot.Generators
|
|||||||
{
|
{
|
||||||
public readonly record struct MethodPermData
|
public readonly record struct MethodPermData
|
||||||
{
|
{
|
||||||
public readonly string Name;
|
public readonly ImmutableArray<(string Name, string Value)> MethodPerms;
|
||||||
public readonly string Value;
|
public readonly ImmutableArray<string> NoAuthRequired;
|
||||||
|
|
||||||
public MethodPermData(string name, string value)
|
public MethodPermData(ImmutableArray<(string Name, string Value)> methodPerms,
|
||||||
|
ImmutableArray<string> noAuthRequired)
|
||||||
{
|
{
|
||||||
Name = name;
|
MethodPerms = methodPerms;
|
||||||
Value = value;
|
NoAuthRequired = noAuthRequired;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ namespace NadekoBot.Generators
|
|||||||
[Generator]
|
[Generator]
|
||||||
public class GrpcApiPermGenerator : IIncrementalGenerator
|
public class GrpcApiPermGenerator : IIncrementalGenerator
|
||||||
{
|
{
|
||||||
public const string Attribute =
|
public const string GRPC_API_PERM_ATTRIBUTE =
|
||||||
"""
|
"""
|
||||||
namespace NadekoBot.GrpcApi;
|
namespace NadekoBot.GrpcApi;
|
||||||
|
|
||||||
@@ -37,13 +38,26 @@ namespace NadekoBot.Generators
|
|||||||
public GrpcApiPermAttribute(GuildPerm value) => Value = value;
|
public GrpcApiPermAttribute(GuildPerm value) => Value = value;
|
||||||
}
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
|
public const string GRPC_NO_AUTH_REQUIRED_ATTRIBUTE =
|
||||||
|
"""
|
||||||
|
namespace NadekoBot.GrpcApi;
|
||||||
|
|
||||||
|
[System.AttributeUsage(System.AttributeTargets.Method)]
|
||||||
|
public class GrpcNoAuthRequiredAttribute : System.Attribute
|
||||||
|
{
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
{
|
||||||
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("GrpcApiPermAttribute.cs",
|
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("GrpcApiPermAttribute.cs",
|
||||||
SourceText.From(Attribute, Encoding.UTF8)));
|
SourceText.From(GRPC_API_PERM_ATTRIBUTE, Encoding.UTF8)));
|
||||||
|
|
||||||
|
context.RegisterPostInitializationOutput(ctx => ctx.AddSource("GrpcNoAuthRequiredAttribute.cs",
|
||||||
|
SourceText.From(GRPC_NO_AUTH_REQUIRED_ATTRIBUTE, Encoding.UTF8)));
|
||||||
|
|
||||||
var enumsToGenerate = context.SyntaxProvider
|
var perms = context.SyntaxProvider
|
||||||
.ForAttributeWithMetadataName(
|
.ForAttributeWithMetadataName(
|
||||||
"NadekoBot.GrpcApi.GrpcApiPermAttribute",
|
"NadekoBot.GrpcApi.GrpcApiPermAttribute",
|
||||||
predicate: static (s, _) => s is MethodDeclarationSyntax,
|
predicate: static (s, _) => s is MethodDeclarationSyntax,
|
||||||
@@ -52,11 +66,24 @@ namespace NadekoBot.Generators
|
|||||||
.Select(static (x, _) => x!.Value)
|
.Select(static (x, _) => x!.Value)
|
||||||
.Collect();
|
.Collect();
|
||||||
|
|
||||||
context.RegisterSourceOutput(enumsToGenerate,
|
|
||||||
|
var all = context.SyntaxProvider
|
||||||
|
.ForAttributeWithMetadataName(
|
||||||
|
"NadekoBot.GrpcApi.GrpcNoAuthRequiredAttribute",
|
||||||
|
predicate: static (s, _) => s is MethodDeclarationSyntax,
|
||||||
|
transform: static (ctx, _) => GetNoAuthMethodName(ctx.SemanticModel, ctx.TargetNode))
|
||||||
|
.Collect()
|
||||||
|
.Combine(perms)
|
||||||
|
.Select((x, _) => new MethodPermData(x.Right, x.Left));
|
||||||
|
|
||||||
|
context.RegisterSourceOutput(all,
|
||||||
static (spc, source) => Execute(source, spc));
|
static (spc, source) => Execute(source, spc));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodPermData? GetMethodSemanticTargets(SemanticModel model, SyntaxNode node)
|
private static string GetNoAuthMethodName(SemanticModel model, SyntaxNode node)
|
||||||
|
=> ((MethodDeclarationSyntax)node).Identifier.Text;
|
||||||
|
|
||||||
|
private static (string Name, string Value)? GetMethodSemanticTargets(SemanticModel model, SyntaxNode node)
|
||||||
{
|
{
|
||||||
var method = (MethodDeclarationSyntax)node;
|
var method = (MethodDeclarationSyntax)node;
|
||||||
|
|
||||||
@@ -64,20 +91,14 @@ namespace NadekoBot.Generators
|
|||||||
var attr = method.AttributeLists
|
var attr = method.AttributeLists
|
||||||
.SelectMany(x => x.Attributes)
|
.SelectMany(x => x.Attributes)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
// .FirstOrDefault(x => x.Name.ToString() == "GrpcApiPermAttribute");
|
|
||||||
|
|
||||||
|
|
||||||
if (attr is null)
|
if (attr is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// if (model.GetSymbolInfo(attr).Symbol is not IMethodSymbol attrSymbol)
|
return (name, attr.ArgumentList?.Arguments[0].ToString() ?? "__missing_perm__");
|
||||||
// return null;
|
|
||||||
|
|
||||||
return new MethodPermData(name, attr.ArgumentList?.Arguments[0].ToString() ?? "__missing_perm__");
|
|
||||||
// return new MethodPermData(name, attrSymbol.Parameters[0].ContainingType.ToDisplayString() + "." + attrSymbol.Parameters[0].Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Execute(ImmutableArray<MethodPermData> fields, SourceProductionContext ctx)
|
private static void Execute(MethodPermData data, SourceProductionContext ctx)
|
||||||
{
|
{
|
||||||
using (var stringWriter = new StringWriter())
|
using (var stringWriter = new StringWriter())
|
||||||
using (var sw = new IndentedTextWriter(stringWriter))
|
using (var sw = new IndentedTextWriter(stringWriter))
|
||||||
@@ -87,16 +108,17 @@ namespace NadekoBot.Generators
|
|||||||
sw.WriteLine("namespace NadekoBot.GrpcApi;");
|
sw.WriteLine("namespace NadekoBot.GrpcApi;");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
|
|
||||||
sw.WriteLine("public partial class PermsInterceptor");
|
sw.WriteLine("public partial class GrpcApiPermsInterceptor");
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
|
|
||||||
sw.Indent++;
|
sw.Indent++;
|
||||||
|
|
||||||
sw.WriteLine("public static FrozenDictionary<string, GuildPerm> perms = new Dictionary<string, GuildPerm>()");
|
sw.WriteLine(
|
||||||
|
"private static FrozenDictionary<string, GuildPerm> _perms = new Dictionary<string, GuildPerm>()");
|
||||||
sw.WriteLine("{");
|
sw.WriteLine("{");
|
||||||
|
|
||||||
sw.Indent++;
|
sw.Indent++;
|
||||||
foreach (var field in fields)
|
foreach (var field in data.MethodPerms)
|
||||||
{
|
{
|
||||||
sw.WriteLine("{{ \"{0}\", {1} }},", field.Name, field.Value);
|
sw.WriteLine("{{ \"{0}\", {1} }},", field.Name, field.Value);
|
||||||
}
|
}
|
||||||
@@ -104,6 +126,21 @@ namespace NadekoBot.Generators
|
|||||||
sw.Indent--;
|
sw.Indent--;
|
||||||
sw.WriteLine("}.ToFrozenDictionary();");
|
sw.WriteLine("}.ToFrozenDictionary();");
|
||||||
|
|
||||||
|
sw.WriteLine();
|
||||||
|
sw.WriteLine("private static FrozenSet<string> _noAuthRequired = new HashSet<string>()");
|
||||||
|
sw.WriteLine("{");
|
||||||
|
|
||||||
|
sw.Indent++;
|
||||||
|
foreach (var noauth in data.NoAuthRequired)
|
||||||
|
{
|
||||||
|
sw.WriteLine("{{ \"{0}\" }},", noauth);
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.WriteLine("");
|
||||||
|
|
||||||
|
sw.Indent--;
|
||||||
|
sw.WriteLine("}.ToFrozenSet();");
|
||||||
|
|
||||||
sw.Indent--;
|
sw.Indent--;
|
||||||
sw.WriteLine("}");
|
sw.WriteLine("}");
|
||||||
|
|
||||||
|
47
src/NadekoBot.GrpcApiBase/protos/canvas.proto
Normal file
47
src/NadekoBot.GrpcApiBase/protos/canvas.proto
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option csharp_namespace = "NadekoBot.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;
|
||||||
|
}
|
@@ -1,26 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
option csharp_namespace = "NadekoBot.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;
|
|
||||||
}
|
|
@@ -2,7 +2,7 @@ syntax = "proto3";
|
|||||||
|
|
||||||
option csharp_namespace = "NadekoBot.GrpcApi";
|
option csharp_namespace = "NadekoBot.GrpcApi";
|
||||||
|
|
||||||
import "google/protobuf/empty.proto";
|
import "google/protobuf/empty.proto";
|
||||||
|
|
||||||
package exprs;
|
package exprs;
|
||||||
|
|
||||||
@@ -10,6 +10,10 @@ service GrpcExprs {
|
|||||||
rpc GetExprs(GetExprsRequest) returns (GetExprsReply);
|
rpc GetExprs(GetExprsRequest) returns (GetExprsReply);
|
||||||
rpc AddExpr(AddExprRequest) returns (AddExprReply);
|
rpc AddExpr(AddExprRequest) returns (AddExprReply);
|
||||||
rpc DeleteExpr(DeleteExprRequest) returns (google.protobuf.Empty);
|
rpc DeleteExpr(DeleteExprRequest) returns (google.protobuf.Empty);
|
||||||
|
|
||||||
|
rpc GetQuotes(GetQuotesRequest) returns (GetQuotesReply);
|
||||||
|
rpc AddQuote(AddQuoteRequest) returns (AddQuoteReply);
|
||||||
|
rpc DeleteQuote(DeleteQuoteRequest) returns (google.protobuf.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteExprRequest {
|
message DeleteExprRequest {
|
||||||
@@ -32,7 +36,7 @@ message ExprDto {
|
|||||||
string id = 1;
|
string id = 1;
|
||||||
string trigger = 2;
|
string trigger = 2;
|
||||||
string response = 3;
|
string response = 3;
|
||||||
|
|
||||||
bool ca = 4;
|
bool ca = 4;
|
||||||
bool ad = 5;
|
bool ad = 5;
|
||||||
bool dm = 6;
|
bool dm = 6;
|
||||||
@@ -47,4 +51,39 @@ message AddExprRequest {
|
|||||||
message AddExprReply {
|
message AddExprReply {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
bool success = 2;
|
bool success = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetQuotesRequest {
|
||||||
|
uint64 guildId = 1;
|
||||||
|
string query = 2;
|
||||||
|
int32 page = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetQuotesReply {
|
||||||
|
repeated QuoteDto quotes = 1;
|
||||||
|
int32 totalCount = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message QuoteDto {
|
||||||
|
string id = 1;
|
||||||
|
string trigger = 2;
|
||||||
|
string response = 3;
|
||||||
|
|
||||||
|
uint64 authorId = 4;
|
||||||
|
string authorName = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddQuoteRequest {
|
||||||
|
uint64 guildId = 1;
|
||||||
|
QuoteDto quote = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message AddQuoteReply {
|
||||||
|
string id = 1;
|
||||||
|
bool success = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteQuoteRequest {
|
||||||
|
string id = 1;
|
||||||
|
uint64 guildId = 2;
|
||||||
}
|
}
|
60
src/NadekoBot.GrpcApiBase/protos/fin.proto
Normal file
60
src/NadekoBot.GrpcApiBase/protos/fin.proto
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option csharp_namespace = "NadekoBot.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;
|
||||||
|
}
|
@@ -5,20 +5,13 @@ option csharp_namespace = "NadekoBot.GrpcApi";
|
|||||||
package greet;
|
package greet;
|
||||||
|
|
||||||
service GrpcGreet {
|
service GrpcGreet {
|
||||||
rpc GetGreetSettings (GetGreetRequest) returns (GetGreetReply);
|
rpc GetGreetSettings (GetGreetRequest) returns (GrpcGreetSettings);
|
||||||
rpc UpdateGreet (UpdateGreetRequest) returns (UpdateGreetReply);
|
rpc UpdateGreet (UpdateGreetRequest) returns (UpdateGreetReply);
|
||||||
rpc TestGreet (TestGreetRequest) returns (TestGreetReply);
|
rpc TestGreet (TestGreetRequest) returns (TestGreetReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetGreetReply {
|
|
||||||
GrpcGreetSettings greet = 1;
|
|
||||||
GrpcGreetSettings greetDm = 2;
|
|
||||||
GrpcGreetSettings bye = 3;
|
|
||||||
GrpcGreetSettings boost = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GrpcGreetSettings {
|
message GrpcGreetSettings {
|
||||||
optional uint64 channelId = 1;
|
string channelId = 1;
|
||||||
string message = 2;
|
string message = 2;
|
||||||
bool isEnabled = 3;
|
bool isEnabled = 3;
|
||||||
GrpcGreetType type = 4;
|
GrpcGreetType type = 4;
|
||||||
@@ -26,6 +19,7 @@ message GrpcGreetSettings {
|
|||||||
|
|
||||||
message GetGreetRequest {
|
message GetGreetRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
|
GrpcGreetType type = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateGreetRequest {
|
message UpdateGreetRequest {
|
||||||
@@ -41,7 +35,7 @@ enum GrpcGreetType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message UpdateGreetReply {
|
message UpdateGreetReply {
|
||||||
bool success = 1;
|
bool Success = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message TestGreetRequest {
|
message TestGreetRequest {
|
||||||
|
@@ -3,43 +3,50 @@ syntax = "proto3";
|
|||||||
option csharp_namespace = "NadekoBot.GrpcApi";
|
option csharp_namespace = "NadekoBot.GrpcApi";
|
||||||
|
|
||||||
import "google/protobuf/empty.proto";
|
import "google/protobuf/empty.proto";
|
||||||
import "google/protobuf/timestamp.proto";
|
|
||||||
|
|
||||||
package other;
|
package other;
|
||||||
|
|
||||||
service GrpcOther {
|
service GrpcOther {
|
||||||
|
rpc BotOnGuild(BotOnGuildRequest) returns (BotOnGuildReply);
|
||||||
rpc GetGuilds(google.protobuf.Empty) returns (GetGuildsReply);
|
|
||||||
rpc GetTextChannels(GetTextChannelsRequest) returns (GetTextChannelsReply);
|
rpc GetTextChannels(GetTextChannelsRequest) returns (GetTextChannelsReply);
|
||||||
|
rpc GetRoles(GetRolesRequest) returns (GetRolesReply);
|
||||||
|
|
||||||
rpc GetCurrencyLb(GetLbRequest) returns (CurrencyLbReply);
|
rpc GetCurrencyLb(GetLbRequest) returns (CurrencyLbReply);
|
||||||
rpc GetXpLb(GetLbRequest) returns (XpLbReply);
|
rpc GetXpLb(GetLbRequest) returns (XpLbReply);
|
||||||
rpc GetWaifuLb(GetLbRequest) returns (WaifuLbReply);
|
rpc GetWaifuLb(GetLbRequest) returns (WaifuLbReply);
|
||||||
|
|
||||||
rpc GetShardStatuses(google.protobuf.Empty) returns (GetShardStatusesReply);
|
rpc GetShardStats(google.protobuf.Empty) returns (stream ShardStatsReply);
|
||||||
|
rpc GetCommandFeed(google.protobuf.Empty) returns (stream CommandFeedEntry);
|
||||||
rpc GetServerInfo(ServerInfoRequest) returns (GetServerInfoReply);
|
rpc GetServerInfo(ServerInfoRequest) returns (GetServerInfoReply);
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetGuildsReply {
|
message CommandFeedEntry {
|
||||||
repeated GuildReply guilds = 1;
|
string command = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GuildReply {
|
message GetRolesRequest {
|
||||||
uint64 id = 1;
|
uint64 guildId = 1;
|
||||||
string name = 2;
|
|
||||||
string iconUrl = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetShardStatusesReply {
|
message GetRolesReply {
|
||||||
repeated ShardStatusReply shards = 1;
|
repeated RoleReply roles = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ShardStatusReply {
|
message BotOnGuildRequest {
|
||||||
|
uint64 guildId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BotOnGuildReply {
|
||||||
|
bool success = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ShardStatsReply {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string status = 2;
|
string status = 2;
|
||||||
|
|
||||||
int32 guildCount = 3;
|
int32 guildCount = 3;
|
||||||
google.protobuf.Timestamp lastUpdate = 4;
|
string uptime = 4;
|
||||||
|
int64 commands = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetTextChannelsRequest{
|
message GetTextChannelsRequest{
|
||||||
|
@@ -6,11 +6,17 @@ package warn;
|
|||||||
|
|
||||||
service GrpcWarn {
|
service GrpcWarn {
|
||||||
rpc GetWarnSettings (WarnSettingsRequest) returns (WarnSettingsReply);
|
rpc GetWarnSettings (WarnSettingsRequest) returns (WarnSettingsReply);
|
||||||
|
|
||||||
|
rpc SetWarnExpiry(SetWarnExpiryRequest) returns (SetWarnExpiryReply);
|
||||||
rpc AddWarnp (AddWarnpRequest) returns (AddWarnpReply);
|
rpc AddWarnp (AddWarnpRequest) returns (AddWarnpReply);
|
||||||
rpc DeleteWarnp (DeleteWarnpRequest) returns (DeleteWarnpReply);
|
rpc DeleteWarnp (DeleteWarnpRequest) returns (DeleteWarnpReply);
|
||||||
|
|
||||||
|
rpc GetLatestWarnings(GetLatestWarningsRequest) returns (GetLatestWarningsReply);
|
||||||
rpc GetUserWarnings(GetUserWarningsRequest) returns (GetUserWarningsReply);
|
rpc GetUserWarnings(GetUserWarningsRequest) returns (GetUserWarningsReply);
|
||||||
rpc ClearWarning(ClearWarningRequest) returns (ClearWarningReply);
|
|
||||||
rpc SetWarnExpiry(SetWarnExpiryRequest) returns (SetWarnExpiryReply);
|
rpc ForgiveWarning(ForgiveWarningRequest) returns (ForgiveWarningReply);
|
||||||
|
rpc DeleteWarning(ForgiveWarningRequest) returns (ForgiveWarningReply);
|
||||||
|
|
||||||
}
|
}
|
||||||
message WarnSettingsRequest {
|
message WarnSettingsRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
@@ -19,12 +25,14 @@ message WarnSettingsRequest {
|
|||||||
message WarnPunishment {
|
message WarnPunishment {
|
||||||
int32 threshold = 1;
|
int32 threshold = 1;
|
||||||
string action = 2;
|
string action = 2;
|
||||||
int64 duration = 3;
|
int32 duration = 3;
|
||||||
|
string role = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message WarnSettingsReply {
|
message WarnSettingsReply {
|
||||||
repeated WarnPunishment punishments = 1;
|
repeated WarnPunishment punishments = 1;
|
||||||
int32 expiryDays = 2;
|
int32 expiryDays = 2;
|
||||||
|
bool deleteOnExpire = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AddWarnpRequest {
|
message AddWarnpRequest {
|
||||||
@@ -38,7 +46,7 @@ message AddWarnpReply {
|
|||||||
|
|
||||||
message DeleteWarnpRequest {
|
message DeleteWarnpRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
int32 warnpIndex = 2;
|
int32 threshold = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteWarnpReply {
|
message DeleteWarnpReply {
|
||||||
@@ -47,37 +55,53 @@ message DeleteWarnpReply {
|
|||||||
|
|
||||||
message GetUserWarningsRequest {
|
message GetUserWarningsRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
uint64 user_id = 2;
|
string user = 2;
|
||||||
|
int32 page = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetUserWarningsReply {
|
message GetUserWarningsReply {
|
||||||
repeated Warning warnings = 1;
|
repeated Warning warnings = 1;
|
||||||
|
int32 totalCount = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Warning {
|
message Warning {
|
||||||
int32 id = 1;
|
string id = 1;
|
||||||
string reason = 2;
|
string reason = 2;
|
||||||
int64 timestamp = 3;
|
int64 timestamp = 3;
|
||||||
int64 expiry_timestamp = 4;
|
int64 weight = 4;
|
||||||
bool cleared = 5;
|
bool forgiven = 5;
|
||||||
string clearedBy = 6;
|
string forgivenBy = 6;
|
||||||
|
string user = 7;
|
||||||
|
uint64 userId = 8;
|
||||||
|
string moderator = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ClearWarningRequest {
|
message ForgiveWarningRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
uint64 userId = 2;
|
string warnId = 2;
|
||||||
optional int32 warnId = 3;
|
string modName = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ClearWarningReply {
|
message ForgiveWarningReply {
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetWarnExpiryRequest {
|
message SetWarnExpiryRequest {
|
||||||
uint64 guildId = 1;
|
uint64 guildId = 1;
|
||||||
int32 expiryDays = 2;
|
int32 expiryDays = 2;
|
||||||
|
bool deleteOnExpire = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetWarnExpiryReply {
|
message SetWarnExpiryReply {
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetLatestWarningsRequest {
|
||||||
|
uint64 guildId = 1;
|
||||||
|
int32 page = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetLatestWarningsReply {
|
||||||
|
repeated Warning warnings = 1;
|
||||||
|
int32 totalCount = 2;
|
||||||
}
|
}
|
120
src/NadekoBot.GrpcApiBase/protos/xp.proto
Normal file
120
src/NadekoBot.GrpcApiBase/protos/xp.proto
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option csharp_namespace = "NadekoBot.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;
|
||||||
|
}
|
@@ -25,7 +25,6 @@ public static class DiscordUserExtensions
|
|||||||
{
|
{
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
Username = username,
|
Username = username,
|
||||||
Discriminator = discrim,
|
|
||||||
AvatarId = avatarId,
|
AvatarId = avatarId,
|
||||||
TotalXp = 0,
|
TotalXp = 0,
|
||||||
CurrencyAmount = 0
|
CurrencyAmount = 0
|
||||||
@@ -33,7 +32,6 @@ public static class DiscordUserExtensions
|
|||||||
old => new()
|
old => new()
|
||||||
{
|
{
|
||||||
Username = username,
|
Username = username,
|
||||||
Discriminator = discrim,
|
|
||||||
AvatarId = avatarId
|
AvatarId = avatarId
|
||||||
},
|
},
|
||||||
() => new()
|
() => new()
|
||||||
@@ -49,8 +47,7 @@ public static class DiscordUserExtensions
|
|||||||
() => new()
|
() => new()
|
||||||
{
|
{
|
||||||
UserId = userId,
|
UserId = userId,
|
||||||
Username = "Unknown",
|
Username = "??Unknown",
|
||||||
Discriminator = "????",
|
|
||||||
AvatarId = string.Empty,
|
AvatarId = string.Empty,
|
||||||
TotalXp = 0,
|
TotalXp = 0,
|
||||||
CurrencyAmount = 0
|
CurrencyAmount = 0
|
||||||
@@ -87,14 +84,7 @@ public static class DiscordUserExtensions
|
|||||||
> users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault())
|
> users.AsQueryable().Where(y => y.UserId == id).Select(y => y.TotalXp).FirstOrDefault())
|
||||||
.Count()
|
.Count()
|
||||||
+ 1;
|
+ 1;
|
||||||
|
|
||||||
public static async Task<IReadOnlyCollection<DiscordUser>> GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page, int perPage)
|
|
||||||
=> await users.ToLinqToDBTable()
|
|
||||||
.OrderByDescending(x => x.TotalXp)
|
|
||||||
.Skip(page * perPage)
|
|
||||||
.Take(perPage)
|
|
||||||
.ToArrayAsyncLinqToDB();
|
|
||||||
|
|
||||||
public static Task<List<DiscordUser>> GetTopRichest(
|
public static Task<List<DiscordUser>> GetTopRichest(
|
||||||
this DbSet<DiscordUser> users,
|
this DbSet<DiscordUser> users,
|
||||||
ulong botId,
|
ulong botId,
|
||||||
|
@@ -57,8 +57,7 @@ public static class GuildConfigExtensions
|
|||||||
List<ulong> availableGuilds)
|
List<ulong> availableGuilds)
|
||||||
{
|
{
|
||||||
var result = await configs
|
var result = await configs
|
||||||
.AsQueryable()
|
.IncludeEverything()
|
||||||
.Include(x => x.CommandCooldowns)
|
|
||||||
.Where(x => availableGuilds.Contains(x.GuildId))
|
.Where(x => availableGuilds.Contains(x.GuildId))
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToArrayAsync();
|
.ToArrayAsync();
|
||||||
@@ -96,7 +95,6 @@ public static class GuildConfigExtensions
|
|||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
Permissions = Permissionv2.GetDefaultPermlist,
|
Permissions = Permissionv2.GetDefaultPermlist,
|
||||||
WarningsInitialized = true,
|
WarningsInitialized = true,
|
||||||
WarnPunishments = DefaultWarnPunishments
|
|
||||||
});
|
});
|
||||||
ctx.SaveChanges();
|
ctx.SaveChanges();
|
||||||
}
|
}
|
||||||
@@ -104,7 +102,6 @@ public static class GuildConfigExtensions
|
|||||||
if (!config.WarningsInitialized)
|
if (!config.WarningsInitialized)
|
||||||
{
|
{
|
||||||
config.WarningsInitialized = true;
|
config.WarningsInitialized = true;
|
||||||
config.WarnPunishments = DefaultWarnPunishments;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@@ -26,17 +26,6 @@ public static class UserXpExtensions
|
|||||||
return usr;
|
return usr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<IReadOnlyCollection<UserXpStats>> GetUsersFor(
|
|
||||||
this DbSet<UserXpStats> xps,
|
|
||||||
ulong guildId,
|
|
||||||
int page)
|
|
||||||
=> await xps.ToLinqToDBTable()
|
|
||||||
.Where(x => x.GuildId == guildId)
|
|
||||||
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
|
||||||
.Skip(page * 9)
|
|
||||||
.Take(9)
|
|
||||||
.ToArrayAsyncLinqToDB();
|
|
||||||
|
|
||||||
public static async Task<List<UserXpStats>> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
|
public static async Task<List<UserXpStats>> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
|
||||||
=> await xps.ToLinqToDBTable()
|
=> await xps.ToLinqToDBTable()
|
||||||
.Where(x => x.GuildId == guildId)
|
.Where(x => x.GuildId == guildId)
|
||||||
@@ -55,9 +44,6 @@ public static class UserXpExtensions
|
|||||||
.CountAsyncLinqToDB()
|
.CountAsyncLinqToDB()
|
||||||
+ 1;
|
+ 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)
|
public static void ResetGuildXp(this DbSet<UserXpStats> xps, ulong guildId)
|
||||||
=> xps.Delete(x => x.GuildId == guildId);
|
=> xps.Delete(x => x.GuildId == guildId);
|
||||||
|
|
||||||
|
@@ -7,7 +7,7 @@ public class DiscordUser : DbEntity
|
|||||||
{
|
{
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string Discriminator { get; set; }
|
// public string Discriminator { get; set; }
|
||||||
public string AvatarId { get; set; }
|
public string AvatarId { get; set; }
|
||||||
|
|
||||||
public int? ClubId { get; set; }
|
public int? ClubId { get; set; }
|
||||||
@@ -27,9 +27,6 @@ public class DiscordUser : DbEntity
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000")
|
return Username;
|
||||||
return Username;
|
|
||||||
|
|
||||||
return Username + "#" + Discriminator;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
8
src/NadekoBot/Db/Models/FlagTranslateChannel.cs
Normal file
8
src/NadekoBot/Db/Models/FlagTranslateChannel.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#nullable disable
|
||||||
|
namespace NadekoBot.Db.Models;
|
||||||
|
|
||||||
|
public class FlagTranslateChannel : DbEntity
|
||||||
|
{
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
|
public ulong ChannelId { get; set; }
|
||||||
|
}
|
@@ -77,7 +77,6 @@ public class GuildConfig : DbEntity
|
|||||||
public HashSet<UnroleTimer> UnroleTimer { get; set; } = new();
|
public HashSet<UnroleTimer> UnroleTimer { get; set; } = new();
|
||||||
public HashSet<VcRoleInfo> VcRoleInfos { get; set; }
|
public HashSet<VcRoleInfo> VcRoleInfos { get; set; }
|
||||||
public HashSet<CommandAlias> CommandAliases { get; set; } = new();
|
public HashSet<CommandAlias> CommandAliases { get; set; } = new();
|
||||||
public List<WarningPunishment> WarnPunishments { get; set; } = new();
|
|
||||||
public bool WarningsInitialized { get; set; }
|
public bool WarningsInitialized { get; set; }
|
||||||
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
|
public HashSet<SlowmodeIgnoredUser> SlowmodeIgnoredUsers { get; set; }
|
||||||
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
|
public HashSet<SlowmodeIgnoredRole> SlowmodeIgnoredRoles { get; set; }
|
||||||
|
19
src/NadekoBot/Db/Models/NCanvas/NCanvas.cs
Normal file
19
src/NadekoBot/Db/Models/NCanvas/NCanvas.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace NadekoBot.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; }
|
||||||
|
}
|
@@ -3,6 +3,7 @@ namespace NadekoBot.Db.Models;
|
|||||||
|
|
||||||
public class WarningPunishment : DbEntity
|
public class WarningPunishment : DbEntity
|
||||||
{
|
{
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
public PunishmentAction Punishment { get; set; }
|
public PunishmentAction Punishment { get; set; }
|
||||||
public int Time { get; set; }
|
public int Time { get; set; }
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace NadekoBot.Db.Models;
|
namespace NadekoBot.Db.Models;
|
||||||
|
|
||||||
public class PatronUser
|
public class PatronUser
|
||||||
{
|
{
|
||||||
|
// [Key]
|
||||||
|
// public int Id { get; set; }
|
||||||
public string UniquePlatformUserId { get; set; }
|
public string UniquePlatformUserId { get; set; }
|
||||||
public ulong UserId { get; set; }
|
public ulong UserId { get; set; }
|
||||||
public int AmountCents { get; set; }
|
public int AmountCents { get; set; }
|
||||||
|
@@ -61,8 +61,8 @@ public abstract class NadekoContext : DbContext
|
|||||||
public DbSet<TodoModel> Todos { get; set; }
|
public DbSet<TodoModel> Todos { get; set; }
|
||||||
public DbSet<ArchivedTodoListModel> TodosArchive { get; set; }
|
public DbSet<ArchivedTodoListModel> TodosArchive { get; set; }
|
||||||
public DbSet<HoneypotChannel> HoneyPotChannels { get; set; }
|
public DbSet<HoneypotChannel> HoneyPotChannels { get; set; }
|
||||||
|
|
||||||
|
|
||||||
// todo add guild colors
|
|
||||||
// public DbSet<GuildColors> GuildColors { get; set; }
|
// public DbSet<GuildColors> GuildColors { get; set; }
|
||||||
|
|
||||||
|
|
||||||
@@ -74,6 +74,40 @@ public abstract class NadekoContext : DbContext
|
|||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
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
|
#region QUOTES
|
||||||
|
|
||||||
var quoteEntity = modelBuilder.Entity<Quote>();
|
var quoteEntity = modelBuilder.Entity<Quote>();
|
||||||
@@ -195,11 +229,6 @@ public abstract class NadekoContext : DbContext
|
|||||||
.WithOne()
|
.WithOne()
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
modelBuilder.Entity<GuildConfig>()
|
|
||||||
.HasMany(x => x.WarnPunishments)
|
|
||||||
.WithOne()
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
|
|
||||||
modelBuilder.Entity<GuildConfig>()
|
modelBuilder.Entity<GuildConfig>()
|
||||||
.HasMany(x => x.SlowmodeIgnoredRoles)
|
.HasMany(x => x.SlowmodeIgnoredRoles)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
@@ -277,6 +306,18 @@ public abstract class NadekoContext : DbContext
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region WarningPunishments
|
||||||
|
|
||||||
|
var warnpunishmentEntity = modelBuilder.Entity<WarningPunishment>(b =>
|
||||||
|
{
|
||||||
|
b.HasAlternateKey(x => new
|
||||||
|
{
|
||||||
|
x.GuildId,
|
||||||
|
x.Count
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Self Assignable Roles
|
#region Self Assignable Roles
|
||||||
|
|
||||||
@@ -339,6 +380,7 @@ public abstract class NadekoContext : DbContext
|
|||||||
du.HasIndex(x => x.TotalXp);
|
du.HasIndex(x => x.TotalXp);
|
||||||
du.HasIndex(x => x.CurrencyAmount);
|
du.HasIndex(x => x.CurrencyAmount);
|
||||||
du.HasIndex(x => x.UserId);
|
du.HasIndex(x => x.UserId);
|
||||||
|
du.HasIndex(x => x.Username);
|
||||||
});
|
});
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -695,7 +737,7 @@ public abstract class NadekoContext : DbContext
|
|||||||
gs
|
gs
|
||||||
.Property(x => x.IsEnabled)
|
.Property(x => x.IsEnabled)
|
||||||
.HasDefaultValue(false);
|
.HasDefaultValue(false);
|
||||||
|
|
||||||
gs
|
gs
|
||||||
.Property(x => x.AutoDeleteTimer)
|
.Property(x => x.AutoDeleteTimer)
|
||||||
.HasDefaultValue(0);
|
.HasDefaultValue(0);
|
||||||
|
@@ -5,6 +5,11 @@ namespace NadekoBot.Migrations;
|
|||||||
|
|
||||||
public static class MigrationQueries
|
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)
|
public static void MigrateRero(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
if (migrationBuilder.IsSqlite())
|
if (migrationBuilder.IsSqlite())
|
||||||
@@ -38,6 +43,7 @@ left join guildconfigs on reactionrolemessage.guildconfigid = guildconfigs.id;")
|
|||||||
DELETE FROM "DelMsgOnCmdChannel" WHERE "GuildConfigId" is NULL;
|
DELETE FROM "DelMsgOnCmdChannel" WHERE "GuildConfigId" is NULL;
|
||||||
DELETE FROM "WarningPunishment" WHERE "GuildConfigId" NOT IN (SELECT "Id" from "GuildConfigs");
|
DELETE FROM "WarningPunishment" WHERE "GuildConfigId" NOT IN (SELECT "Id" from "GuildConfigs");
|
||||||
DELETE FROM "StreamRoleBlacklistedUser" WHERE "StreamRoleSettingsId" is NULL;
|
DELETE FROM "StreamRoleBlacklistedUser" WHERE "StreamRoleSettingsId" is NULL;
|
||||||
|
DELETE FROM "Permissions" WHERE "GuildConfigId" NOT IN (SELECT "Id" from "GuildConfigs");
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,4 +71,20 @@ left join guildconfigs on reactionrolemessage.guildconfigid = guildconfigs.id;")
|
|||||||
WHERE SendBoostMessage = TRUE;
|
WHERE SendBoostMessage = TRUE;
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void AddGuildIdsToWarningPunishment(MigrationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Sql("""
|
||||||
|
DELETE FROM WarningPunishment WHERE GuildConfigId IS NULL OR GuildConfigId NOT IN (SELECT Id FROM GuildConfigs);
|
||||||
|
UPDATE WarningPunishment
|
||||||
|
SET GuildId = (SELECT GuildId FROM GuildConfigs WHERE Id = GuildConfigId);
|
||||||
|
|
||||||
|
DELETE FROM WarningPunishment as wp
|
||||||
|
WHERE (wp.Count, wp.GuildConfigId) in (
|
||||||
|
SELECT wp2.Count, wp2.GuildConfigId FROM WarningPunishment as wp2
|
||||||
|
GROUP BY wp2.Count, wp2.GuildConfigId
|
||||||
|
HAVING COUNT(id) > 1
|
||||||
|
);
|
||||||
|
""");
|
||||||
|
}
|
||||||
}
|
}
|
3778
src/NadekoBot/Migrations/PostgreSql/20241018004623_warn-split.Designer.cs
generated
Normal file
3778
src/NadekoBot/Migrations/PostgreSql/20241018004623_warn-split.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations.PostgreSql
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class warnsplit : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<decimal>(
|
||||||
|
name: "guildid",
|
||||||
|
table: "warningpunishment",
|
||||||
|
type: "numeric(20,0)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0m);
|
||||||
|
|
||||||
|
MigrationQueries.AddGuildIdsToWarningPunishment(migrationBuilder);
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "fk_warningpunishment_guildconfigs_guildconfigid",
|
||||||
|
table: "warningpunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "ix_warningpunishment_guildconfigid",
|
||||||
|
table: "warningpunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "guildconfigid",
|
||||||
|
table: "warningpunishment");
|
||||||
|
|
||||||
|
migrationBuilder.AddUniqueConstraint(
|
||||||
|
name: "ak_warningpunishment_guildid_count",
|
||||||
|
table: "warningpunishment",
|
||||||
|
columns: new[] { "guildid", "count" });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropUniqueConstraint(
|
||||||
|
name: "ak_warningpunishment_guildid_count",
|
||||||
|
table: "warningpunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "guildid",
|
||||||
|
table: "warningpunishment");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "guildconfigid",
|
||||||
|
table: "warningpunishment",
|
||||||
|
type: "integer",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "ix_warningpunishment_guildconfigid",
|
||||||
|
table: "warningpunishment",
|
||||||
|
column: "guildconfigid");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "fk_warningpunishment_guildconfigs_guildconfigid",
|
||||||
|
table: "warningpunishment",
|
||||||
|
column: "guildconfigid",
|
||||||
|
principalTable: "guildconfigs",
|
||||||
|
principalColumn: "id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3824
src/NadekoBot/Migrations/PostgreSql/20241028033704_ncanvas.Designer.cs
generated
Normal file
3824
src/NadekoBot/Migrations/PostgreSql/20241028033704_ncanvas.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3851
src/NadekoBot/Migrations/PostgreSql/20241102022956_no-discrim-and-flag-translate.Designer.cs
generated
Normal file
3851
src/NadekoBot/Migrations/PostgreSql/20241102022956_no-discrim-and-flag-translate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3902
src/NadekoBot/Migrations/PostgreSql/20241104094232_betstats.Designer.cs
generated
Normal file
3902
src/NadekoBot/Migrations/PostgreSql/20241104094232_betstats.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3919
src/NadekoBot/Migrations/PostgreSql/20241105073004_rakeback.Designer.cs
generated
Normal file
3919
src/NadekoBot/Migrations/PostgreSql/20241105073004_rakeback.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -751,10 +751,6 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
.HasColumnType("timestamp without time zone")
|
.HasColumnType("timestamp without time zone")
|
||||||
.HasColumnName("dateadded");
|
.HasColumnName("dateadded");
|
||||||
|
|
||||||
b.Property<string>("Discriminator")
|
|
||||||
.HasColumnType("text")
|
|
||||||
.HasColumnName("discriminator");
|
|
||||||
|
|
||||||
b.Property<bool>("IsClubAdmin")
|
b.Property<bool>("IsClubAdmin")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("boolean")
|
.HasColumnType("boolean")
|
||||||
@@ -799,6 +795,9 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.HasIndex("UserId")
|
b.HasIndex("UserId")
|
||||||
.HasDatabaseName("ix_discorduser_userid");
|
.HasDatabaseName("ix_discorduser_userid");
|
||||||
|
|
||||||
|
b.HasIndex("Username")
|
||||||
|
.HasDatabaseName("ix_discorduser_username");
|
||||||
|
|
||||||
b.ToTable("discorduser", (string)null);
|
b.ToTable("discorduser", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -995,6 +994,37 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.ToTable("filteredword", (string)null);
|
b.ToTable("filteredword", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.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("NadekoBot.Db.Models.FollowedStream", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.FollowedStream", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -1627,6 +1657,49 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.ToTable("muteduserid", (string)null);
|
b.ToTable("muteduserid", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Db.Models.NCPixel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("Color")
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasColumnName("color");
|
||||||
|
|
||||||
|
b.Property<decimal>("OwnerId")
|
||||||
|
.HasColumnType("numeric(20,0)")
|
||||||
|
.HasColumnName("ownerid");
|
||||||
|
|
||||||
|
b.Property<int>("Position")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("position");
|
||||||
|
|
||||||
|
b.Property<long>("Price")
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasColumnName("price");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)")
|
||||||
|
.HasColumnName("text");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_ncpixel");
|
||||||
|
|
||||||
|
b.HasAlternateKey("Position")
|
||||||
|
.HasName("ak_ncpixel_position");
|
||||||
|
|
||||||
|
b.HasIndex("OwnerId")
|
||||||
|
.HasDatabaseName("ix_ncpixel_ownerid");
|
||||||
|
|
||||||
|
b.ToTable("ncpixel", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.NadekoExpression", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.NadekoExpression", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -2938,9 +3011,9 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
.HasColumnType("timestamp without time zone")
|
.HasColumnType("timestamp without time zone")
|
||||||
.HasColumnName("dateadded");
|
.HasColumnName("dateadded");
|
||||||
|
|
||||||
b.Property<int?>("GuildConfigId")
|
b.Property<decimal>("GuildId")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("numeric(20,0)")
|
||||||
.HasColumnName("guildconfigid");
|
.HasColumnName("guildid");
|
||||||
|
|
||||||
b.Property<int>("Punishment")
|
b.Property<int>("Punishment")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
@@ -2957,8 +3030,8 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.HasKey("Id")
|
b.HasKey("Id")
|
||||||
.HasName("pk_warningpunishment");
|
.HasName("pk_warningpunishment");
|
||||||
|
|
||||||
b.HasIndex("GuildConfigId")
|
b.HasAlternateKey("GuildId", "Count")
|
||||||
.HasDatabaseName("ix_warningpunishment_guildconfigid");
|
.HasName("ak_warningpunishment_guildid_count");
|
||||||
|
|
||||||
b.ToTable("warningpunishment", (string)null);
|
b.ToTable("warningpunishment", (string)null);
|
||||||
});
|
});
|
||||||
@@ -3154,6 +3227,74 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.ToTable("greetsettings", (string)null);
|
b.ToTable("greetsettings", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.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("NadekoBot.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("NadekoBot.Db.Models.AntiAltSetting", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.AntiAltSetting", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
||||||
@@ -3616,15 +3757,6 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.WarningPunishment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
|
||||||
.WithMany("WarnPunishments")
|
|
||||||
.HasForeignKey("GuildConfigId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.HasConstraintName("fk_warningpunishment_guildconfigs_guildconfigid");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.XpCurrencyReward", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.XpCurrencyReward", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Db.Models.XpSettings", "XpSettings")
|
b.HasOne("NadekoBot.Db.Models.XpSettings", "XpSettings")
|
||||||
@@ -3740,8 +3872,6 @@ namespace NadekoBot.Migrations.PostgreSql
|
|||||||
|
|
||||||
b.Navigation("VcRoleInfos");
|
b.Navigation("VcRoleInfos");
|
||||||
|
|
||||||
b.Navigation("WarnPunishments");
|
|
||||||
|
|
||||||
b.Navigation("XpSettings");
|
b.Navigation("XpSettings");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
2919
src/NadekoBot/Migrations/Sqlite/20241018004612_warn-split.Designer.cs
generated
Normal file
2919
src/NadekoBot/Migrations/Sqlite/20241018004612_warn-split.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
72
src/NadekoBot/Migrations/Sqlite/20241018004612_warn-split.cs
Normal file
72
src/NadekoBot/Migrations/Sqlite/20241018004612_warn-split.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class warnsplit : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<ulong>(
|
||||||
|
name: "GuildId",
|
||||||
|
table: "WarningPunishment",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0ul);
|
||||||
|
|
||||||
|
MigrationQueries.AddGuildIdsToWarningPunishment(migrationBuilder);
|
||||||
|
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_WarningPunishment_GuildConfigs_GuildConfigId",
|
||||||
|
table: "WarningPunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_WarningPunishment_GuildConfigId",
|
||||||
|
table: "WarningPunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "GuildConfigId",
|
||||||
|
table: "WarningPunishment");
|
||||||
|
|
||||||
|
migrationBuilder.AddUniqueConstraint(
|
||||||
|
name: "AK_WarningPunishment_GuildId_Count",
|
||||||
|
table: "WarningPunishment",
|
||||||
|
columns: new[] { "GuildId", "Count" });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropUniqueConstraint(
|
||||||
|
name: "AK_WarningPunishment_GuildId_Count",
|
||||||
|
table: "WarningPunishment");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "GuildId",
|
||||||
|
table: "WarningPunishment");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "GuildConfigId",
|
||||||
|
table: "WarningPunishment",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_WarningPunishment_GuildConfigId",
|
||||||
|
table: "WarningPunishment",
|
||||||
|
column: "GuildConfigId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_WarningPunishment_GuildConfigs_GuildConfigId",
|
||||||
|
table: "WarningPunishment",
|
||||||
|
column: "GuildConfigId",
|
||||||
|
principalTable: "GuildConfigs",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2953
src/NadekoBot/Migrations/Sqlite/20241028033656_ncanvas.Designer.cs
generated
Normal file
2953
src/NadekoBot/Migrations/Sqlite/20241028033656_ncanvas.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
53
src/NadekoBot/Migrations/Sqlite/20241028033656_ncanvas.cs
Normal file
53
src/NadekoBot/Migrations/Sqlite/20241028033656_ncanvas.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2973
src/NadekoBot/Migrations/Sqlite/20241102022949_no-discrim-and-flag-translate.Designer.cs
generated
Normal file
2973
src/NadekoBot/Migrations/Sqlite/20241102022949_no-discrim-and-flag-translate.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3011
src/NadekoBot/Migrations/Sqlite/20241104094222_betstats.Designer.cs
generated
Normal file
3011
src/NadekoBot/Migrations/Sqlite/20241104094222_betstats.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
src/NadekoBot/Migrations/Sqlite/20241104094222_betstats.cs
Normal file
47
src/NadekoBot/Migrations/Sqlite/20241104094222_betstats.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3025
src/NadekoBot/Migrations/Sqlite/20241105072953_rakeback.Designer.cs
generated
Normal file
3025
src/NadekoBot/Migrations/Sqlite/20241105072953_rakeback.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
src/NadekoBot/Migrations/Sqlite/20241105072953_rakeback.cs
Normal file
34
src/NadekoBot/Migrations/Sqlite/20241105072953_rakeback.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace NadekoBot.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -560,9 +560,6 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<DateTime?>("DateAdded")
|
b.Property<DateTime?>("DateAdded")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Discriminator")
|
|
||||||
.HasColumnType("TEXT");
|
|
||||||
|
|
||||||
b.Property<bool>("IsClubAdmin")
|
b.Property<bool>("IsClubAdmin")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("INTEGER")
|
.HasColumnType("INTEGER")
|
||||||
@@ -596,6 +593,8 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.HasIndex("Username");
|
||||||
|
|
||||||
b.ToTable("DiscordUser");
|
b.ToTable("DiscordUser");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -741,6 +740,29 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("FilteredWord");
|
b.ToTable("FilteredWord");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.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("NadekoBot.Db.Models.FollowedStream", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.FollowedStream", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -1213,6 +1235,38 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("MutedUserId");
|
b.ToTable("MutedUserId");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Db.Models.NCPixel", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<uint>("Color")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<ulong>("OwnerId")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("Position")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<long>("Price")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<string>("Text")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasAlternateKey("Position");
|
||||||
|
|
||||||
|
b.HasIndex("OwnerId");
|
||||||
|
|
||||||
|
b.ToTable("NCPixel");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.NadekoExpression", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.NadekoExpression", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@@ -2183,7 +2237,7 @@ namespace NadekoBot.Migrations
|
|||||||
b.Property<DateTime?>("DateAdded")
|
b.Property<DateTime?>("DateAdded")
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<int?>("GuildConfigId")
|
b.Property<ulong>("GuildId")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("Punishment")
|
b.Property<int>("Punishment")
|
||||||
@@ -2197,7 +2251,7 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("GuildConfigId");
|
b.HasAlternateKey("GuildId", "Count");
|
||||||
|
|
||||||
b.ToTable("WarningPunishment");
|
b.ToTable("WarningPunishment");
|
||||||
});
|
});
|
||||||
@@ -2345,6 +2399,58 @@ namespace NadekoBot.Migrations
|
|||||||
b.ToTable("GreetSettings");
|
b.ToTable("GreetSettings");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.Services.Rakeback", b =>
|
||||||
|
{
|
||||||
|
b.Property<ulong>("UserId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<decimal>("Amount")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Rakeback");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("NadekoBot.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("NadekoBot.Db.Models.AntiAltSetting", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.AntiAltSetting", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
||||||
@@ -2760,14 +2866,6 @@ namespace NadekoBot.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.WarningPunishment", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("NadekoBot.Db.Models.GuildConfig", null)
|
|
||||||
.WithMany("WarnPunishments")
|
|
||||||
.HasForeignKey("GuildConfigId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("NadekoBot.Db.Models.XpCurrencyReward", b =>
|
modelBuilder.Entity("NadekoBot.Db.Models.XpCurrencyReward", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("NadekoBot.Db.Models.XpSettings", "XpSettings")
|
b.HasOne("NadekoBot.Db.Models.XpSettings", "XpSettings")
|
||||||
@@ -2880,8 +2978,6 @@ namespace NadekoBot.Migrations
|
|||||||
|
|
||||||
b.Navigation("VcRoleInfos");
|
b.Navigation("VcRoleInfos");
|
||||||
|
|
||||||
b.Navigation("WarnPunishments");
|
|
||||||
|
|
||||||
b.Navigation("XpSettings");
|
b.Navigation("XpSettings");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -24,6 +24,13 @@ public partial class Administration
|
|||||||
await Response().Error(strs.hierarchy).SendAsync();
|
await Response().Error(strs.hierarchy).SendAsync();
|
||||||
return;
|
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);
|
var roles = await _service.ToggleAarAsync(ctx.Guild.Id, role.Id);
|
||||||
if (roles.Count == 0)
|
if (roles.Count == 0)
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
#nullable disable
|
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using NadekoBot.Common.ModuleBehaviors;
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
@@ -11,53 +10,63 @@ public class AutoPublishService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IBotCredsProvider _creds;
|
private readonly IBotCredsProvider _creds;
|
||||||
private ConcurrentDictionary<ulong, ulong> _enabled;
|
private ConcurrentDictionary<ulong, ulong> _enabled = new();
|
||||||
|
|
||||||
public AutoPublishService(DbService db, DiscordSocketClient client, IBotCredsProvider creds)
|
public AutoPublishService(DbService db, DiscordSocketClient client, IBotCredsProvider creds)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_client = client;
|
_client = client;
|
||||||
_creds = creds;
|
_creds = creds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
|
public async Task ExecOnNoCommandAsync(IGuild? guild, IUserMessage msg)
|
||||||
{
|
{
|
||||||
if (guild is null)
|
if (guild is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (msg.Channel.GetChannelType() != ChannelType.News)
|
if (msg.Channel.GetChannelType() != ChannelType.News)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_enabled.TryGetValue(guild.Id, out var cid) || cid != msg.Channel.Id)
|
if (!_enabled.TryGetValue(guild.Id, out var cid) || cid != msg.Channel.Id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await msg.CrosspostAsync(new RequestOptions()
|
await msg.CrosspostAsync(new RequestOptions()
|
||||||
{
|
{
|
||||||
RetryMode = RetryMode.AlwaysFail
|
RetryMode = RetryMode.AlwaysFail
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo GUILDS
|
|
||||||
|
|
||||||
public async Task OnReadyAsync()
|
public async Task OnReadyAsync()
|
||||||
{
|
{
|
||||||
var creds = _creds.GetCreds();
|
var creds = _creds.GetCreds();
|
||||||
|
|
||||||
await using var ctx = _db.GetDbContext();
|
await using var ctx = _db.GetDbContext();
|
||||||
var items = await ctx.GetTable<AutoPublishChannel>()
|
var items = await ctx.GetTable<AutoPublishChannel>()
|
||||||
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId, creds.TotalShards, _client.ShardId))
|
.Where(x => Linq2DbExpressions.GuildOnShard(x.GuildId, creds.TotalShards, _client.ShardId))
|
||||||
.ToListAsyncLinqToDB();
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
_enabled = items
|
_enabled = items
|
||||||
.ToDictionary(x => x.GuildId, x => x.ChannelId)
|
.ToDictionary(x => x.GuildId, x => x.ChannelId)
|
||||||
.ToConcurrent();
|
.ToConcurrent();
|
||||||
|
|
||||||
|
_client.LeftGuild += ClientOnLeftGuild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task ClientOnLeftGuild(SocketGuild guild)
|
||||||
|
{
|
||||||
|
await using var ctx = _db.GetDbContext();
|
||||||
|
_enabled.TryRemove(guild.Id, out _);
|
||||||
|
|
||||||
|
await ctx.GetTable<AutoPublishChannel>()
|
||||||
|
.Where(x => x.GuildId == guild.Id)
|
||||||
|
.DeleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> ToggleAutoPublish(ulong guildId, ulong channelId)
|
public async Task<bool> ToggleAutoPublish(ulong guildId, ulong channelId)
|
||||||
{
|
{
|
||||||
await using var ctx = _db.GetDbContext();
|
await using var ctx = _db.GetDbContext();
|
||||||
var deleted = await ctx.GetTable<AutoPublishChannel>()
|
var deleted = await ctx.GetTable<AutoPublishChannel>()
|
||||||
.DeleteAsync(x => x.GuildId == guildId && x.ChannelId == channelId);
|
.DeleteAsync(x => x.GuildId == guildId && x.ChannelId == channelId);
|
||||||
|
|
||||||
if (deleted != 0)
|
if (deleted != 0)
|
||||||
{
|
{
|
||||||
@@ -66,22 +75,22 @@ public class AutoPublishService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
}
|
}
|
||||||
|
|
||||||
await ctx.GetTable<AutoPublishChannel>()
|
await ctx.GetTable<AutoPublishChannel>()
|
||||||
.InsertOrUpdateAsync(() => new()
|
.InsertOrUpdateAsync(() => new()
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
ChannelId = channelId,
|
ChannelId = channelId,
|
||||||
DateAdded = DateTime.UtcNow,
|
DateAdded = DateTime.UtcNow,
|
||||||
},
|
},
|
||||||
old => new()
|
old => new()
|
||||||
{
|
{
|
||||||
ChannelId = channelId,
|
ChannelId = channelId,
|
||||||
DateAdded = DateTime.UtcNow,
|
DateAdded = DateTime.UtcNow,
|
||||||
},
|
},
|
||||||
() => new()
|
() => new()
|
||||||
{
|
{
|
||||||
GuildId = guildId
|
GuildId = guildId
|
||||||
});
|
});
|
||||||
|
|
||||||
_enabled[guildId] = channelId;
|
_enabled[guildId] = channelId;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -206,6 +206,18 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService
|
|||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
|
// delete autopublish channels
|
||||||
|
await ctx.GetTable<AutoPublishChannel>()
|
||||||
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
|
.Contains(x.GuildId))
|
||||||
|
.DeleteAsync();
|
||||||
|
|
||||||
|
// delete greet settings
|
||||||
|
await ctx.GetTable<GreetSettings>()
|
||||||
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
|
.Contains(x.GuildId))
|
||||||
|
.DeleteAsync();
|
||||||
|
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
|
@@ -138,8 +138,7 @@ public partial class Administration
|
|||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public Task DeleteXp()
|
public Task DeleteXp()
|
||||||
=> ConfirmActionInternalAsync("Delete Xp", () => _xcs.DeleteXp());
|
=> ConfirmActionInternalAsync("Delete Xp", () => _xcs.DeleteXp());
|
||||||
|
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public Task DeleteWaifus()
|
public Task DeleteWaifus()
|
||||||
|
@@ -200,9 +200,7 @@ public partial class Administration
|
|||||||
|
|
||||||
if (!isEnabled)
|
if (!isEnabled)
|
||||||
{
|
{
|
||||||
var cmdName = GetCmdName(type);
|
await SendGreetEnableHint(type);
|
||||||
|
|
||||||
await Response().Pending(strs.boostmsg_enable($"`{prefix}{cmdName}`")).SendAsync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,19 +224,24 @@ public partial class Administration
|
|||||||
await _service.Test(ctx.Guild.Id, type, (ITextChannel)ctx.Channel, user);
|
await _service.Test(ctx.Guild.Id, type, (ITextChannel)ctx.Channel, user);
|
||||||
var conf = await _service.GetGreetSettingsAsync(ctx.Guild.Id, type);
|
var conf = await _service.GetGreetSettingsAsync(ctx.Guild.Id, type);
|
||||||
|
|
||||||
|
if (conf?.IsEnabled is not true)
|
||||||
|
await SendGreetEnableHint(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SendGreetEnableHint(GreetType type)
|
||||||
|
{
|
||||||
var cmd = $"`{prefix}{GetCmdName(type)}`";
|
var cmd = $"`{prefix}{GetCmdName(type)}`";
|
||||||
|
|
||||||
var str = type switch
|
var str = type switch
|
||||||
{
|
{
|
||||||
GreetType.Greet => strs.boostmsg_enable(cmd),
|
GreetType.Greet => strs.greetmsg_enable(cmd),
|
||||||
GreetType.Bye => strs.greetmsg_enable(cmd),
|
GreetType.Bye => strs.byemsg_enable(cmd),
|
||||||
GreetType.Boost => strs.byemsg_enable(cmd),
|
GreetType.Boost => strs.boostmsg_enable(cmd),
|
||||||
GreetType.GreetDm => strs.greetdmmsg_enable(cmd),
|
GreetType.GreetDm => strs.greetdmmsg_enable(cmd),
|
||||||
_ => strs.error
|
_ => strs.error
|
||||||
};
|
};
|
||||||
|
|
||||||
if (conf?.IsEnabled is not true)
|
await Response().Pending(str).SendAsync();
|
||||||
await Response().Pending(str).SendAsync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -339,7 +339,7 @@ public class GreetService : INService, IReadyExecutor
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex, "Error sending greet dm");
|
Log.Warning(ex, "Unable to send Greet DM. Probably the user has closed DMs");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -71,7 +71,6 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
if (server.OwnerId != _client.CurrentUser.Id)
|
if (server.OwnerId != _client.CurrentUser.Id)
|
||||||
{
|
{
|
||||||
await server.LeaveAsync();
|
await server.LeaveAsync();
|
||||||
Log.Information("Left server {Name} [{Id}]", server.Name, server.Id);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -453,7 +452,6 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
{
|
{
|
||||||
x.UserId,
|
x.UserId,
|
||||||
x.Username,
|
x.Username,
|
||||||
x.Discriminator
|
|
||||||
})
|
})
|
||||||
.Where(x => users.Select(y => y.Id).Contains(x.UserId))
|
.Where(x => users.Select(y => y.Id).Contains(x.UserId))
|
||||||
.ToArrayAsyncEF();
|
.ToArrayAsyncEF();
|
||||||
@@ -465,12 +463,11 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
UserId = x.Id,
|
UserId = x.Id,
|
||||||
AvatarId = x.AvatarId,
|
AvatarId = x.AvatarId,
|
||||||
Username = x.Username,
|
Username = x.Username,
|
||||||
Discriminator = x.Discriminator
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied;
|
var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied;
|
||||||
var toUpdateUserIds = presentDbUsers
|
var toUpdateUserIds = presentDbUsers
|
||||||
.Where(x => x.Username == "Unknown" && x.Discriminator == "????")
|
.Where(x => x.Username.StartsWith("??"))
|
||||||
.Select(x => x.UserId)
|
.Select(x => x.UserId)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
@@ -481,7 +478,6 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
.UpdateAsync(x => new DiscordUser()
|
.UpdateAsync(x => new DiscordUser()
|
||||||
{
|
{
|
||||||
Username = user.Username,
|
Username = user.Username,
|
||||||
Discriminator = user.Discriminator,
|
|
||||||
|
|
||||||
// .award tends to set AvatarId and DateAdded to NULL, so account for that.
|
// .award tends to set AvatarId and DateAdded to NULL, so account for that.
|
||||||
AvatarId = user.AvatarId,
|
AvatarId = user.AvatarId,
|
||||||
|
@@ -66,10 +66,10 @@ public partial class Administration
|
|||||||
{
|
{
|
||||||
await _sender.Response(user)
|
await _sender.Response(user)
|
||||||
.Embed(_sender.CreateEmbed()
|
.Embed(_sender.CreateEmbed()
|
||||||
.WithErrorColor()
|
.WithErrorColor()
|
||||||
.WithDescription(GetText(strs.warned_on(ctx.Guild.ToString())))
|
.WithDescription(GetText(strs.warned_on(ctx.Guild.ToString())))
|
||||||
.AddField(GetText(strs.moderator), ctx.User.ToString())
|
.AddField(GetText(strs.moderator), ctx.User.ToString())
|
||||||
.AddField(GetText(strs.reason), reason ?? "-"))
|
.AddField(GetText(strs.reason), reason ?? "-"))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -85,8 +85,9 @@ public partial class Administration
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warning(ex, "Exception occured while warning a user");
|
Log.Warning(ex, "Exception occured while warning a user");
|
||||||
var errorEmbed = _sender.CreateEmbed().WithErrorColor()
|
var errorEmbed = _sender.CreateEmbed()
|
||||||
.WithDescription(GetText(strs.cant_apply_punishment));
|
.WithErrorColor()
|
||||||
|
.WithDescription(GetText(strs.cant_apply_punishment));
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
errorEmbed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
errorEmbed.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -117,7 +118,7 @@ public partial class Administration
|
|||||||
[Priority(1)]
|
[Priority(1)]
|
||||||
public async Task WarnExpire()
|
public async Task WarnExpire()
|
||||||
{
|
{
|
||||||
var expireDays = await _service.GetWarnExpire(ctx.Guild.Id);
|
var (expireDays, _) = await _service.GetWarnExpire(ctx.Guild.Id);
|
||||||
|
|
||||||
if (expireDays == 0)
|
if (expireDays == 0)
|
||||||
await Response().Confirm(strs.warns_dont_expire).SendAsync();
|
await Response().Confirm(strs.warns_dont_expire).SendAsync();
|
||||||
@@ -266,9 +267,9 @@ public partial class Administration
|
|||||||
});
|
});
|
||||||
|
|
||||||
return _sender.CreateEmbed()
|
return _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.warnings_list))
|
.WithTitle(GetText(strs.warnings_list))
|
||||||
.WithDescription(string.Join("\n", ws));
|
.WithDescription(string.Join("\n", ws));
|
||||||
})
|
})
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
@@ -278,7 +279,7 @@ public partial class Administration
|
|||||||
[UserPerm(GuildPerm.Administrator)]
|
[UserPerm(GuildPerm.Administrator)]
|
||||||
public Task WarnDelete(IGuildUser user, int index)
|
public Task WarnDelete(IGuildUser user, int index)
|
||||||
=> WarnDelete(user.Id, index);
|
=> WarnDelete(user.Id, index);
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.Administrator)]
|
[UserPerm(GuildPerm.Administrator)]
|
||||||
@@ -286,15 +287,15 @@ public partial class Administration
|
|||||||
{
|
{
|
||||||
if (--index < 0)
|
if (--index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var warn = await _service.WarnDelete(userId, index);
|
var warn = await _service.WarnDelete(ctx.Guild.Id, userId, index);
|
||||||
|
|
||||||
if (warn is null)
|
if (warn is null)
|
||||||
{
|
{
|
||||||
await Response().Error(strs.warning_not_found).SendAsync();
|
await Response().Error(strs.warning_not_found).SendAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Response().Confirm(strs.warning_deleted(Format.Bold(index.ToString()))).SendAsync();
|
await Response().Confirm(strs.warning_deleted(Format.Bold(index.ToString()))).SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +312,7 @@ public partial class Administration
|
|||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var success = await _service.WarnClearAsync(ctx.Guild.Id, userId, index, ctx.User.ToString());
|
var success = await _service.WarnClearAsync(ctx.Guild.Id, userId, index, ctx.User.ToString());
|
||||||
var userStr = Format.Bold((ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString());
|
var userStr = Format.Bold((ctx.Guild as SocketGuild)?.GetUser(userId)?.ToString() ?? userId.ToString());
|
||||||
if (index == 0)
|
if (index == 0)
|
||||||
@@ -344,7 +345,7 @@ public partial class Administration
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time, role);
|
var success = await _service.WarnPunish(ctx.Guild.Id, number, punish, time, role);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return;
|
return;
|
||||||
@@ -380,7 +381,7 @@ public partial class Administration
|
|||||||
if (punish is PunishmentAction.TimeOut && time is null)
|
if (punish is PunishmentAction.TimeOut && time is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time);
|
var success = await _service.WarnPunish(ctx.Guild.Id, number, punish, time);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
return;
|
return;
|
||||||
@@ -407,7 +408,7 @@ public partial class Administration
|
|||||||
[UserPerm(GuildPerm.BanMembers)]
|
[UserPerm(GuildPerm.BanMembers)]
|
||||||
public async Task WarnPunish(int number)
|
public async Task WarnPunish(int number)
|
||||||
{
|
{
|
||||||
if (!_service.WarnPunishRemove(ctx.Guild.Id, number))
|
if (!await _service.WarnPunishRemove(ctx.Guild.Id, number))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Response().Confirm(strs.warn_punish_rem(Format.Bold(number.ToString()))).SendAsync();
|
await Response().Confirm(strs.warn_punish_rem(Format.Bold(number.ToString()))).SendAsync();
|
||||||
@@ -417,7 +418,7 @@ public partial class Administration
|
|||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task WarnPunishList()
|
public async Task WarnPunishList()
|
||||||
{
|
{
|
||||||
var ps = _service.WarnPunishList(ctx.Guild.Id);
|
var ps = await _service.WarnPunishList(ctx.Guild.Id);
|
||||||
|
|
||||||
string list;
|
string list;
|
||||||
if (ps.Any())
|
if (ps.Any())
|
||||||
@@ -478,13 +479,13 @@ public partial class Administration
|
|||||||
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
||||||
await _mute.TimedBan(ctx.Guild, userId, time.Time, (ctx.User + " | " + msg).TrimTo(512), banPrune);
|
await _mute.TimedBan(ctx.Guild, userId, time.Time, (ctx.User + " | " + msg).TrimTo(512), banPrune);
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
||||||
.AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true)
|
.AddField(GetText(strs.username), user?.ToString() ?? userId.ToString(), true)
|
||||||
.AddField("ID", userId.ToString(), true)
|
.AddField("ID", userId.ToString(), true)
|
||||||
.AddField(GetText(strs.duration),
|
.AddField(GetText(strs.duration),
|
||||||
time.Time.ToPrettyStringHm(),
|
time.Time.ToPrettyStringHm(),
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -505,11 +506,12 @@ public partial class Administration
|
|||||||
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
||||||
await ctx.Guild.AddBanAsync(userId, banPrune, (ctx.User + " | " + msg).TrimTo(512));
|
await ctx.Guild.AddBanAsync(userId, banPrune, (ctx.User + " | " + msg).TrimTo(512));
|
||||||
|
|
||||||
await Response().Embed(_sender.CreateEmbed()
|
await Response()
|
||||||
.WithOkColor()
|
.Embed(_sender.CreateEmbed()
|
||||||
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
.WithOkColor()
|
||||||
.AddField("ID", userId.ToString(), true))
|
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
||||||
.SendAsync();
|
.AddField("ID", userId.ToString(), true))
|
||||||
|
.SendAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
await Ban(user, msg);
|
await Ban(user, msg);
|
||||||
@@ -543,10 +545,10 @@ public partial class Administration
|
|||||||
await ctx.Guild.AddBanAsync(user, banPrune, (ctx.User + " | " + msg).TrimTo(512));
|
await ctx.Guild.AddBanAsync(user, banPrune, (ctx.User + " | " + msg).TrimTo(512));
|
||||||
|
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
.WithTitle("⛔️ " + GetText(strs.banned_user))
|
||||||
.AddField(GetText(strs.username), user.ToString(), true)
|
.AddField(GetText(strs.username), user.ToString(), true)
|
||||||
.AddField("ID", user.Id.ToString(), true);
|
.AddField("ID", user.Id.ToString(), true);
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -738,10 +740,10 @@ public partial class Administration
|
|||||||
catch { await ctx.Guild.RemoveBanAsync(user); }
|
catch { await ctx.Guild.RemoveBanAsync(user); }
|
||||||
|
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("☣ " + GetText(strs.sb_user))
|
.WithTitle("☣ " + GetText(strs.sb_user))
|
||||||
.AddField(GetText(strs.username), user.ToString(), true)
|
.AddField(GetText(strs.username), user.ToString(), true)
|
||||||
.AddField("ID", user.Id.ToString(), true);
|
.AddField("ID", user.Id.ToString(), true);
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -793,10 +795,10 @@ public partial class Administration
|
|||||||
await user.KickAsync((ctx.User + " | " + msg).TrimTo(512));
|
await user.KickAsync((ctx.User + " | " + msg).TrimTo(512));
|
||||||
|
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.kicked_user))
|
.WithTitle(GetText(strs.kicked_user))
|
||||||
.AddField(GetText(strs.username), user.ToString(), true)
|
.AddField(GetText(strs.username), user.ToString(), true)
|
||||||
.AddField("ID", user.Id.ToString(), true);
|
.AddField("ID", user.Id.ToString(), true);
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -826,8 +828,8 @@ public partial class Administration
|
|||||||
var dmMessage = GetText(strs.timeoutdm(Format.Bold(ctx.Guild.Name), msg));
|
var dmMessage = GetText(strs.timeoutdm(Format.Bold(ctx.Guild.Name), msg));
|
||||||
await _sender.Response(user)
|
await _sender.Response(user)
|
||||||
.Embed(_sender.CreateEmbed()
|
.Embed(_sender.CreateEmbed()
|
||||||
.WithPendingColor()
|
.WithPendingColor()
|
||||||
.WithDescription(dmMessage))
|
.WithDescription(dmMessage))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -838,10 +840,10 @@ public partial class Administration
|
|||||||
await user.SetTimeOutAsync(time.Time);
|
await user.SetTimeOutAsync(time.Time);
|
||||||
|
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("⏳ " + GetText(strs.timedout_user))
|
.WithTitle("⏳ " + GetText(strs.timedout_user))
|
||||||
.AddField(GetText(strs.username), user.ToString(), true)
|
.AddField(GetText(strs.username), user.ToString(), true)
|
||||||
.AddField("ID", user.Id.ToString(), true);
|
.AddField("ID", user.Id.ToString(), true);
|
||||||
|
|
||||||
if (dmFailed)
|
if (dmFailed)
|
||||||
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
toSend.WithFooter("⚠️ " + GetText(strs.unable_to_dm_user));
|
||||||
@@ -899,9 +901,9 @@ public partial class Administration
|
|||||||
missStr = "-";
|
missStr = "-";
|
||||||
|
|
||||||
var toSend = _sender.CreateEmbed()
|
var toSend = _sender.CreateEmbed()
|
||||||
.WithDescription(GetText(strs.mass_ban_in_progress(banning.Count)))
|
.WithDescription(GetText(strs.mass_ban_in_progress(banning.Count)))
|
||||||
.AddField(GetText(strs.invalid(missing.Count)), missStr)
|
.AddField(GetText(strs.invalid(missing.Count)), missStr)
|
||||||
.WithPendingColor();
|
.WithPendingColor();
|
||||||
|
|
||||||
var banningMessage = await Response().Embed(toSend).SendAsync();
|
var banningMessage = await Response().Embed(toSend).SendAsync();
|
||||||
|
|
||||||
@@ -919,11 +921,13 @@ public partial class Administration
|
|||||||
}
|
}
|
||||||
|
|
||||||
await banningMessage.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
await banningMessage.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
||||||
.WithDescription(
|
.WithDescription(
|
||||||
GetText(strs.mass_ban_completed(banning.Count())))
|
GetText(strs.mass_ban_completed(
|
||||||
.AddField(GetText(strs.invalid(missing.Count)), missStr)
|
banning.Count())))
|
||||||
.WithOkColor()
|
.AddField(GetText(strs.invalid(missing.Count)),
|
||||||
.Build());
|
missStr)
|
||||||
|
.WithOkColor()
|
||||||
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
@@ -945,10 +949,10 @@ public partial class Administration
|
|||||||
//send a message but don't wait for it
|
//send a message but don't wait for it
|
||||||
var banningMessageTask = Response()
|
var banningMessageTask = Response()
|
||||||
.Embed(_sender.CreateEmbed()
|
.Embed(_sender.CreateEmbed()
|
||||||
.WithDescription(
|
.WithDescription(
|
||||||
GetText(strs.mass_kill_in_progress(bans.Count())))
|
GetText(strs.mass_kill_in_progress(bans.Count())))
|
||||||
.AddField(GetText(strs.invalid(missing)), missStr)
|
.AddField(GetText(strs.invalid(missing)), missStr)
|
||||||
.WithPendingColor())
|
.WithPendingColor())
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
|
|
||||||
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
var banPrune = await _service.GetBanPruneAsync(ctx.Guild.Id) ?? 7;
|
||||||
@@ -966,11 +970,11 @@ public partial class Administration
|
|||||||
var banningMessage = await banningMessageTask;
|
var banningMessage = await banningMessageTask;
|
||||||
|
|
||||||
await banningMessage.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
await banningMessage.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
||||||
.WithDescription(
|
.WithDescription(
|
||||||
GetText(strs.mass_kill_completed(bans.Count())))
|
GetText(strs.mass_kill_completed(bans.Count())))
|
||||||
.AddField(GetText(strs.invalid(missing)), missStr)
|
.AddField(GetText(strs.invalid(missing)), missStr)
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.Build());
|
.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WarnExpireOptions : INadekoCommandOptions
|
public class WarnExpireOptions : INadekoCommandOptions
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
using LinqToDB;
|
using LinqToDB;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using NadekoBot.Common.ModuleBehaviors;
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using NadekoBot.Common.TypeReaders.Models;
|
|
||||||
using NadekoBot.Modules.Permissions.Services;
|
using NadekoBot.Modules.Permissions.Services;
|
||||||
using NadekoBot.Db.Models;
|
using NadekoBot.Db.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -83,17 +81,24 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
};
|
};
|
||||||
|
|
||||||
long previousCount;
|
long previousCount;
|
||||||
List<WarningPunishment> ps;
|
var ps = await WarnPunishList(guildId);
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
previousCount = uow.GetTable<Warning>()
|
||||||
|
.Where(w => w.GuildId == guildId && w.UserId == userId && !w.Forgiven)
|
||||||
previousCount = uow.Set<Warning>()
|
|
||||||
.ForId(guildId, userId)
|
|
||||||
.Where(w => !w.Forgiven && w.UserId == userId)
|
|
||||||
.Sum(x => x.Weight);
|
.Sum(x => x.Weight);
|
||||||
|
|
||||||
uow.Set<Warning>().Add(warn);
|
await uow.GetTable<Warning>()
|
||||||
|
.InsertAsync(() => new()
|
||||||
|
{
|
||||||
|
UserId = userId,
|
||||||
|
GuildId = guildId,
|
||||||
|
Forgiven = false,
|
||||||
|
Reason = reason,
|
||||||
|
Moderator = modName,
|
||||||
|
Weight = weight,
|
||||||
|
DateAdded = DateTime.UtcNow,
|
||||||
|
});
|
||||||
|
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
@@ -260,12 +265,12 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
.ToListAsyncLinqToDB();
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
var cleared = await uow.GetTable<Warning>()
|
var cleared = await uow.GetTable<Warning>()
|
||||||
.Where(x => toClear.Contains(x.Id))
|
.Where(x => toClear.Contains(x.Id))
|
||||||
.UpdateAsync(_ => new()
|
.UpdateAsync(_ => new()
|
||||||
{
|
{
|
||||||
Forgiven = true,
|
Forgiven = true,
|
||||||
ForgivenBy = "expiry"
|
ForgivenBy = "expiry"
|
||||||
});
|
});
|
||||||
|
|
||||||
var toDelete = await uow.GetTable<Warning>()
|
var toDelete = await uow.GetTable<Warning>()
|
||||||
.Where(x => uow.GetTable<GuildConfig>()
|
.Where(x => uow.GetTable<GuildConfig>()
|
||||||
@@ -282,8 +287,8 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
.ToListAsyncLinqToDB();
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
var deleted = await uow.GetTable<Warning>()
|
var deleted = await uow.GetTable<Warning>()
|
||||||
.Where(x => toDelete.Contains(x.Id))
|
.Where(x => toDelete.Contains(x.Id))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
if (cleared > 0 || deleted > 0)
|
if (cleared > 0 || deleted > 0)
|
||||||
{
|
{
|
||||||
@@ -324,11 +329,11 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> GetWarnExpire(ulong guildId)
|
public Task<(int, bool)> GetWarnExpire(ulong guildId)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
var config = uow.GuildConfigsForId(guildId, set => set);
|
var config = uow.GuildConfigsForId(guildId, set => set);
|
||||||
return Task.FromResult(config.WarnExpireHours / 24);
|
return Task.FromResult((config.WarnExpireHours / 24, config.WarnExpireAction == WarnExpireAction.Delete));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task WarnExpireAsync(ulong guildId, int days, bool delete)
|
public async Task WarnExpireAsync(ulong guildId, int days, bool delete)
|
||||||
@@ -377,18 +382,19 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WarnPunish(
|
public async Task<bool> WarnPunish(
|
||||||
ulong guildId,
|
ulong guildId,
|
||||||
int number,
|
int number,
|
||||||
PunishmentAction punish,
|
PunishmentAction punish,
|
||||||
StoopidTime time,
|
TimeSpan? time,
|
||||||
IRole role = null)
|
IRole role = null)
|
||||||
{
|
{
|
||||||
// these 3 don't make sense with time
|
// these 3 don't make sense with time
|
||||||
if (punish is PunishmentAction.Softban or PunishmentAction.Kick or PunishmentAction.RemoveRoles
|
if (punish is PunishmentAction.Softban or PunishmentAction.Kick or PunishmentAction.RemoveRoles
|
||||||
&& time is not null)
|
&& time is not null)
|
||||||
return false;
|
return false;
|
||||||
if (number <= 0 || (time is not null && time.Time > TimeSpan.FromDays(49)))
|
|
||||||
|
if (number <= 0 || (time is not null && time > TimeSpan.FromDays(59)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (punish is PunishmentAction.AddRole && role is null)
|
if (punish is PunishmentAction.AddRole && role is null)
|
||||||
@@ -397,47 +403,51 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
if (punish is PunishmentAction.TimeOut && time is null)
|
if (punish is PunishmentAction.TimeOut && time is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
using var uow = _db.GetDbContext();
|
var timeMinutes = (int?)time?.TotalMinutes ?? 0;
|
||||||
var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
var roleId = punish == PunishmentAction.AddRole ? role!.Id : default(ulong?);
|
||||||
var toDelete = ps.Where(x => x.Count == number);
|
await using var uow = _db.GetDbContext();
|
||||||
|
await uow.GetTable<WarningPunishment>()
|
||||||
uow.RemoveRange(toDelete);
|
.InsertOrUpdateAsync(() => new()
|
||||||
|
{
|
||||||
ps.Add(new()
|
GuildId = guildId,
|
||||||
{
|
Count = number,
|
||||||
Count = number,
|
Punishment = punish,
|
||||||
Punishment = punish,
|
Time = timeMinutes,
|
||||||
Time = (int?)time?.Time.TotalMinutes ?? 0,
|
RoleId = roleId
|
||||||
RoleId = punish == PunishmentAction.AddRole ? role!.Id : default(ulong?)
|
},
|
||||||
});
|
_ => new()
|
||||||
uow.SaveChanges();
|
{
|
||||||
|
Punishment = punish,
|
||||||
|
Time = timeMinutes,
|
||||||
|
RoleId = roleId
|
||||||
|
},
|
||||||
|
() => new()
|
||||||
|
{
|
||||||
|
GuildId = guildId,
|
||||||
|
Count = number
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WarnPunishRemove(ulong guildId, int number)
|
public async Task<bool> WarnPunishRemove(ulong guildId, int count)
|
||||||
{
|
{
|
||||||
if (number <= 0)
|
await using var uow = _db.GetDbContext();
|
||||||
return false;
|
var numDeleted = await uow.GetTable<WarningPunishment>()
|
||||||
|
.DeleteAsync(x => x.GuildId == guildId && x.Count == count);
|
||||||
|
|
||||||
using var uow = _db.GetDbContext();
|
return numDeleted > 0;
|
||||||
var ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
|
|
||||||
var p = ps.FirstOrDefault(x => x.Count == number);
|
|
||||||
|
|
||||||
if (p is not null)
|
|
||||||
{
|
|
||||||
uow.Remove(p);
|
|
||||||
uow.SaveChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WarningPunishment[] WarnPunishList(ulong guildId)
|
|
||||||
|
public async Task<WarningPunishment[]> WarnPunishList(ulong guildId)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
return uow.GuildConfigsForId(guildId, gc => gc.Include(x => x.WarnPunishments))
|
|
||||||
.WarnPunishments.OrderBy(x => x.Count)
|
var wps = uow.GetTable<WarningPunishment>()
|
||||||
.ToArray();
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.OrderBy(x => x.Count)
|
||||||
|
.ToArray();
|
||||||
|
return wps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public (IReadOnlyCollection<(string Original, ulong? Id, string Reason)> Bans, int Missing) MassKill(
|
public (IReadOnlyCollection<(string Original, ulong? Id, string Reason)> Bans, int Missing) MassKill(
|
||||||
@@ -607,12 +617,12 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
return await _repSvc.ReplaceAsync(output, repCtx);
|
return await _repSvc.ReplaceAsync(output, repCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Warning> WarnDelete(ulong userId, int index)
|
public async Task<Warning> WarnDelete(ulong guildId, ulong userId, int index)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
var warn = await uow.GetTable<Warning>()
|
var warn = await uow.GetTable<Warning>()
|
||||||
.Where(x => x.UserId == userId)
|
.Where(x => x.GuildId == guildId && x.UserId == userId)
|
||||||
.OrderByDescending(x => x.DateAdded)
|
.OrderByDescending(x => x.DateAdded)
|
||||||
.Skip(index)
|
.Skip(index)
|
||||||
.FirstOrDefaultAsyncLinqToDB();
|
.FirstOrDefaultAsyncLinqToDB();
|
||||||
@@ -626,4 +636,73 @@ public class UserPunishService : INService, IReadyExecutor
|
|||||||
|
|
||||||
return warn;
|
return warn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> WarnDelete(ulong guildId, int id)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
|
var numDeleted = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == guildId && x.Id == id)
|
||||||
|
.DeleteAsync();
|
||||||
|
|
||||||
|
return numDeleted > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<(IReadOnlyCollection<Warning> latest, int totalCount)> GetLatestWarnings(
|
||||||
|
ulong guildId,
|
||||||
|
int page = 1)
|
||||||
|
{
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(page);
|
||||||
|
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
var latest = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.OrderByDescending(x => x.DateAdded)
|
||||||
|
.Skip(10 * (page - 1))
|
||||||
|
.Take(10)
|
||||||
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
|
var totalCount = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.CountAsyncLinqToDB();
|
||||||
|
|
||||||
|
return (latest, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ForgiveWarning(ulong requestGuildId, int warnId, string modName)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
var success = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == requestGuildId && x.Id == warnId)
|
||||||
|
.UpdateAsync(_ => new()
|
||||||
|
{
|
||||||
|
Forgiven = true,
|
||||||
|
ForgivenBy = modName,
|
||||||
|
})
|
||||||
|
== 1;
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<(IReadOnlyCollection<Warning> latest, int totalCount)> GetUserWarnings(
|
||||||
|
ulong guildId,
|
||||||
|
ulong userId,
|
||||||
|
int page)
|
||||||
|
{
|
||||||
|
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(page);
|
||||||
|
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
var latest = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == guildId && x.UserId == userId)
|
||||||
|
.OrderByDescending(x => x.DateAdded)
|
||||||
|
.Skip(10 * (page - 1))
|
||||||
|
.Take(10)
|
||||||
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
|
var totalCount = await uow.GetTable<Warning>()
|
||||||
|
.Where(x => x.GuildId == guildId && x.UserId == userId)
|
||||||
|
.CountAsyncLinqToDB();
|
||||||
|
|
||||||
|
return (latest, totalCount);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -67,7 +67,6 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
|
|||||||
// private readonly GlobalPermissionService _gperm;
|
// private readonly GlobalPermissionService _gperm;
|
||||||
// private readonly CmdCdService _cmdCds;
|
// private readonly CmdCdService _cmdCds;
|
||||||
private readonly IPermissionChecker _permChecker;
|
private readonly IPermissionChecker _permChecker;
|
||||||
private readonly ICommandHandler _cmd;
|
|
||||||
private readonly IBotStrings _strings;
|
private readonly IBotStrings _strings;
|
||||||
private readonly IBot _bot;
|
private readonly IBot _bot;
|
||||||
private readonly IPubSub _pubSub;
|
private readonly IPubSub _pubSub;
|
||||||
@@ -84,7 +83,6 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
|
|||||||
IBotStrings strings,
|
IBotStrings strings,
|
||||||
IBot bot,
|
IBot bot,
|
||||||
DiscordSocketClient client,
|
DiscordSocketClient client,
|
||||||
ICommandHandler cmd,
|
|
||||||
IPubSub pubSub,
|
IPubSub pubSub,
|
||||||
IMessageSenderService sender,
|
IMessageSenderService sender,
|
||||||
IReplacementService repSvc,
|
IReplacementService repSvc,
|
||||||
@@ -93,7 +91,6 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor
|
|||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_client = client;
|
_client = client;
|
||||||
_cmd = cmd;
|
|
||||||
_strings = strings;
|
_strings = strings;
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
_pubSub = pubSub;
|
_pubSub = pubSub;
|
||||||
|
@@ -6,6 +6,10 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
|||||||
|
|
||||||
public sealed class AnimalRace : IDisposable
|
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
|
public enum Phase
|
||||||
{
|
{
|
||||||
WaitingForPlayers,
|
WaitingForPlayers,
|
||||||
@@ -100,7 +104,7 @@ public sealed class AnimalRace : IDisposable
|
|||||||
foreach (var user in _users)
|
foreach (var user in _users)
|
||||||
{
|
{
|
||||||
if (user.Bet > 0)
|
if (user.Bet > 0)
|
||||||
await _currency.AddAsync(user.UserId, user.Bet, new("animalrace", "refund"));
|
await _currency.AddAsync(user.UserId, (long)(user.Bet * BASE_MULTIPLIER), new("animalrace", "refund"));
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = OnStartingFailed?.Invoke(this);
|
_ = OnStartingFailed?.Invoke(this);
|
||||||
@@ -116,7 +120,7 @@ public sealed class AnimalRace : IDisposable
|
|||||||
{
|
{
|
||||||
foreach (var user in _users)
|
foreach (var user in _users)
|
||||||
{
|
{
|
||||||
user.Progress += rng.Next(1, 11);
|
user.Progress += rng.Next(1, 10);
|
||||||
if (user.Progress >= 60)
|
if (user.Progress >= 60)
|
||||||
user.Progress = 60;
|
user.Progress = 60;
|
||||||
}
|
}
|
||||||
@@ -126,13 +130,15 @@ public sealed class AnimalRace : IDisposable
|
|||||||
FinishedUsers.AddRange(finished);
|
FinishedUsers.AddRange(finished);
|
||||||
|
|
||||||
_ = OnStateUpdate?.Invoke(this);
|
_ = OnStateUpdate?.Invoke(this);
|
||||||
await Task.Delay(2500);
|
await Task.Delay(1750);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FinishedUsers[0].Bet > 0)
|
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,
|
await _currency.AddAsync(FinishedUsers[0].UserId,
|
||||||
FinishedUsers[0].Bet * (_users.Count - 1),
|
(long)(FinishedUsers[0].Bet * Multi),
|
||||||
new("animalrace", "win"));
|
new("animalrace", "win"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +146,8 @@ public sealed class AnimalRace : IDisposable
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double Multi { get; set; } = BASE_MULTIPLIER;
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
CurrentPhase = Phase.Ended;
|
CurrentPhase = Phase.Ended;
|
||||||
|
@@ -12,7 +12,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class AnimalRacingCommands : GamblingSubmodule<AnimalRaceService>
|
public partial class AnimalRacingCommands : GamblingModule<AnimalRaceService>
|
||||||
{
|
{
|
||||||
private readonly ICurrencyService _cs;
|
private readonly ICurrencyService _cs;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
@@ -74,10 +74,14 @@ public partial class Gambling
|
|||||||
if (race.FinishedUsers[0].Bet > 0)
|
if (race.FinishedUsers[0].Bet > 0)
|
||||||
{
|
{
|
||||||
return Response()
|
return Response()
|
||||||
.Confirm(GetText(strs.animal_race),
|
.Embed(_sender.CreateEmbed()
|
||||||
GetText(strs.animal_race_won_money(Format.Bold(winner.Username),
|
.WithOkColor()
|
||||||
winner.Animal.Icon,
|
.WithTitle(GetText(strs.animal_race))
|
||||||
(race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign)))
|
.WithDescription(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}"))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,14 +117,14 @@ public partial class Gambling
|
|||||||
|
|
||||||
private async Task Ar_OnStateUpdate(AnimalRace race)
|
private async Task Ar_OnStateUpdate(AnimalRace race)
|
||||||
{
|
{
|
||||||
var text = $@"|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|
|
var text = $@"|🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁🔚|
|
||||||
{string.Join("\n", race.Users.Select(p =>
|
{string.Join("\n", race.Users.Select(p =>
|
||||||
{
|
{
|
||||||
var index = race.FinishedUsers.IndexOf(p);
|
var index = race.FinishedUsers.IndexOf(p);
|
||||||
var extra = index == -1 ? "" : $"#{index + 1} {(index == 0 ? "🏆" : "")}";
|
var extra = index == -1 ? "" : $"#{index + 1} {(index == 0 ? "🏆" : "")}";
|
||||||
return $"{(int)(p.Progress / 60f * 100),-2}%|{new string('‣', p.Progress) + p.Animal.Icon + extra}";
|
return $"{(int)(p.Progress / 60f * 100),-2}%|{new string('‣', p.Progress) + p.Animal.Icon + extra}";
|
||||||
}))}
|
}))}
|
||||||
|🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|";
|
|🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🏁 🔚|";
|
||||||
|
|
||||||
var msg = raceMessage;
|
var msg = raceMessage;
|
||||||
|
|
||||||
@@ -129,10 +133,10 @@ public partial class Gambling
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
await msg.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
await msg.ModifyAsync(x => x.Embed = _sender.CreateEmbed()
|
||||||
.WithTitle(GetText(strs.animal_race))
|
.WithTitle(GetText(strs.animal_race))
|
||||||
.WithDescription(text)
|
.WithDescription(text)
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.Build());
|
.Build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
175
src/NadekoBot/Modules/Gambling/BetStatsCommands.cs
Normal file
175
src/NadekoBot/Modules/Gambling/BetStatsCommands.cs
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
#nullable disable
|
||||||
|
using NadekoBot.Modules.Gambling.Common;
|
||||||
|
using NadekoBot.Modules.Gambling.Services;
|
||||||
|
|
||||||
|
namespace NadekoBot.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 NadekoBot.Modules.Gambling;
|
|||||||
|
|
||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
public partial class BlackJackCommands : GamblingSubmodule<BlackJackService>
|
public partial class BlackJackCommands : GamblingModule<BlackJackService>
|
||||||
{
|
{
|
||||||
public enum BjAction
|
public enum BjAction
|
||||||
{
|
{
|
||||||
|
@@ -9,7 +9,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class Connect4Commands : GamblingSubmodule<GamblingService>
|
public partial class Connect4Commands : GamblingModule<GamblingService>
|
||||||
{
|
{
|
||||||
private static readonly string[] _numbers =
|
private static readonly string[] _numbers =
|
||||||
[
|
[
|
||||||
|
@@ -12,7 +12,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class DrawCommands : GamblingSubmodule<IGamblingService>
|
public partial class DrawCommands : GamblingModule<IGamblingService>
|
||||||
{
|
{
|
||||||
private static readonly ConcurrentDictionary<IGuild, Deck> _allDecks = new();
|
private static readonly ConcurrentDictionary<IGuild, Deck> _allDecks = new();
|
||||||
private readonly IImageCache _images;
|
private readonly IImageCache _images;
|
||||||
|
@@ -9,7 +9,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class CurrencyEventsCommands : GamblingSubmodule<CurrencyEventsService>
|
public partial class CurrencyEventsCommands : GamblingModule<CurrencyEventsService>
|
||||||
{
|
{
|
||||||
public CurrencyEventsCommands(GamblingConfigService gamblingConf)
|
public CurrencyEventsCommands(GamblingConfigService gamblingConf)
|
||||||
: base(gamblingConf)
|
: base(gamblingConf)
|
||||||
|
@@ -11,7 +11,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class FlipCoinCommands : GamblingSubmodule<IGamblingService>
|
public partial class FlipCoinCommands : GamblingModule<IGamblingService>
|
||||||
{
|
{
|
||||||
public enum BetFlipGuess : byte
|
public enum BetFlipGuess : byte
|
||||||
{
|
{
|
||||||
|
@@ -14,6 +14,13 @@ using System.Text;
|
|||||||
using NadekoBot.Modules.Gambling.Rps;
|
using NadekoBot.Modules.Gambling.Rps;
|
||||||
using NadekoBot.Common.TypeReaders;
|
using NadekoBot.Common.TypeReaders;
|
||||||
using NadekoBot.Modules.Patronage;
|
using NadekoBot.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 NadekoBot.Modules.Gambling;
|
namespace NadekoBot.Modules.Gambling;
|
||||||
|
|
||||||
@@ -26,10 +33,12 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
private readonly NumberFormatInfo _enUsCulture;
|
private readonly NumberFormatInfo _enUsCulture;
|
||||||
private readonly DownloadTracker _tracker;
|
private readonly DownloadTracker _tracker;
|
||||||
private readonly GamblingConfigService _configService;
|
private readonly GamblingConfigService _configService;
|
||||||
|
private readonly FontProvider _fonts;
|
||||||
private readonly IBankService _bank;
|
private readonly IBankService _bank;
|
||||||
private readonly IRemindService _remind;
|
private readonly IRemindService _remind;
|
||||||
private readonly GamblingTxTracker _gamblingTxTracker;
|
private readonly GamblingTxTracker _gamblingTxTracker;
|
||||||
private readonly IPatronageService _ps;
|
private readonly IPatronageService _ps;
|
||||||
|
private readonly RakebackService _rb;
|
||||||
|
|
||||||
public Gambling(
|
public Gambling(
|
||||||
IGamblingService gs,
|
IGamblingService gs,
|
||||||
@@ -38,10 +47,12 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
DiscordSocketClient client,
|
DiscordSocketClient client,
|
||||||
DownloadTracker tracker,
|
DownloadTracker tracker,
|
||||||
GamblingConfigService configService,
|
GamblingConfigService configService,
|
||||||
|
FontProvider fonts,
|
||||||
IBankService bank,
|
IBankService bank,
|
||||||
IRemindService remind,
|
IRemindService remind,
|
||||||
IPatronageService patronage,
|
IPatronageService patronage,
|
||||||
GamblingTxTracker gamblingTxTracker)
|
GamblingTxTracker gamblingTxTracker,
|
||||||
|
RakebackService rb)
|
||||||
: base(configService)
|
: base(configService)
|
||||||
{
|
{
|
||||||
_gs = gs;
|
_gs = gs;
|
||||||
@@ -51,13 +62,16 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
_bank = bank;
|
_bank = bank;
|
||||||
_remind = remind;
|
_remind = remind;
|
||||||
_gamblingTxTracker = gamblingTxTracker;
|
_gamblingTxTracker = gamblingTxTracker;
|
||||||
|
_rb = rb;
|
||||||
_ps = patronage;
|
_ps = patronage;
|
||||||
|
_rng = new NadekoRandom();
|
||||||
|
|
||||||
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
||||||
_enUsCulture.NumberDecimalDigits = 0;
|
_enUsCulture.NumberDecimalDigits = 0;
|
||||||
_enUsCulture.NumberGroupSeparator = " ";
|
_enUsCulture.NumberGroupSeparator = " ";
|
||||||
_tracker = tracker;
|
_tracker = tracker;
|
||||||
_configService = configService;
|
_configService = configService;
|
||||||
|
_fonts = fonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetBalanceStringAsync(ulong userId)
|
public async Task<string> GetBalanceStringAsync(ulong userId)
|
||||||
@@ -66,42 +80,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
return N(bal);
|
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)
|
private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when)
|
||||||
{
|
{
|
||||||
@@ -140,7 +118,21 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms)))
|
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms)))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private NadekoInteractionBase 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]
|
[Cmd]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task Timely()
|
public async Task Timely()
|
||||||
{
|
{
|
||||||
var val = Config.Timely.Amount;
|
var val = Config.Timely.Amount;
|
||||||
@@ -151,6 +143,71 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
return;
|
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)
|
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
|
||||||
{
|
{
|
||||||
// Get correct time form remainder
|
// Get correct time form remainder
|
||||||
@@ -169,6 +226,30 @@ 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 patron = await _ps.GetPatronAsync(ctx.User.Id);
|
||||||
|
|
||||||
var percentBonus = (_ps.PercentBonus(patron) / 100f);
|
var percentBonus = (_ps.PercentBonus(patron) / 100f);
|
||||||
@@ -179,7 +260,21 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
|
|
||||||
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
|
||||||
|
|
||||||
await Response().Confirm(strs.timely(N(val), period)).Interaction(inter).SendAsync();
|
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}!*";
|
||||||
|
|
||||||
|
if (percentBonus > float.Epsilon)
|
||||||
|
msg +=
|
||||||
|
$"*+{percentBonus:P0} bonus for the [Patreon](https://patreon.com/nadekobot) pledge! <:hart:746995901758832712>*";
|
||||||
|
|
||||||
|
await Response().Confirm(msg).Interaction(inter).SendAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
await Response().Confirm(strs.timely(N(val), period)).Interaction(inter).SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
@@ -290,8 +385,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
}
|
}
|
||||||
|
|
||||||
var embed = _sender.CreateEmbed()
|
var embed = _sender.CreateEmbed()
|
||||||
.WithTitle(GetText(strs.transactions(((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
.WithTitle(GetText(strs.transactions(
|
||||||
?? $"{userId}")))
|
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
||||||
|
?? $"{userId}")))
|
||||||
.WithOkColor();
|
.WithOkColor();
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@@ -547,7 +643,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
}
|
}
|
||||||
else
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,7 +666,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
}
|
}
|
||||||
else
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,6 +862,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
private static readonly ImmutableArray<string> _emojis =
|
private static readonly ImmutableArray<string> _emojis =
|
||||||
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
||||||
|
|
||||||
|
private readonly NadekoRandom _rng;
|
||||||
|
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
||||||
@@ -900,4 +1002,45 @@ public partial class Gambling : GamblingModule<GamblingService>
|
|||||||
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
|
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NadekoInteractionBase 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 NadekoBot.Modules.Gambling.Common;
|
|||||||
public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
||||||
{
|
{
|
||||||
[Comment("""DO NOT CHANGE""")]
|
[Comment("""DO NOT CHANGE""")]
|
||||||
public int Version { get; set; } = 8;
|
public int Version { get; set; } = 12;
|
||||||
|
|
||||||
[Comment("""Currency settings""")]
|
[Comment("""Currency settings""")]
|
||||||
public CurrencyConfig Currency { get; set; }
|
public CurrencyConfig Currency { get; set; }
|
||||||
@@ -67,6 +67,11 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
|||||||
[Comment("""Slot config""")]
|
[Comment("""Slot config""")]
|
||||||
public SlotsConfig Slots { get; set; }
|
public SlotsConfig Slots { get; set; }
|
||||||
|
|
||||||
|
[Comment("""
|
||||||
|
Bonus config for server boosts
|
||||||
|
""")]
|
||||||
|
public BoostBonusConfig BoostBonus { get; set; }
|
||||||
|
|
||||||
public GamblingConfig()
|
public GamblingConfig()
|
||||||
{
|
{
|
||||||
BetRoll = new();
|
BetRoll = new();
|
||||||
@@ -79,6 +84,7 @@ public sealed partial class GamblingConfig : ICloneable<GamblingConfig>
|
|||||||
Slots = new();
|
Slots = new();
|
||||||
LuckyLadder = new();
|
LuckyLadder = new();
|
||||||
BotCuts = new();
|
BotCuts = new();
|
||||||
|
BoostBonus = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,13 +110,26 @@ public partial class TimelyConfig
|
|||||||
How much currency will the users get every time they run .timely command
|
How much currency will the users get every time they run .timely command
|
||||||
setting to 0 or less will disable this feature
|
setting to 0 or less will disable this feature
|
||||||
""")]
|
""")]
|
||||||
public int Amount { get; set; } = 0;
|
public long Amount { get; set; } = 0;
|
||||||
|
|
||||||
[Comment("""
|
[Comment("""
|
||||||
How often (in hours) can users claim currency with .timely command
|
How often (in hours) can users claim currency with .timely command
|
||||||
setting to 0 or less will disable this feature
|
setting to 0 or less will disable this feature
|
||||||
""")]
|
""")]
|
||||||
public int Cooldown { get; set; } = 24;
|
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]
|
[Cloneable]
|
||||||
@@ -145,7 +164,7 @@ public partial class BetRollConfig
|
|||||||
},
|
},
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
WhenAbove = 66,
|
WhenAbove = 65,
|
||||||
MultiplyBy = 2
|
MultiplyBy = 2
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -207,7 +226,7 @@ public partial class LuckyLadderSettings
|
|||||||
public decimal[] Multipliers { get; set; }
|
public decimal[] Multipliers { get; set; }
|
||||||
|
|
||||||
public LuckyLadderSettings()
|
public LuckyLadderSettings()
|
||||||
=> Multipliers = [2.4M, 1.7M, 1.5M, 1.2M, 0.5M, 0.3M, 0.2M, 0.1M];
|
=> Multipliers = [2.4M, 1.7M, 1.5M, 1.1M, 0.5M, 0.3M, 0.2M, 0.1M];
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cloneable]
|
[Cloneable]
|
||||||
@@ -408,4 +427,15 @@ public sealed partial class BotCutConfig
|
|||||||
Default 0.1 (10%).
|
Default 0.1 (10%).
|
||||||
""")]
|
""")]
|
||||||
public decimal ShopSaleCut { get; set; } = 0.1m;
|
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,6 +144,11 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||||||
ConfigPrinters.ToString,
|
ConfigPrinters.ToString,
|
||||||
val => val >= 0);
|
val => val >= 0);
|
||||||
|
|
||||||
|
AddParsedProp("timely.prot",
|
||||||
|
gs => gs.Timely.ProtType,
|
||||||
|
ConfigParsers.InsensitiveEnum,
|
||||||
|
ConfigPrinters.ToString);
|
||||||
|
|
||||||
Migrate();
|
Migrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,22 +172,6 @@ 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)
|
if (data.Version < 7)
|
||||||
{
|
{
|
||||||
ModifyConfig(c =>
|
ModifyConfig(c =>
|
||||||
@@ -199,5 +188,18 @@ public sealed class GamblingConfigService : ConfigServiceBase<GamblingConfig>
|
|||||||
c.Waifu.Decay.UnclaimedDecayPercent = 0;
|
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,6 +16,7 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly IBotCache _cache;
|
private readonly IBotCache _cache;
|
||||||
private readonly GamblingConfigService _gss;
|
private readonly GamblingConfigService _gss;
|
||||||
|
private readonly NadekoRandom _rng;
|
||||||
|
|
||||||
private static readonly TypedKey<long> _curDecayKey = new("currency:last_decay");
|
private static readonly TypedKey<long> _curDecayKey = new("currency:last_decay");
|
||||||
|
|
||||||
@@ -29,11 +30,19 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
_client = client;
|
_client = client;
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
_gss = gss;
|
_gss = gss;
|
||||||
|
_rng = new NadekoRandom();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task OnReadyAsync()
|
public Task OnReadyAsync()
|
||||||
=> Task.WhenAll(CurrencyDecayLoopAsync(), TransactionClearLoopAsync());
|
=> 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()
|
private async Task TransactionClearLoopAsync()
|
||||||
{
|
{
|
||||||
if (_client.ShardId != 0)
|
if (_client.ShardId != 0)
|
||||||
@@ -52,7 +61,7 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
var days = TimeSpan.FromDays(lifetime);
|
var days = TimeSpan.FromDays(lifetime);
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
await uow.Set<CurrencyTransaction>()
|
await uow.Set<CurrencyTransaction>()
|
||||||
.DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days);
|
.DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -90,11 +99,11 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.Information("""
|
Log.Information("""
|
||||||
--- Decaying users' currency ---
|
--- Decaying users' currency ---
|
||||||
| decay: {ConfigDecayPercent}%
|
| decay: {ConfigDecayPercent}%
|
||||||
| max: {MaxDecay}
|
| max: {MaxDecay}
|
||||||
| threshold: {DecayMinTreshold}
|
| threshold: {DecayMinTreshold}
|
||||||
""",
|
""",
|
||||||
config.Decay.Percent * 100,
|
config.Decay.Percent * 100,
|
||||||
maxDecay,
|
maxDecay,
|
||||||
config.Decay.MinThreshold);
|
config.Decay.MinThreshold);
|
||||||
@@ -104,14 +113,14 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
|
|
||||||
var decay = (double)config.Decay.Percent;
|
var decay = (double)config.Decay.Percent;
|
||||||
await uow.Set<DiscordUser>()
|
await uow.Set<DiscordUser>()
|
||||||
.Where(x => x.CurrencyAmount > config.Decay.MinThreshold && x.UserId != _client.CurrentUser.Id)
|
.Where(x => x.CurrencyAmount > config.Decay.MinThreshold && x.UserId != _client.CurrentUser.Id)
|
||||||
.UpdateAsync(old => new()
|
.UpdateAsync(old => new()
|
||||||
{
|
{
|
||||||
CurrencyAmount =
|
CurrencyAmount =
|
||||||
maxDecay > Sql.Round((old.CurrencyAmount * decay) - 0.5)
|
maxDecay > Sql.Round((old.CurrencyAmount * decay) - 0.5)
|
||||||
? (long)(old.CurrencyAmount - Sql.Round((old.CurrencyAmount * decay) - 0.5))
|
? (long)(old.CurrencyAmount - Sql.Round((old.CurrencyAmount * decay) - 0.5))
|
||||||
: old.CurrencyAmount - maxDecay
|
: old.CurrencyAmount - maxDecay
|
||||||
});
|
});
|
||||||
|
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -133,6 +142,7 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
private static TypedKey<Dictionary<ulong, long>> _timelyKey
|
private static TypedKey<Dictionary<ulong, long>> _timelyKey
|
||||||
= new("timely:claims");
|
= new("timely:claims");
|
||||||
|
|
||||||
|
|
||||||
public async Task<TimeSpan?> ClaimTimelyAsync(ulong userId, int period)
|
public async Task<TimeSpan?> ClaimTimelyAsync(ulong userId, int period)
|
||||||
{
|
{
|
||||||
if (period == 0)
|
if (period == 0)
|
||||||
@@ -178,9 +188,10 @@ public class GamblingService : INService, IReadyExecutor
|
|||||||
public bool UserHasTimelyReminder(ulong userId)
|
public bool UserHasTimelyReminder(ulong userId)
|
||||||
{
|
{
|
||||||
var db = _db.GetDbContext();
|
var db = _db.GetDbContext();
|
||||||
return db.GetTable<Reminder>().Any(x => x.UserId == userId
|
return db.GetTable<Reminder>()
|
||||||
&& x.Type == ReminderType.Timely);
|
.Any(x => x.UserId == userId
|
||||||
}
|
&& x.Type == ReminderType.Timely);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task RemoveAllTimelyClaimsAsync()
|
public async Task RemoveAllTimelyClaimsAsync()
|
||||||
=> await _cache.RemoveAsync(_timelyKey);
|
=> await _cache.RemoveAsync(_timelyKey);
|
||||||
|
@@ -57,12 +57,4 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
|
|||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
return InternalCheckBet(amount);
|
return InternalCheckBet(amount);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class GamblingSubmodule<TService> : GamblingModule<TService>
|
|
||||||
{
|
|
||||||
protected GamblingSubmodule(GamblingConfigService gamblingConfService)
|
|
||||||
: base(gamblingConfService)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -8,7 +8,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class PlantPickCommands : GamblingSubmodule<PlantPickService>
|
public partial class PlantPickCommands : GamblingModule<PlantPickService>
|
||||||
{
|
{
|
||||||
private readonly ILogCommandService _logService;
|
private readonly ILogCommandService _logService;
|
||||||
|
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NadekoBot.Common.ModuleBehaviors;
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using NadekoBot.Db.Models;
|
using NadekoBot.Db.Models;
|
||||||
using SixLabors.Fonts;
|
using SixLabors.Fonts;
|
||||||
|
using SixLabors.Fonts.Unicode;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Drawing.Processing;
|
using SixLabors.ImageSharp.Drawing.Processing;
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
@@ -25,6 +28,7 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
private readonly NadekoRandom _rng;
|
private readonly NadekoRandom _rng;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly GamblingConfigService _gss;
|
private readonly GamblingConfigService _gss;
|
||||||
|
private readonly GamblingService _gs;
|
||||||
|
|
||||||
private readonly ConcurrentHashSet<ulong> _generationChannels;
|
private readonly ConcurrentHashSet<ulong> _generationChannels;
|
||||||
private readonly SemaphoreSlim _pickLock = new(1, 1);
|
private readonly SemaphoreSlim _pickLock = new(1, 1);
|
||||||
@@ -37,7 +41,8 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
ICurrencyService cs,
|
ICurrencyService cs,
|
||||||
CommandHandler cmdHandler,
|
CommandHandler cmdHandler,
|
||||||
DiscordSocketClient client,
|
DiscordSocketClient client,
|
||||||
GamblingConfigService gss)
|
GamblingConfigService gss,
|
||||||
|
GamblingService gs)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_strings = strings;
|
_strings = strings;
|
||||||
@@ -48,6 +53,7 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
_rng = new();
|
_rng = new();
|
||||||
_client = client;
|
_client = client;
|
||||||
_gss = gss;
|
_gss = gss;
|
||||||
|
_gs = gs;
|
||||||
|
|
||||||
using var uow = db.GetDbContext();
|
using var uow = db.GetDbContext();
|
||||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||||
@@ -87,6 +93,7 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
|
var toDelete = guildConfig.GenerateCurrencyChannelIds.FirstOrDefault(x => x.Equals(toAdd));
|
||||||
if (toDelete is not null)
|
if (toDelete is not null)
|
||||||
uow.Remove(toDelete);
|
uow.Remove(toDelete);
|
||||||
|
|
||||||
_generationChannels.TryRemove(cid);
|
_generationChannels.TryRemove(cid);
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
@@ -140,7 +147,7 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
pass = pass.TrimTo(10, true).ToLowerInvariant();
|
pass = pass.TrimTo(10, true).ToLowerInvariant();
|
||||||
using var img = Image.Load<Rgba32>(curImg);
|
using var img = Image.Load<Rgba32>(curImg);
|
||||||
// choose font size based on the image height, so that it's visible
|
// choose font size based on the image height, so that it's visible
|
||||||
var font = _fonts.NotoSans.CreateFont(img.Height / 12.0f, FontStyle.Bold);
|
var font = _fonts.NotoSans.CreateFont(img.Height / 11.0f, FontStyle.Bold);
|
||||||
img.Mutate(x =>
|
img.Mutate(x =>
|
||||||
{
|
{
|
||||||
// measure the size of the text to be drawing
|
// measure the size of the text to be drawing
|
||||||
@@ -152,13 +159,31 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
|
|
||||||
// fill the background with black, add 5 pixels on each side to make it look better
|
// fill the background with black, add 5 pixels on each side to make it look better
|
||||||
x.FillPolygon(Color.ParseHex("00000080"),
|
x.FillPolygon(Color.ParseHex("00000080"),
|
||||||
new PointF(0, 0),
|
new PointF(1, 1),
|
||||||
new PointF(size.Width + 5, 0),
|
new PointF(size.Width + 5, 0),
|
||||||
new PointF(size.Width + 5, size.Height + 10),
|
new PointF(size.Width + 5, size.Height + 10),
|
||||||
new PointF(0, 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
|
// draw the password over the background
|
||||||
x.DrawText(pass, font, Color.White, new(0, 0));
|
x.DrawText(new RichTextOptions(font)
|
||||||
|
{
|
||||||
|
Origin = new(0, 0),
|
||||||
|
TextRuns =
|
||||||
|
[
|
||||||
|
strikeoutRun
|
||||||
|
]
|
||||||
|
},
|
||||||
|
pass,
|
||||||
|
new SolidBrush(Color.White));
|
||||||
});
|
});
|
||||||
// return image as a stream for easy sending
|
// return image as a stream for easy sending
|
||||||
var format = img.Metadata.DecodedImageFormat;
|
var format = img.Metadata.DecodedImageFormat;
|
||||||
@@ -208,7 +233,7 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
+ " "
|
+ " "
|
||||||
+ GetText(channel.GuildId, strs.pick_pl(prefix));
|
+ GetText(channel.GuildId, strs.pick_pl(prefix));
|
||||||
|
|
||||||
var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null;
|
var pw = config.Generation.HasPassword ? _gs.GeneratePassword().ToUpperInvariant() : null;
|
||||||
|
|
||||||
IUserMessage sent;
|
IUserMessage sent;
|
||||||
var (stream, ext) = await GetRandomCurrencyImageAsync(pw);
|
var (stream, ext) = await GetRandomCurrencyImageAsync(pw);
|
||||||
@@ -232,67 +257,44 @@ public class PlantPickService : INService, IExecNoCommand
|
|||||||
return Task.CompletedTask;
|
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(
|
public async Task<long> PickAsync(
|
||||||
ulong gid,
|
ulong gid,
|
||||||
ITextChannel ch,
|
ITextChannel ch,
|
||||||
ulong uid,
|
ulong uid,
|
||||||
string pass)
|
string pass)
|
||||||
{
|
{
|
||||||
await _pickLock.WaitAsync();
|
long amount;
|
||||||
|
ulong[] ids;
|
||||||
|
await using (var uow = _db.GetDbContext())
|
||||||
|
{
|
||||||
|
// 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();
|
||||||
|
// gets all plants in this channel with the same password
|
||||||
|
var entries = await uow.GetTable<PlantedCurrency>()
|
||||||
|
.Where(x => x.ChannelId == ch.Id && pass == x.Password)
|
||||||
|
.DeleteWithOutputAsync();
|
||||||
|
|
||||||
|
if (!entries.Any())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
amount = entries.Sum(x => x.Amount);
|
||||||
|
ids = entries.Select(x => x.MessageId).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount > 0)
|
||||||
|
await _cs.AddAsync(uid, amount, new("currency", "collect"));
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long amount;
|
_ = ch.DeleteMessagesAsync(ids);
|
||||||
ulong[] ids;
|
|
||||||
await using (var uow = _db.GetDbContext())
|
|
||||||
{
|
|
||||||
// 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();
|
|
||||||
// gets all plants in this channel with the same password
|
|
||||||
var entries = uow.Set<PlantedCurrency>()
|
|
||||||
.AsQueryable()
|
|
||||||
.Where(x => x.ChannelId == ch.Id && pass == x.Password)
|
|
||||||
.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 { }
|
|
||||||
|
|
||||||
// return the amount of currency the user picked
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
_pickLock.Release();
|
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
// return the amount of currency the user picked
|
||||||
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ulong?> SendPlantMessageAsync(
|
public async Task<ulong?> SendPlantMessageAsync(
|
||||||
|
@@ -10,7 +10,7 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class ShopCommands : GamblingSubmodule<IShopService>
|
public partial class ShopCommands : GamblingModule<IShopService>
|
||||||
{
|
{
|
||||||
public enum List
|
public enum List
|
||||||
{
|
{
|
||||||
|
@@ -21,7 +21,7 @@ public enum GamblingError
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class SlotCommands : GamblingSubmodule<IGamblingService>
|
public partial class SlotCommands : GamblingModule<IGamblingService>
|
||||||
{
|
{
|
||||||
private readonly IImageCache _images;
|
private readonly IImageCache _images;
|
||||||
private readonly FontProvider _fonts;
|
private readonly FontProvider _fonts;
|
||||||
|
55
src/NadekoBot/Modules/Gambling/UserBetStatsService.cs
Normal file
55
src/NadekoBot/Modules/Gambling/UserBetStatsService.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using NadekoBot.Db.Models;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Gambling.Services;
|
||||||
|
|
||||||
|
public sealed class UserBetStatsService : INService
|
||||||
|
{
|
||||||
|
private const long RESET_MIN_PRICE = 1000;
|
||||||
|
private const decimal RESET_TOTAL_MULTIPLIER = 0.02m;
|
||||||
|
|
||||||
|
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 NadekoBot.Modules.Gambling;
|
|||||||
public partial class Gambling
|
public partial class Gambling
|
||||||
{
|
{
|
||||||
[Group]
|
[Group]
|
||||||
public partial class WaifuClaimCommands : GamblingSubmodule<WaifuService>
|
public partial class WaifuClaimCommands : GamblingModule<WaifuService>
|
||||||
{
|
{
|
||||||
public WaifuClaimCommands(GamblingConfigService gamblingConfService)
|
public WaifuClaimCommands(GamblingConfigService gamblingConfService)
|
||||||
: base(gamblingConfService)
|
: base(gamblingConfService)
|
||||||
@@ -37,6 +37,45 @@ public partial class Gambling
|
|||||||
await Response().Error(strs.waifu_reset_fail).SendAsync();
|
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]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task WaifuClaim(long amount, [Leftover] IUser target)
|
public async Task WaifuClaim(long amount, [Leftover] IUser target)
|
||||||
@@ -74,7 +113,7 @@ public partial class Gambling
|
|||||||
Format.Bold(ctx.User.ToString()),
|
Format.Bold(ctx.User.ToString()),
|
||||||
Format.Bold(target.ToString()),
|
Format.Bold(target.ToString()),
|
||||||
N(amount)));
|
N(amount)));
|
||||||
|
|
||||||
if (w.Affinity?.UserId == ctx.User.Id)
|
if (w.Affinity?.UserId == ctx.User.Id)
|
||||||
msg += "\n" + GetText(strs.waifu_fulfilled(target, N(w.Price)));
|
msg += "\n" + GetText(strs.waifu_fulfilled(target, N(w.Price)));
|
||||||
else
|
else
|
||||||
@@ -144,7 +183,7 @@ public partial class Gambling
|
|||||||
if (targetId == ctx.User.Id)
|
if (targetId == ctx.User.Id)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var (w, result, amount, remaining) = await _service.DivorceWaifuAsync(ctx.User, targetId);
|
var (w, result, amount) = await _service.DivorceWaifuAsync(ctx.User, targetId);
|
||||||
|
|
||||||
if (result == DivorceResult.SucessWithPenalty)
|
if (result == DivorceResult.SucessWithPenalty)
|
||||||
{
|
{
|
||||||
@@ -157,14 +196,6 @@ public partial class Gambling
|
|||||||
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
|
await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync();
|
||||||
else if (result == DivorceResult.NotYourWife)
|
else if (result == DivorceResult.NotYourWife)
|
||||||
await Response().Error(strs.waifu_not_yours).SendAsync();
|
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]
|
[Cmd]
|
||||||
@@ -252,18 +283,18 @@ public partial class Gambling
|
|||||||
var claimer = "no one";
|
var claimer = "no one";
|
||||||
string status;
|
string status;
|
||||||
|
|
||||||
var waifuUsername = w.Username.TrimTo(20);
|
var waifuUsername = w.WaifuName.TrimTo(20);
|
||||||
var claimerUsername = w.Claimer?.TrimTo(20);
|
var claimerUsername = w.ClaimerName?.TrimTo(20);
|
||||||
|
|
||||||
if (w.Claimer is not null)
|
if (w.ClaimerName is not null)
|
||||||
claimer = $"{claimerUsername}#{w.ClaimerDiscrim}";
|
claimer = $"{claimerUsername}";
|
||||||
if (w.Affinity is null)
|
if (w.Affinity is null)
|
||||||
status = $"... but {waifuUsername}'s heart is empty";
|
status = $"... but {waifuUsername}'s heart is empty";
|
||||||
else if (w.Affinity + w.AffinityDiscrim == w.Claimer + w.ClaimerDiscrim)
|
else if (w.Affinity == w.ClaimerName)
|
||||||
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
|
status = $"... and {waifuUsername} likes {claimerUsername} too <3";
|
||||||
else
|
else
|
||||||
status = $"... but {waifuUsername}'s heart belongs to {w.Affinity.TrimTo(20)}#{w.AffinityDiscrim}";
|
status = $"... but {waifuUsername}'s heart belongs to {w.Affinity.TrimTo(20)}";
|
||||||
return $"**{waifuUsername}#{w.Discrim}** - claimed by **{claimer}**\n\t{status}";
|
return $"**{waifuUsername}** - claimed by **{claimer}**\n\t{status}";
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@@ -318,25 +318,20 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
private static TypedKey<long> GetAffinityKey(ulong userId)
|
private static TypedKey<long> GetAffinityKey(ulong userId)
|
||||||
=> new($"waifu:affinity:{userId}");
|
=> new($"waifu:affinity:{userId}");
|
||||||
|
|
||||||
public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId)
|
public async Task<(WaifuInfo, DivorceResult, long)> DivorceWaifuAsync(IUser user, ulong targetId)
|
||||||
{
|
{
|
||||||
DivorceResult result;
|
DivorceResult result;
|
||||||
TimeSpan? remaining = null;
|
|
||||||
long amount = 0;
|
long amount = 0;
|
||||||
WaifuInfo w;
|
WaifuInfo w;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
w = uow.Set<WaifuInfo>().ByWaifuUserId(targetId);
|
w = uow.Set<WaifuInfo>().ByWaifuUserId(targetId);
|
||||||
if (w?.Claimer is null || w.Claimer.UserId != user.Id)
|
if (w?.Claimer is null || w.Claimer.UserId != user.Id)
|
||||||
|
{
|
||||||
result = DivorceResult.NotYourWife;
|
result = DivorceResult.NotYourWife;
|
||||||
|
}
|
||||||
else
|
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;
|
amount = w.Price / 2;
|
||||||
|
|
||||||
@@ -369,7 +364,7 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (w, result, amount, remaining);
|
return (w, result, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> GiftWaifuAsync(
|
public async Task<bool> GiftWaifuAsync(
|
||||||
@@ -603,7 +598,7 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
.Where(wi => wi.ClaimerId == waifuId)
|
.Where(wi => wi.ClaimerId == waifuId)
|
||||||
.Select(wi => wi.WaifuId)
|
.Select(wi => wi.WaifuId)
|
||||||
.Contains(x.Id))
|
.Contains(x.Id))
|
||||||
.Select(x => $"{x.Username}#{x.Discriminator}")
|
.Select(x => x.Username)
|
||||||
.ToListAsyncEF();
|
.ToListAsyncEF();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,7 +610,7 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
.Where(wi => wi.AffinityId == waifuId)
|
.Where(wi => wi.AffinityId == waifuId)
|
||||||
.Select(wi => wi.WaifuId)
|
.Select(wi => wi.WaifuId)
|
||||||
.Contains(x.Id))
|
.Contains(x.Id))
|
||||||
.Select(x => $"{x.Username}#{x.Discriminator}")
|
.Select(x => x.Username)
|
||||||
.ToListAsyncEF();
|
.ToListAsyncEF();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,4 +625,38 @@ public class WaifuService : INService, IReadyExecutor
|
|||||||
.FirstOrDefault())
|
.FirstOrDefault())
|
||||||
.ToListAsyncEF();
|
.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;
|
||||||
}
|
}
|
@@ -40,12 +40,14 @@ public static class WaifuExtensions
|
|||||||
.Take(count)
|
.Take(count)
|
||||||
.Select(x => new WaifuLbResult
|
.Select(x => new WaifuLbResult
|
||||||
{
|
{
|
||||||
Affinity = x.Affinity == null ? null : x.Affinity.Username,
|
Affinity = x.Affinity == null
|
||||||
AffinityDiscrim = x.Affinity == null ? null : x.Affinity.Discriminator,
|
? null
|
||||||
Claimer = x.Claimer == null ? null : x.Claimer.Username,
|
: x.Affinity.Username,
|
||||||
ClaimerDiscrim = x.Claimer == null ? null : x.Claimer.Discriminator,
|
ClaimerName =
|
||||||
Username = x.Waifu.Username,
|
x.Claimer == null
|
||||||
Discrim = x.Waifu.Discriminator,
|
? null
|
||||||
|
: x.Claimer.Username,
|
||||||
|
WaifuName = x.Waifu.Username,
|
||||||
Price = x.Price
|
Price = x.Price
|
||||||
})
|
})
|
||||||
.ToListAsyncEF();
|
.ToListAsyncEF();
|
||||||
@@ -57,7 +59,7 @@ public static class WaifuExtensions
|
|||||||
public static ulong GetWaifuUserId(this DbSet<WaifuInfo> waifus, ulong ownerId, string name)
|
public static ulong GetWaifuUserId(this DbSet<WaifuInfo> waifus, ulong ownerId, string name)
|
||||||
=> waifus.AsQueryable()
|
=> waifus.AsQueryable()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(x => x.Claimer.UserId == ownerId && x.Waifu.Username + "#" + x.Waifu.Discriminator == name)
|
.Where(x => x.Claimer.UserId == ownerId && x.Waifu.Username == name)
|
||||||
.Select(x => x.Waifu.UserId)
|
.Select(x => x.Waifu.UserId)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ public static class WaifuExtensions
|
|||||||
ctx.Set<DiscordUser>()
|
ctx.Set<DiscordUser>()
|
||||||
.AsQueryable()
|
.AsQueryable()
|
||||||
.Where(u => u.UserId == userId)
|
.Where(u => u.UserId == userId)
|
||||||
.Select(u => u.Username + "#" + u.Discriminator)
|
.Select(u => u.Username)
|
||||||
.FirstOrDefault(),
|
.FirstOrDefault(),
|
||||||
AffinityCount =
|
AffinityCount =
|
||||||
ctx.Set<WaifuUpdate>()
|
ctx.Set<WaifuUpdate>()
|
||||||
@@ -107,14 +109,14 @@ public static class WaifuExtensions
|
|||||||
ctx.Set<DiscordUser>()
|
ctx.Set<DiscordUser>()
|
||||||
.AsQueryable()
|
.AsQueryable()
|
||||||
.Where(u => u.Id == w.AffinityId)
|
.Where(u => u.Id == w.AffinityId)
|
||||||
.Select(u => u.Username + "#" + u.Discriminator)
|
.Select(u => u.Username)
|
||||||
.FirstOrDefault(),
|
.FirstOrDefault(),
|
||||||
ClaimCount = ctx.Set<WaifuInfo>().AsQueryable().Count(x => x.ClaimerId == w.WaifuId),
|
ClaimCount = ctx.Set<WaifuInfo>().AsQueryable().Count(x => x.ClaimerId == w.WaifuId),
|
||||||
ClaimerName =
|
ClaimerName =
|
||||||
ctx.Set<DiscordUser>()
|
ctx.Set<DiscordUser>()
|
||||||
.AsQueryable()
|
.AsQueryable()
|
||||||
.Where(u => u.Id == w.ClaimerId)
|
.Where(u => u.Id == w.ClaimerId)
|
||||||
.Select(u => u.Username + "#" + u.Discriminator)
|
.Select(u => u.Username)
|
||||||
.FirstOrDefault(),
|
.FirstOrDefault(),
|
||||||
DivorceCount =
|
DivorceCount =
|
||||||
ctx.Set<WaifuUpdate>()
|
ctx.Set<WaifuUpdate>()
|
||||||
|
@@ -3,14 +3,11 @@ namespace NadekoBot.Db.Models;
|
|||||||
|
|
||||||
public class WaifuLbResult
|
public class WaifuLbResult
|
||||||
{
|
{
|
||||||
public string Username { get; set; }
|
public string WaifuName { get; set; }
|
||||||
public string Discrim { get; set; }
|
|
||||||
|
|
||||||
public string Claimer { get; set; }
|
public string ClaimerName { get; set; }
|
||||||
public string ClaimerDiscrim { get; set; }
|
|
||||||
|
|
||||||
public string Affinity { get; set; }
|
public string Affinity { get; set; }
|
||||||
public string AffinityDiscrim { get; set; }
|
|
||||||
|
|
||||||
public long Price { get; set; }
|
public long Price { get; set; }
|
||||||
}
|
}
|
@@ -13,5 +13,10 @@ public interface IGamblingService
|
|||||||
Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount);
|
Task<OneOf<SlotResult, GamblingError>> SlotAsync(ulong userId, long amount);
|
||||||
Task<FlipResult[]> FlipAsync(int count);
|
Task<FlipResult[]> FlipAsync(int count);
|
||||||
Task<OneOf<RpsResult, GamblingError>> RpsAsync(ulong userId, long amount, byte pick);
|
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,4 +1,6 @@
|
|||||||
#nullable disable
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
using NadekoBot.Modules.Gambling.Betdraw;
|
using NadekoBot.Modules.Gambling.Betdraw;
|
||||||
using NadekoBot.Modules.Gambling.Rps;
|
using NadekoBot.Modules.Gambling.Rps;
|
||||||
using NadekoBot.Modules.Gambling.Services;
|
using NadekoBot.Modules.Gambling.Services;
|
||||||
@@ -8,15 +10,15 @@ namespace NadekoBot.Modules.Gambling;
|
|||||||
|
|
||||||
public sealed class NewGamblingService : IGamblingService, INService
|
public sealed class NewGamblingService : IGamblingService, INService
|
||||||
{
|
{
|
||||||
private readonly GamblingConfigService _bcs;
|
private readonly GamblingConfigService _gcs;
|
||||||
private readonly ICurrencyService _cs;
|
private readonly ICurrencyService _cs;
|
||||||
|
|
||||||
public NewGamblingService(GamblingConfigService bcs, ICurrencyService cs)
|
public NewGamblingService(GamblingConfigService gcs, ICurrencyService cs)
|
||||||
{
|
{
|
||||||
_bcs = bcs;
|
_gcs = gcs;
|
||||||
_cs = cs;
|
_cs = cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<OneOf<LuLaResult, GamblingError>> LulaAsync(ulong userId, long amount)
|
public async Task<OneOf<LuLaResult, GamblingError>> LulaAsync(ulong userId, long amount)
|
||||||
{
|
{
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
||||||
@@ -31,13 +33,13 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var game = new LulaGame(_bcs.Data.LuckyLadder.Multipliers);
|
var game = new LulaGame(_gcs.Data.LuckyLadder.Multipliers);
|
||||||
var result = game.Spin(amount);
|
var result = game.Spin(amount);
|
||||||
|
|
||||||
var won = (long)result.Won;
|
var won = (long)result.Won;
|
||||||
if (won > 0)
|
if (won > 0)
|
||||||
{
|
{
|
||||||
await _cs.AddAsync(userId, won, new("lula", "win"));
|
await _cs.AddAsync(userId, won, new("lula", result.Multiplier >= 1 ? "win" : "lose"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -57,9 +59,9 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var game = new BetrollGame(_bcs.Data.BetRoll.Pairs
|
var game = new BetrollGame(_gcs.Data.BetRoll.Pairs
|
||||||
.Select(x => (x.WhenAbove, (decimal)x.MultiplyBy))
|
.Select(x => (x.WhenAbove, (decimal)x.MultiplyBy))
|
||||||
.ToList());
|
.ToList());
|
||||||
|
|
||||||
var result = game.Roll(amount);
|
var result = game.Roll(amount);
|
||||||
|
|
||||||
@@ -88,19 +90,23 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var game = new BetflipGame(_bcs.Data.BetFlip.Multiplier);
|
var game = new BetflipGame(_gcs.Data.BetFlip.Multiplier);
|
||||||
var result = game.Flip(guess, amount);
|
var result = game.Flip(guess, amount);
|
||||||
|
|
||||||
var won = (long)result.Won;
|
var won = (long)result.Won;
|
||||||
if (won > 0)
|
if (won > 0)
|
||||||
{
|
{
|
||||||
await _cs.AddAsync(userId, won, new("betflip", "win"));
|
await _cs.AddAsync(userId, won, new("betflip", "win"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
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);
|
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
||||||
|
|
||||||
@@ -109,7 +115,7 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
|
|
||||||
if (maybeGuessColor > 1)
|
if (maybeGuessColor > 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(maybeGuessColor));
|
throw new ArgumentOutOfRangeException(nameof(maybeGuessColor));
|
||||||
|
|
||||||
if (maybeGuessValue > 1)
|
if (maybeGuessValue > 1)
|
||||||
throw new ArgumentOutOfRangeException(nameof(maybeGuessValue));
|
throw new ArgumentOutOfRangeException(nameof(maybeGuessValue));
|
||||||
|
|
||||||
@@ -125,13 +131,13 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
|
|
||||||
var game = new BetdrawGame();
|
var game = new BetdrawGame();
|
||||||
var result = game.Draw((BetdrawValueGuess?)maybeGuessValue, (BetdrawColorGuess?)maybeGuessColor, amount);
|
var result = game.Draw((BetdrawValueGuess?)maybeGuessValue, (BetdrawColorGuess?)maybeGuessColor, amount);
|
||||||
|
|
||||||
var won = (long)result.Won;
|
var won = (long)result.Won;
|
||||||
if (won > 0)
|
if (won > 0)
|
||||||
{
|
{
|
||||||
await _cs.AddAsync(userId, won, new("betdraw", "win"));
|
await _cs.AddAsync(userId, won, new("betdraw", "win"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +161,7 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
var won = (long)result.Won;
|
var won = (long)result.Won;
|
||||||
if (won > 0)
|
if (won > 0)
|
||||||
{
|
{
|
||||||
await _cs.AddAsync(userId, won, new("slot", "won"));
|
await _cs.AddAsync(userId, won, new("slot", "win"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -178,7 +184,7 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
|
|
||||||
return Task.FromResult(results);
|
return Task.FromResult(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// private readonly ConcurrentDictionary<ulong, Deck> _decks = new ConcurrentDictionary<ulong, Deck>();
|
// private readonly ConcurrentDictionary<ulong, Deck> _decks = new ConcurrentDictionary<ulong, Deck>();
|
||||||
@@ -236,7 +242,7 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
{
|
{
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
ArgumentOutOfRangeException.ThrowIfNegative(amount);
|
||||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(pick, 2);
|
ArgumentOutOfRangeException.ThrowIfGreaterThan(pick, 2);
|
||||||
|
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
{
|
{
|
||||||
var isTakeSuccess = await _cs.RemoveAsync(userId, amount, new("rps", "bet"));
|
var isTakeSuccess = await _cs.RemoveAsync(userId, amount, new("rps", "bet"));
|
||||||
@@ -249,7 +255,7 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
|
|
||||||
var rps = new RpsGame();
|
var rps = new RpsGame();
|
||||||
var result = rps.Play((RpsPick)pick, amount);
|
var result = rps.Play((RpsPick)pick, amount);
|
||||||
|
|
||||||
var won = (long)result.Won;
|
var won = (long)result.Won;
|
||||||
if (won > 0)
|
if (won > 0)
|
||||||
{
|
{
|
||||||
@@ -265,4 +271,46 @@ public sealed class NewGamblingService : IGamblingService, INService
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RakebackService: INService
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
24
src/NadekoBot/Modules/Games/NCanvas/INCanvasService.cs
Normal file
24
src/NadekoBot/Modules/Games/NCanvas/INCanvasService.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using NadekoBot.Db.Models;
|
||||||
|
|
||||||
|
namespace NadekoBot.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();
|
||||||
|
}
|
305
src/NadekoBot/Modules/Games/NCanvas/NCanvasCommands.cs
Normal file
305
src/NadekoBot/Modules/Games/NCanvas/NCanvasCommands.cs
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
using NadekoBot.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 NadekoBot.Modules.Games;
|
||||||
|
|
||||||
|
public partial class Games
|
||||||
|
{
|
||||||
|
public sealed class NCanvasCommands : NadekoModule
|
||||||
|
{
|
||||||
|
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_NADEKO
|
||||||
|
.WithDescription("https://dashy.nadeko.bot/ncanvas")
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
206
src/NadekoBot/Modules/Games/NCanvas/NCanvasService.cs
Normal file
206
src/NadekoBot/Modules/Games/NCanvas/NCanvasService.cs
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.Data;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
|
using NadekoBot.Db.Models;
|
||||||
|
using SixLabors.ImageSharp.ColorSpaces;
|
||||||
|
using SixLabors.ImageSharp.ColorSpaces.Conversion;
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Games;
|
||||||
|
|
||||||
|
public sealed class NCanvasService : INCanvasService, IReadyExecutor, INService
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
9
src/NadekoBot/Modules/Games/NCanvas/SetPixelResult.cs
Normal file
9
src/NadekoBot/Modules/Games/NCanvas/SetPixelResult.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace NadekoBot.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()))
|
if (!await nunchi.Join(ctx.User.Id, ctx.User.ToString()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await Response().Error(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync();
|
await Response().Confirm(strs.nunchi_joined(nunchi.ParticipantCount)).SendAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -122,9 +122,9 @@ public sealed class CurrencyRewardService : INService, IReadyExecutor
|
|||||||
var dollarValue = pledgeCents / 100;
|
var dollarValue = pledgeCents / 100;
|
||||||
percentBonus = dollarValue switch
|
percentBonus = dollarValue switch
|
||||||
{
|
{
|
||||||
>= 100 => 100,
|
>= 100 => 25,
|
||||||
>= 50 => 50,
|
>= 50 => 20,
|
||||||
>= 20 => 20,
|
>= 20 => 15,
|
||||||
>= 10 => 10,
|
>= 10 => 10,
|
||||||
>= 5 => 5,
|
>= 5 => 5,
|
||||||
_ => 0
|
_ => 0
|
||||||
|
@@ -404,9 +404,9 @@ public sealed class PatronageService
|
|||||||
{
|
{
|
||||||
>= 10_000 => 100,
|
>= 10_000 => 100,
|
||||||
>= 5000 => 50,
|
>= 5000 => 50,
|
||||||
>= 2000 => 20,
|
>= 2000 => 30,
|
||||||
>= 1000 => 10,
|
>= 1000 => 20,
|
||||||
>= 500 => 5,
|
>= 500 => 10,
|
||||||
_ => 0
|
_ => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -18,39 +18,39 @@ public partial class Permissions
|
|||||||
{
|
{
|
||||||
ArgumentOutOfRangeException.ThrowIfNegative(page);
|
ArgumentOutOfRangeException.ThrowIfNegative(page);
|
||||||
|
|
||||||
var list = _service.GetBlacklist();
|
var list = await _service.GetBlacklist(type);
|
||||||
var allItems = await list.Where(x => x.Type == type)
|
var allItems = await list
|
||||||
.Select(i =>
|
.Select(i =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return Task.FromResult(i.Type switch
|
return Task.FromResult(type switch
|
||||||
{
|
{
|
||||||
BlacklistType.Channel => Format.Code(i.ItemId.ToString())
|
BlacklistType.Channel => Format.Code(i.ItemId.ToString())
|
||||||
+ " "
|
|
||||||
+ (_client.GetChannel(i.ItemId)?.ToString()
|
|
||||||
?? ""),
|
|
||||||
BlacklistType.User => Format.Code(i.ItemId.ToString())
|
|
||||||
+ " "
|
|
||||||
+ ((_client.GetUser(i.ItemId))
|
|
||||||
?.ToString()
|
|
||||||
?? ""),
|
|
||||||
BlacklistType.Server => Format.Code(i.ItemId.ToString())
|
|
||||||
+ " "
|
+ " "
|
||||||
+ (_client.GetGuild(i.ItemId)?.ToString() ?? ""),
|
+ (_client.GetChannel(i.ItemId)?.ToString()
|
||||||
_ => Format.Code(i.ItemId.ToString())
|
?? ""),
|
||||||
});
|
BlacklistType.User => Format.Code(i.ItemId.ToString())
|
||||||
}
|
+ " "
|
||||||
catch
|
+ ((_client.GetUser(i.ItemId))
|
||||||
{
|
?.ToString()
|
||||||
Log.Warning("Can't get {BlacklistType} [{BlacklistItemId}]",
|
?? ""),
|
||||||
i.Type,
|
BlacklistType.Server => Format.Code(i.ItemId.ToString())
|
||||||
i.ItemId);
|
+ " "
|
||||||
|
+ (_client.GetGuild(i.ItemId)?.ToString() ?? ""),
|
||||||
return Task.FromResult(Format.Code(i.ItemId.ToString()));
|
_ => Format.Code(i.ItemId.ToString())
|
||||||
}
|
});
|
||||||
})
|
}
|
||||||
.WhenAll();
|
catch
|
||||||
|
{
|
||||||
|
Log.Warning("Can't get {BlacklistType} [{BlacklistItemId}]",
|
||||||
|
i.Type,
|
||||||
|
i.ItemId);
|
||||||
|
|
||||||
|
return Task.FromResult(Format.Code(i.ItemId.ToString()));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.WhenAll();
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
@@ -61,14 +61,14 @@ public partial class Permissions
|
|||||||
{
|
{
|
||||||
if (pageItems.Count == 0)
|
if (pageItems.Count == 0)
|
||||||
return _sender.CreateEmbed()
|
return _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(title)
|
.WithTitle(title)
|
||||||
.WithDescription(GetText(strs.empty_page));
|
.WithDescription(GetText(strs.empty_page));
|
||||||
|
|
||||||
return _sender.CreateEmbed()
|
return _sender.CreateEmbed()
|
||||||
.WithTitle(title)
|
.WithTitle(title)
|
||||||
.WithDescription(allItems.Join('\n'))
|
.WithDescription(pageItems.Join('\n'))
|
||||||
.WithOkColor();
|
.WithOkColor();
|
||||||
})
|
})
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,9 @@ public sealed class YoutubeDataApiSearchService : IYoutubeSearchService, INServi
|
|||||||
if(results.Count == 0)
|
if(results.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return results.Map(r => new VideoInfo(r));
|
return results.Map(r => new VideoInfo()
|
||||||
|
{
|
||||||
|
Url = r
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
191
src/NadekoBot/Modules/Searches/Translate/FlagTranslateService.cs
Normal file
191
src/NadekoBot/Modules/Searches/Translate/FlagTranslateService.cs
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
#nullable disable
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
|
using NadekoBot.Db.Models;
|
||||||
|
using System.Collections.Frozen;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Searches;
|
||||||
|
|
||||||
|
public sealed partial class FlagTranslateService : IReadyExecutor, INService
|
||||||
|
{
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,81 @@
|
|||||||
|
namespace NadekoBot.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,12 +44,10 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
|
|||||||
foreach (var c in cs)
|
foreach (var c in cs)
|
||||||
{
|
{
|
||||||
_atcs[c.ChannelId] = c.AutoDelete;
|
_atcs[c.ChannelId] = c.AutoDelete;
|
||||||
_users[c.ChannelId] =
|
_users[c.ChannelId] = new(c.Users.ToDictionary(x => x.UserId, x => (x.Source.ToLower(), x.Target.ToLower())));
|
||||||
new(c.Users.ToDictionary(x => x.UserId, x => (x.Source.ToLower(), x.Target.ToLower())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
|
public async Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(msg.Content))
|
if (string.IsNullOrWhiteSpace(msg.Content))
|
||||||
@@ -95,7 +93,7 @@ public sealed class TranslateService : ITranslateService, IExecNoCommand, IReady
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> Translate(string source, string target, string text = null)
|
public async Task<string> Translate(string source, string target, string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(text))
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
throw new ArgumentException("Text is empty or null", nameof(text));
|
throw new ArgumentException("Text is empty or null", nameof(text));
|
||||||
|
@@ -6,6 +6,14 @@ public partial class Searches
|
|||||||
[Group]
|
[Group]
|
||||||
public partial class TranslateCommands : NadekoModule<ITranslateService>
|
public partial class TranslateCommands : NadekoModule<ITranslateService>
|
||||||
{
|
{
|
||||||
|
private readonly FlagTranslateService _flagSvc;
|
||||||
|
|
||||||
|
public TranslateCommands(FlagTranslateService flagSvc)
|
||||||
|
{
|
||||||
|
_flagSvc = flagSvc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum AutoDeleteAutoTranslate
|
public enum AutoDeleteAutoTranslate
|
||||||
{
|
{
|
||||||
Del,
|
Del,
|
||||||
@@ -91,5 +99,18 @@ public partial class Searches
|
|||||||
|
|
||||||
await Response().Embed(eb).SendAsync();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -100,10 +100,6 @@ public sealed class AiAssistantService
|
|||||||
|
|
||||||
using var client = _httpFactory.CreateClient();
|
using var client = _httpFactory.CreateClient();
|
||||||
|
|
||||||
// todo customize according to the bot's config
|
|
||||||
// - CurrencyName
|
|
||||||
// -
|
|
||||||
|
|
||||||
using var response = await client.SendAsync(request);
|
using var response = await client.SendAsync(request);
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.TooManyRequests)
|
if (response.StatusCode == HttpStatusCode.TooManyRequests)
|
||||||
|
@@ -26,6 +26,8 @@ public interface IQuoteService
|
|||||||
ulong guildId,
|
ulong guildId,
|
||||||
string? keyword,
|
string? keyword,
|
||||||
string text);
|
string text);
|
||||||
|
|
||||||
|
Task<(IReadOnlyCollection<Quote> quotes, int totalCount)> FindQuotesAsync(ulong guildId, string query, int page);
|
||||||
|
|
||||||
Task<IReadOnlyCollection<Quote>> GetGuildQuotesAsync(ulong guildId);
|
Task<IReadOnlyCollection<Quote>> GetGuildQuotesAsync(ulong guildId);
|
||||||
Task<int> RemoveAllByKeyword(ulong guildId, string keyword);
|
Task<int> RemoveAllByKeyword(ulong guildId, string keyword);
|
||||||
@@ -39,6 +41,7 @@ public interface IQuoteService
|
|||||||
string text);
|
string text);
|
||||||
|
|
||||||
Task<Quote?> EditQuoteAsync(ulong authorId, int quoteId, string text);
|
Task<Quote?> EditQuoteAsync(ulong authorId, int quoteId, string text);
|
||||||
|
Task<Quote?> EditQuoteAsync(ulong guildId, int quoteId, string keyword, string text);
|
||||||
|
|
||||||
Task<bool> DeleteQuoteAsync(
|
Task<bool> DeleteQuoteAsync(
|
||||||
ulong guildId,
|
ulong guildId,
|
||||||
|
@@ -169,6 +169,23 @@ public sealed class QuoteService : IQuoteService, INService
|
|||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Quote?> EditQuoteAsync(
|
||||||
|
ulong guildId,
|
||||||
|
int quoteId,
|
||||||
|
string keyword,
|
||||||
|
string text)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
var result = await uow.GetTable<Quote>()
|
||||||
|
.Where(x => x.Id == quoteId && x.GuildId == guildId)
|
||||||
|
.Set(x => x.Keyword, keyword)
|
||||||
|
.Set(x => x.Text, text)
|
||||||
|
.UpdateWithOutputAsync((del, ins) => ins);
|
||||||
|
|
||||||
|
var q = result.FirstOrDefault();
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteQuoteAsync(
|
public async Task<bool> DeleteQuoteAsync(
|
||||||
ulong guildId,
|
ulong guildId,
|
||||||
ulong authorId,
|
ulong authorId,
|
||||||
@@ -219,4 +236,24 @@ public sealed class QuoteService : IQuoteService, INService
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<(IReadOnlyCollection<Quote> quotes, int totalCount)> FindQuotesAsync(
|
||||||
|
ulong guildId,
|
||||||
|
string query,
|
||||||
|
int page)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
|
var baseQuery = uow.GetTable<Quote>()
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.Where(x => x.Keyword.Contains(query) || x.Text.Contains(query));
|
||||||
|
|
||||||
|
var quotes = await baseQuery
|
||||||
|
.OrderBy(x => x.Id)
|
||||||
|
.Skip((page - 1) * 10)
|
||||||
|
.Take(10)
|
||||||
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
|
return (quotes, await baseQuery.CountAsyncLinqToDB());
|
||||||
|
}
|
||||||
}
|
}
|
@@ -197,26 +197,29 @@ public class RemindService : INService, IReadyExecutor, IRemindService
|
|||||||
|
|
||||||
var st = SmartText.CreateFrom(r.Message);
|
var st = SmartText.CreateFrom(r.Message);
|
||||||
|
|
||||||
|
var res = _sender.Response(ch)
|
||||||
|
.UserBasedMentions(_client.GetGuild(r.ServerId)?.GetUser(r.UserId));
|
||||||
|
|
||||||
if (st is SmartEmbedText set)
|
if (st is SmartEmbedText set)
|
||||||
{
|
{
|
||||||
await _sender.Response(ch).Embed(set.GetEmbed()).SendAsync();
|
await res.Embed(set.GetEmbed()).SendAsync();
|
||||||
}
|
}
|
||||||
else if (st is SmartEmbedTextArray seta)
|
else if (st is SmartEmbedTextArray seta)
|
||||||
{
|
{
|
||||||
await _sender.Response(ch).Embeds(seta.GetEmbedBuilders()).SendAsync();
|
await res.Embeds(seta.GetEmbedBuilders()).SendAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _sender.Response(ch)
|
await res
|
||||||
.Embed(_sender.CreateEmbed()
|
.Embed(_sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle("Reminder")
|
.WithTitle("Reminder")
|
||||||
.AddField("Created At",
|
.AddField("Created At",
|
||||||
r.DateAdded.HasValue ? r.DateAdded.Value.ToLongDateString() : "?")
|
r.DateAdded.HasValue ? r.DateAdded.Value.ToLongDateString() : "?")
|
||||||
.AddField("By",
|
.AddField("By",
|
||||||
(await ch.GetUserAsync(r.UserId))?.ToString() ?? r.UserId.ToString()))
|
(await ch.GetUserAsync(r.UserId))?.ToString() ?? r.UserId.ToString()))
|
||||||
.Text(r.Message)
|
.Text(r.Message)
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@@ -783,4 +783,28 @@ public partial class Utility : NadekoModule
|
|||||||
await Response().Error(ex.Message).SendAsync();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
@@ -107,7 +107,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
[Cmd]
|
[Cmd]
|
||||||
[UserPerm(GuildPerm.ManageChannels)]
|
[UserPerm(GuildPerm.ManageChannels)]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task XpExclude(Channel _, [Leftover] IChannel channel = null)
|
public async Task XpExclude(Channel _, [Leftover] IChannel? channel = null)
|
||||||
{
|
{
|
||||||
if (channel is null)
|
if (channel is null)
|
||||||
channel = ctx.Channel;
|
channel = ctx.Channel;
|
||||||
@@ -182,29 +182,28 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
||||||
|
|
||||||
await ctx.Channel.TriggerTypingAsync();
|
await ctx.Channel.TriggerTypingAsync();
|
||||||
|
|
||||||
var socketGuild = (SocketGuild)ctx.Guild;
|
|
||||||
var allCleanUsers = new List<UserXpStats>();
|
|
||||||
if (opts.Clean)
|
if (opts.Clean)
|
||||||
{
|
{
|
||||||
await ctx.Channel.TriggerTypingAsync();
|
|
||||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||||
|
|
||||||
allCleanUsers = (await _service.GetTopUserXps(ctx.Guild.Id, 1000))
|
|
||||||
.Where(user => socketGuild.GetUser(user.UserId) is not null)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var res = opts.Clean
|
async Task<IReadOnlyCollection<UserXpStats>> GetPageItems(int curPage)
|
||||||
? Response()
|
{
|
||||||
.Paginated()
|
var socketGuild = (SocketGuild)ctx.Guild;
|
||||||
.Items(allCleanUsers)
|
if (opts.Clean)
|
||||||
: Response()
|
{
|
||||||
.Paginated()
|
return await _service.GetGuildUserXps(ctx.Guild.Id,
|
||||||
.PageItems((curPage) => _service.GetUserXps(ctx.Guild.Id, curPage));
|
socketGuild.Users.Select(x => x.Id).ToList(),
|
||||||
|
curPage);
|
||||||
|
}
|
||||||
|
|
||||||
await res
|
return await _service.GetGuildUserXps(ctx.Guild.Id, curPage);
|
||||||
.PageSize(9)
|
}
|
||||||
|
|
||||||
|
await Response()
|
||||||
|
.Paginated()
|
||||||
|
.PageItems(GetPageItems)
|
||||||
|
.PageSize(10)
|
||||||
.CurrentPage(page)
|
.CurrentPage(page)
|
||||||
.Page((users, curPage) =>
|
.Page((users, curPage) =>
|
||||||
{
|
{
|
||||||
@@ -226,7 +225,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
else if (userXpData.AwardedXp < 0)
|
else if (userXpData.AwardedXp < 0)
|
||||||
awardStr = $"({userXpData.AwardedXp})";
|
awardStr = $"({userXpData.AwardedXp})";
|
||||||
|
|
||||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
embed.AddField($"#{i + 1 + (curPage * 10)} {user?.ToString() ?? users[i].UserId.ToString()}",
|
||||||
$"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}");
|
$"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,15 +236,33 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task XpGlobalLeaderboard(int page = 1)
|
public async Task XpGlobalLeaderboard(int page = 1, params string[] args)
|
||||||
{
|
{
|
||||||
if (--page < 0 || page > 99)
|
if (--page < 0 || page > 99)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
||||||
|
|
||||||
|
await ctx.Channel.TriggerTypingAsync();
|
||||||
|
if (opts.Clean)
|
||||||
|
{
|
||||||
|
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||||
|
}
|
||||||
|
|
||||||
|
async Task<IReadOnlyCollection<DiscordUser>> GetPageItems(int curPage)
|
||||||
|
{
|
||||||
|
if (opts.Clean)
|
||||||
|
{
|
||||||
|
return await _service.GetGlobalUserXps(page, ((SocketGuild)ctx.Guild).Users.Select(x => x.Id).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return await _service.GetGlobalUserXps(curPage);
|
||||||
|
}
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
.PageItems(async curPage => await _service.GetUserXps(curPage))
|
.PageItems(GetPageItems)
|
||||||
.PageSize(9)
|
.PageSize(10)
|
||||||
.Page((users, curPage) =>
|
.Page((users, curPage) =>
|
||||||
{
|
{
|
||||||
var embed = _sender.CreateEmbed()
|
var embed = _sender.CreateEmbed()
|
||||||
@@ -261,7 +278,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
for (var i = 0; i < users.Count; i++)
|
for (var i = 0; i < users.Count; i++)
|
||||||
{
|
{
|
||||||
var user = users[i];
|
var user = users[i];
|
||||||
embed.AddField($"#{i + 1 + (curPage * 9)} {user}",
|
embed.AddField($"#{i + 1 + (curPage * 10)} {user}",
|
||||||
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
$"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +299,9 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
if (role.IsManaged)
|
if (role.IsManaged)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var count = await _service.AddXpToUsersAsync(ctx.Guild.Id, amount, role.Members.Select(x => x.Id).ToArray());
|
var count = await _service.AddXpToUsersAsync(ctx.Guild.Id,
|
||||||
|
amount,
|
||||||
|
role.Members.Select(x => x.Id).ToArray());
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(
|
.Confirm(
|
||||||
strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString())))
|
strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString())))
|
||||||
@@ -338,7 +357,7 @@ public partial class Xp : NadekoModule<XpService>
|
|||||||
if (!await PromptUserConfirmAsync(embed))
|
if (!await PromptUserConfirmAsync(embed))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_service.XpReset(ctx.Guild.Id, userId);
|
await _service.XpReset(ctx.Guild.Id, userId);
|
||||||
|
|
||||||
await Response().Confirm(strs.reset_user(userId)).SendAsync();
|
await Response().Confirm(strs.reset_user(userId)).SendAsync();
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ using SixLabors.ImageSharp.PixelFormats;
|
|||||||
using SixLabors.ImageSharp.Processing;
|
using SixLabors.ImageSharp.Processing;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using LinqToDB.EntityFrameworkCore;
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using LinqToDB.Tools;
|
||||||
using NadekoBot.Modules.Patronage;
|
using NadekoBot.Modules.Patronage;
|
||||||
using Color = SixLabors.ImageSharp.Color;
|
using Color = SixLabors.ImageSharp.Color;
|
||||||
using Exception = System.Exception;
|
using Exception = System.Exception;
|
||||||
@@ -19,6 +20,31 @@ using Image = SixLabors.ImageSharp.Image;
|
|||||||
|
|
||||||
namespace NadekoBot.Modules.Xp.Services;
|
namespace NadekoBot.Modules.Xp.Services;
|
||||||
|
|
||||||
|
public interface IUserService
|
||||||
|
{
|
||||||
|
Task<DiscordUser?> GetUserAsync(ulong userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class UserService : IUserService, INService
|
||||||
|
{
|
||||||
|
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 : INService, IReadyExecutor, IExecNoCommand
|
public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||||
{
|
{
|
||||||
private readonly DbService _db;
|
private readonly DbService _db;
|
||||||
@@ -563,23 +589,50 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
|||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page)
|
public async Task<IReadOnlyCollection<UserXpStats>> GetGuildUserXps(ulong guildId, int page)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
return await uow.Set<UserXpStats>().GetUsersFor(guildId, page);
|
return await uow
|
||||||
|
.UserXpStats
|
||||||
|
.Where(x => x.GuildId == guildId)
|
||||||
|
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
||||||
|
.Skip(page * 10)
|
||||||
|
.Take(10)
|
||||||
|
.ToArrayAsyncLinqToDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IReadOnlyCollection<UserXpStats>> GetTopUserXps(ulong guildId, int count)
|
public async Task<IReadOnlyCollection<UserXpStats>> GetGuildUserXps(ulong guildId, List<ulong> users, int page)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
return await uow.Set<UserXpStats>().GetTopUserXps(guildId, count);
|
return await uow.Set<UserXpStats>()
|
||||||
|
.Where(x => x.GuildId == guildId && x.UserId.In(users))
|
||||||
|
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
||||||
|
.Skip(page * 10)
|
||||||
|
.Take(10)
|
||||||
|
.ToArrayAsyncLinqToDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IReadOnlyCollection<DiscordUser>> GetUserXps(int page, int perPage = 9)
|
public async Task<IReadOnlyCollection<DiscordUser>> GetGlobalUserXps(int page)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
return uow.Set<DiscordUser>()
|
|
||||||
.GetUsersXpLeaderboardFor(page, perPage);
|
return await uow.GetTable<DiscordUser>()
|
||||||
|
.OrderByDescending(x => x.TotalXp)
|
||||||
|
.Skip(page * 10)
|
||||||
|
.Take(10)
|
||||||
|
.ToArrayAsyncLinqToDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IReadOnlyCollection<DiscordUser>> GetGlobalUserXps(int page, List<ulong> users)
|
||||||
|
{
|
||||||
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
|
return await uow.GetTable<DiscordUser>()
|
||||||
|
.Where(x => x.UserId.In(users))
|
||||||
|
.OrderByDescending(x => x.TotalXp)
|
||||||
|
.Skip(page * 10)
|
||||||
|
.Take(10)
|
||||||
|
.ToArrayAsyncLinqToDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type)
|
public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type)
|
||||||
@@ -1409,11 +1462,11 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void XpReset(ulong guildId, ulong userId)
|
public async Task XpReset(ulong guildId, ulong userId)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
uow.Set<UserXpStats>().ResetGuildUserXp(userId, guildId);
|
await uow.GetTable<UserXpStats>()
|
||||||
uow.SaveChanges();
|
.DeleteAsync(x => x.UserId == userId && x.GuildId == guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void XpReset(ulong guildId)
|
public void XpReset(ulong guildId)
|
||||||
@@ -1609,6 +1662,15 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
|||||||
|
|
||||||
public bool IsShopEnabled()
|
public bool IsShopEnabled()
|
||||||
=> _xpConfig.Data.Shop.IsEnabled;
|
=> _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
|
public enum BuyResult
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>true</ImplicitUsings>
|
<ImplicitUsings>true</ImplicitUsings>
|
||||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||||
<Version>5.1.12</Version>
|
<Version>5.1.20</Version>
|
||||||
|
|
||||||
<!-- Output/build -->
|
<!-- Output/build -->
|
||||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||||
|
@@ -2,21 +2,31 @@
|
|||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using NadekoBot.Db.Models;
|
using NadekoBot.Db.Models;
|
||||||
using NadekoBot.Modules.NadekoExpressions;
|
using NadekoBot.Modules.NadekoExpressions;
|
||||||
|
using NadekoBot.Modules.Utility;
|
||||||
|
|
||||||
namespace NadekoBot.GrpcApi;
|
namespace NadekoBot.GrpcApi;
|
||||||
|
|
||||||
public class ExprsSvc : GrpcExprs.GrpcExprsBase, INService
|
public class ExprsSvc : GrpcExprs.GrpcExprsBase, IGrpcSvc, INService
|
||||||
{
|
{
|
||||||
private readonly NadekoExpressionsService _svc;
|
private readonly NadekoExpressionsService _svc;
|
||||||
|
private readonly IQuoteService _qs;
|
||||||
|
private readonly DiscordSocketClient _client;
|
||||||
|
|
||||||
public ExprsSvc(NadekoExpressionsService svc)
|
public ExprsSvc(NadekoExpressionsService svc, IQuoteService qs, DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
_svc = svc;
|
_svc = svc;
|
||||||
|
_qs = qs;
|
||||||
|
_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GrpcApiPerm(GuildPerm.Administrator)]
|
public ServerServiceDefinition Bind()
|
||||||
|
=> GrpcExprs.BindService(this);
|
||||||
|
|
||||||
public override async Task<AddExprReply> AddExpr(AddExprRequest request, ServerCallContext context)
|
public override async Task<AddExprReply> AddExpr(AddExprRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Expr.Trigger) || string.IsNullOrWhiteSpace(request.Expr.Response))
|
||||||
|
throw new RpcException(new Status(StatusCode.InvalidArgument, "Trigger and response are required"));
|
||||||
|
|
||||||
NadekoExpression expr;
|
NadekoExpression expr;
|
||||||
if (!string.IsNullOrWhiteSpace(request.Expr.Id))
|
if (!string.IsNullOrWhiteSpace(request.Expr.Id))
|
||||||
{
|
{
|
||||||
@@ -45,7 +55,6 @@ public class ExprsSvc : GrpcExprs.GrpcExprsBase, INService
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[GrpcApiPerm(GuildPerm.Administrator)]
|
|
||||||
public override async Task<GetExprsReply> GetExprs(GetExprsRequest request, ServerCallContext context)
|
public override async Task<GetExprsReply> GetExprs(GetExprsRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
var (exprs, totalCount) = await _svc.FindExpressionsAsync(request.GuildId, request.Query, request.Page);
|
var (exprs, totalCount) = await _svc.FindExpressionsAsync(request.GuildId, request.Query, request.Page);
|
||||||
@@ -66,11 +75,75 @@ public class ExprsSvc : GrpcExprs.GrpcExprsBase, INService
|
|||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
[GrpcApiPerm(GuildPerm.Administrator)]
|
|
||||||
public override async Task<Empty> DeleteExpr(DeleteExprRequest request, ServerCallContext context)
|
public override async Task<Empty> DeleteExpr(DeleteExprRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
await _svc.DeleteAsync(request.GuildId, new kwum(request.Id));
|
if (kwum.TryParse(request.Id, out var id))
|
||||||
|
await _svc.DeleteAsync(request.GuildId, id);
|
||||||
|
|
||||||
return new Empty();
|
return new Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<GetQuotesReply> GetQuotes(GetQuotesRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
if (request.Page < 0)
|
||||||
|
throw new RpcException(new Status(StatusCode.InvalidArgument, "Page must be >= 0"));
|
||||||
|
|
||||||
|
var (quotes, totalCount) = await _qs.FindQuotesAsync(request.GuildId, request.Query, request.Page);
|
||||||
|
|
||||||
|
var reply = new GetQuotesReply();
|
||||||
|
reply.TotalCount = totalCount;
|
||||||
|
reply.Quotes.AddRange(quotes.Select(x => new QuoteDto()
|
||||||
|
{
|
||||||
|
Id = new kwum(x.Id).ToString(),
|
||||||
|
Trigger = x.Keyword,
|
||||||
|
Response = x.Text,
|
||||||
|
AuthorId = x.AuthorId,
|
||||||
|
AuthorName = x.AuthorName
|
||||||
|
}));
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<AddQuoteReply> AddQuote(AddQuoteRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
var userId = context.RequestHeaders.GetUserId();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Quote.Trigger) || string.IsNullOrWhiteSpace(request.Quote.Response))
|
||||||
|
throw new RpcException(new Status(StatusCode.InvalidArgument, "Trigger and response are required"));
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(request.Quote.Id))
|
||||||
|
{
|
||||||
|
var q = await _qs.AddQuoteAsync(request.GuildId,
|
||||||
|
userId,
|
||||||
|
(await _client.GetUserAsync(userId))?.Username ?? userId.ToString(),
|
||||||
|
request.Quote.Trigger,
|
||||||
|
request.Quote.Response);
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = new kwum(q.Id).ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!kwum.TryParse(request.Quote.Id, out var qid))
|
||||||
|
throw new RpcException(new Status(StatusCode.InvalidArgument, "Invalid quote id"));
|
||||||
|
|
||||||
|
await _qs.EditQuoteAsync(
|
||||||
|
request.GuildId,
|
||||||
|
new kwum(request.Quote.Id),
|
||||||
|
request.Quote.Trigger,
|
||||||
|
request.Quote.Response);
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = new kwum(qid).ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task<Empty> DeleteQuote(DeleteQuoteRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
await _qs.DeleteQuoteAsync(request.GuildId, context.RequestHeaders.GetUserId(), true, new kwum(request.Id));
|
||||||
|
return new Empty();
|
||||||
|
}
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user