-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add total playtime to
!playtime
, and added !playstats
- Loading branch information
Showing
11 changed files
with
349 additions
and
12 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
BanchoMultiplayerBot.Database/BanchoMultiplayerBot.Database.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.5" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BanchoMultiplayerBot.Database.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BanchoMultiplayerBot.Database | ||
{ | ||
public class BotDbContext : DbContext | ||
{ | ||
public DbSet<User> Users { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite($"Data Source=bot.db"); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
BanchoMultiplayerBot.Database/Migrations/20230503154038_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
BanchoMultiplayerBot.Database/Migrations/20230503154038_InitialCreate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace BanchoMultiplayerBot.Database.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class InitialCreate : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Users", | ||
columns: table => new | ||
{ | ||
Id = table.Column<Guid>(type: "TEXT", nullable: false), | ||
UserId = table.Column<int>(type: "INTEGER", nullable: true), | ||
Name = table.Column<string>(type: "TEXT", nullable: false), | ||
Playtime = table.Column<int>(type: "INTEGER", nullable: false), | ||
MatchesPlayed = table.Column<int>(type: "INTEGER", nullable: false), | ||
NumberOneResults = table.Column<int>(type: "INTEGER", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Users", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Users"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
BanchoMultiplayerBot.Database/Migrations/BotDbContextModelSnapshot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// <auto-generated /> | ||
using System; | ||
using BanchoMultiplayerBot.Database; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
#nullable disable | ||
|
||
namespace BanchoMultiplayerBot.Database.Migrations | ||
{ | ||
[DbContext(typeof(BotDbContext))] | ||
partial class BotDbContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder.HasAnnotation("ProductVersion", "7.0.5"); | ||
|
||
modelBuilder.Entity("BanchoMultiplayerBot.Database.Models.User", b => | ||
{ | ||
b.Property<Guid>("Id") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("TEXT"); | ||
|
||
b.Property<int>("MatchesPlayed") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<string>("Name") | ||
.IsRequired() | ||
.HasColumnType("TEXT"); | ||
|
||
b.Property<int>("NumberOneResults") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<int>("Playtime") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.Property<int?>("UserId") | ||
.HasColumnType("INTEGER"); | ||
|
||
b.HasKey("Id"); | ||
|
||
b.ToTable("Users"); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BanchoMultiplayerBot.Database.Models | ||
{ | ||
public class User | ||
{ | ||
|
||
public Guid Id { get; set; } | ||
|
||
/// <summary> | ||
/// osu! user id | ||
/// </summary> | ||
public int? UserId { get; set; } | ||
|
||
/// <summary> | ||
/// osu! username | ||
/// </summary> | ||
public string Name { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Total playtime in seconds | ||
/// </summary> | ||
public int Playtime { get; set; } | ||
|
||
public int MatchesPlayed { get; set; } | ||
|
||
/// <summary> | ||
/// Number of times the user has gotten #1 in a match | ||
/// </summary> | ||
public int NumberOneResults { get; set; } | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
BanchoMultiplayerBot.Database/Repositories/UserRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BanchoMultiplayerBot.Database.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BanchoMultiplayerBot.Database.Repositories | ||
{ | ||
public class UserRepository : IDisposable | ||
{ | ||
private readonly BotDbContext _botDbContext; | ||
private bool _disposed; | ||
|
||
public UserRepository() | ||
{ | ||
_botDbContext = new BotDbContext(); | ||
} | ||
|
||
public async Task<User?> FindUser(string username) | ||
{ | ||
return await _botDbContext.Users.Where(x => x.Name == username).FirstOrDefaultAsync(); | ||
} | ||
|
||
public async Task<User> CreateUser(string username) | ||
{ | ||
var user = new User() | ||
{ | ||
Id = Guid.NewGuid(), | ||
Name = username | ||
}; | ||
|
||
await _botDbContext.AddAsync(user); | ||
await _botDbContext.SaveChangesAsync(); | ||
|
||
return user; | ||
} | ||
|
||
public async Task Save() | ||
{ | ||
await _botDbContext.SaveChangesAsync(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!_disposed) | ||
{ | ||
if (disposing) | ||
{ | ||
_botDbContext.Dispose(); | ||
} | ||
} | ||
|
||
_disposed = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.