Split Geekbot.net into src/Bot, src/Core, and src/Web

This commit is contained in:
runebaas 2020-08-08 22:24:01 +02:00
parent 7b6dd2d2f9
commit fc0af492ad
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
197 changed files with 542 additions and 498 deletions

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace Geekbot.Core.Extensions
{
public static class DbSetExtensions
{
public static EntityEntry<T> AddIfNotExists<T>(this DbSet<T> dbSet, T entity, Expression<Func<T, bool>> predicate = null) where T : class, new()
{
var exists = predicate != null ? dbSet.Any(predicate) : dbSet.Any();
return !exists ? dbSet.Add(entity) : null;
}
// https://github.com/dotnet/efcore/issues/18124
public static IAsyncEnumerable<TEntity> AsAsyncEnumerable<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj) where TEntity : class
{
return Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AsAsyncEnumerable(obj);
}
public static IQueryable<TEntity> Where<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj, System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate) where TEntity : class
{
return System.Linq.Queryable.Where(obj, predicate);
}
}
}

View file

@ -0,0 +1,12 @@
using Discord;
namespace Geekbot.Core.Extensions
{
public static class EmbedBuilderExtensions
{
public static EmbedBuilder AddInlineField(this EmbedBuilder builder, string name, object value)
{
return builder.AddField(new EmbedFieldBuilder().WithIsInline(true).WithName(name).WithValue(value));
}
}
}

View file

@ -0,0 +1,15 @@
using System;
namespace Geekbot.Core.Extensions
{
public static class IntExtensions
{
public static void Times(this int count, Action action)
{
for (var i = 0; i < count; i++)
{
action();
}
}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace Geekbot.Core.Extensions
{
public static class LongExtensions
{
public static ulong AsUlong(this long thing)
{
return Convert.ToUInt64(thing);
}
}
}

View file

@ -0,0 +1,12 @@
using System.Linq;
namespace Geekbot.Core.Extensions
{
public static class StringExtensions
{
public static string CapitalizeFirst(this string source)
{
return source.First().ToString().ToUpper() + source.Substring(1);
}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace Geekbot.Core.Extensions
{
public static class UlongExtensions
{
public static long AsLong(this ulong thing)
{
return Convert.ToInt64(thing);
}
}
}