Skip to content

Commit

Permalink
update all packages, add invite counting.
Browse files Browse the repository at this point in the history
  • Loading branch information
SylveonDeko committed Oct 13, 2024
1 parent cd28f79 commit a9ba7b7
Show file tree
Hide file tree
Showing 30 changed files with 10,556 additions and 201 deletions.
17 changes: 17 additions & 0 deletions src/Mewdeko/Common/Yml/CommentGatheringTypeInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public CommentGatheringTypeInspector(ITypeInspector innerTypeDescriptor)
innerTypeDescriptor ?? throw new ArgumentNullException(nameof(innerTypeDescriptor));
}

/// <inheritdoc />
public override string GetEnumName(Type enumType, string name)
{
return name;
}

/// <inheritdoc />
public override string GetEnumValue(object enumValue)
{
return enumValue.ToString();
}

/// <inheritdoc />
public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object? container)
{
Expand All @@ -43,6 +55,8 @@ public CommentsPropertyDescriptor(IPropertyDescriptor baseDescriptor)
/// <inheritdoc />
public string Name { get; }

public bool AllowNulls { get; }

/// <inheritdoc />
public Type Type
{
Expand Down Expand Up @@ -81,6 +95,9 @@ public ScalarStyle ScalarStyle
}
}

public bool Required { get; }
public Type? ConverterType { get; }

/// <inheritdoc />
public bool CanWrite
{
Expand Down
5 changes: 3 additions & 2 deletions src/Mewdeko/Common/Yml/CommentsObjectGraphVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public CommentsObjectGraphVisitor(IObjectGraphVisitor<IEmitter> nextVisitor)
{
}


/// <inheritdoc />
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value, IEmitter context)
public override bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, IEmitter context, ObjectSerializer serializer)
{
if (value is CommentsObjectDescriptor commentsDescriptor &&
!string.IsNullOrWhiteSpace(commentsDescriptor.Comment))
Expand All @@ -29,6 +30,6 @@ public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor val
context.Emit(new Comment(commentsDescriptor.Comment.Replace("\n", "\n# "), false));
}

return base.EnterMapping(key, value, context);
return base.EnterMapping(key, value, context, serializer);
}
}
8 changes: 4 additions & 4 deletions src/Mewdeko/Common/Yml/Rgba32Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public bool Accepts(Type type)
}

/// <inheritdoc />
public object ReadYaml(IParser parser, Type type)
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var scalar = parser.Consume<Scalar>();
return SKColor.Parse(scalar.Value);
}

/// <inheritdoc />
public void WriteYaml(IEmitter emitter, object? value, Type type)
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
{
var color = (SKColor)value;
var val = (uint)((color.Blue << 0) | (color.Green << 8) | (color.Red << 16));
Expand All @@ -45,14 +45,14 @@ public bool Accepts(Type type)
}

/// <inheritdoc />
public object ReadYaml(IParser parser, Type type)
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var scalar = parser.Consume<Scalar>();
return new CultureInfo(scalar.Value);
}

/// <inheritdoc />
public void WriteYaml(IEmitter emitter, object? value, Type type)
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
{
var ci = (CultureInfo)value;
emitter.Emit(new Scalar(ci.Name));
Expand Down
5 changes: 3 additions & 2 deletions src/Mewdeko/Common/Yml/UriConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ public bool Accepts(Type type)
}

/// <inheritdoc />
public object ReadYaml(IParser parser, Type type)
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var scalar = parser.Consume<Scalar>();
return new Uri(scalar.Value);
}

/// <inheritdoc />
public void WriteYaml(IEmitter emitter, object? value, Type type)
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
{
var uri = (Uri)value;
emitter.Emit(new Scalar(uri.ToString()));
}

}
9 changes: 8 additions & 1 deletion src/Mewdeko/Controllers/BotStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class BotStatus(DiscordShardedClient client, StatsService statsService, C
[HttpGet]
public async Task<IActionResult> GetStatus()
{
var creds = new BotCredentials();
var clients = client.Shards;
var rest = client.Rest;
var curUser = await rest.GetUserAsync(client.CurrentUser.Id);
Expand All @@ -40,7 +41,8 @@ public async Task<IActionResult> GetStatus()
BotStatus = client.Status.ToString(),
UserCount = clients.Select(x => x.Guilds.Sum(g => g.Users.Count)).Sum(),
CommitHash = GetCommitHash(),
BotId = client.CurrentUser.Id
BotId = client.CurrentUser.Id,
InstanceUrl = $"http://localhost:{creds.ApiPort}"
};

return Ok(toReturn);
Expand Down Expand Up @@ -159,5 +161,10 @@ public class BotStatusModel
/// The bots userId
/// </summary>
public ulong BotId { get; set; }

/// <summary>
/// The api url of this instance.
/// </summary>
public string InstanceUrl { get; set; }
}
}
18 changes: 15 additions & 3 deletions src/Mewdeko/Database/MewdekoContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Mewdeko.Common.Attributes.DB;
using Mewdeko.Modules.OwnerOnly.Services;
using Mewdeko.Services.Impl;
using Mewdeko.Services.Impl;
using Microsoft.EntityFrameworkCore;

namespace Mewdeko.Database;
Expand All @@ -26,6 +24,15 @@ public MewdekoContext(DbContextOptions options) : base(options)
/// </summary>
public DbSet<GlobalUserBalance> GlobalUserBalances { get; set; }

/// <summary>
/// Gets or sets invite counts
/// </summary>
public DbSet<InviteCount> InviteCounts { get; set; }
/// <summary>
/// Gets or sets invited by
/// </summary>
public DbSet<InvitedBy> InvitedBy { get; set; }

/// <summary>
/// Gets or sets the lockdown channel permissions.
/// </summary>
Expand Down Expand Up @@ -421,6 +428,11 @@ public MewdekoContext(DbContextOptions options) : base(options)
/// </summary>
public DbSet<LocalBotInstances> BotInstances { get; set; }

/// <summary>
/// Settings for invite counting
/// </summary>
public DbSet<InviteCountSettings> InviteCountSettings { get; set; }

/// <summary>
/// Configures the model that was discovered by convention from the entity types
/// exposed in <see cref="DbSet{TEntity}" /> properties on your derived context.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable
Expand Down
Loading

0 comments on commit a9ba7b7

Please sign in to comment.