-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from murl-digital/development
v1.2.0
- Loading branch information
Showing
27 changed files
with
1,303 additions
and
188 deletions.
There are no files selected for viewing
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
10 changes: 10 additions & 0 deletions
10
GarbageCan.Application/Common/Interfaces/IDiscordPresenceService.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,10 @@ | ||
using System.Threading.Tasks; | ||
using GarbageCan.Domain.Enums; | ||
|
||
namespace GarbageCan.Application.Common.Interfaces | ||
{ | ||
public interface IDiscordPresenceService | ||
{ | ||
public Task ChangeStatusAsync(string name, Activity activity); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
GarbageCan.Application/Fun/Commands/RandomStatus/AddStatusCommand.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,37 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GarbageCan.Application.Common.Interfaces; | ||
using GarbageCan.Domain.Entities.Presence; | ||
using GarbageCan.Domain.Enums; | ||
using MediatR; | ||
|
||
namespace GarbageCan.Application.Fun.Commands.RandomStatus | ||
{ | ||
public class AddStatusCommand : IRequest | ||
{ | ||
public string Name { get; set; } | ||
public Activity Activity { get; set; } | ||
} | ||
|
||
public class AddStatusCommandHandler : IRequestHandler<AddStatusCommand> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public AddStatusCommandHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<Unit> Handle(AddStatusCommand request, CancellationToken cancellationToken) | ||
{ | ||
_context.CustomStatuses.Add(new CustomStatus | ||
{ | ||
Name = request.Name, | ||
Activity = request.Activity | ||
}); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
GarbageCan.Application/Fun/Commands/RandomStatus/RandomizeStatusCommand.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,45 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GarbageCan.Application.Common.Interfaces; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GarbageCan.Application.Fun.Commands.RandomStatus | ||
{ | ||
public class RandomizeStatusCommand : IRequest | ||
{ | ||
} | ||
|
||
public class RandomizeStatusCommandHandler : IRequestHandler<RandomizeStatusCommand> | ||
{ | ||
private readonly IDiscordConfiguration _configuration; | ||
private readonly IRngService _rngService; | ||
private readonly IDiscordPresenceService _presenceService; | ||
private readonly ILogger<RandomizeStatusCommandHandler> _logger; | ||
private readonly IApplicationDbContext _context; | ||
|
||
public RandomizeStatusCommandHandler(IDiscordConfiguration configuration, IRngService rngService, | ||
IDiscordPresenceService presenceService, ILogger<RandomizeStatusCommandHandler> logger, | ||
IApplicationDbContext context) | ||
{ | ||
_configuration = configuration; | ||
_rngService = rngService; | ||
_context = context; | ||
_presenceService = presenceService; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<Unit> Handle(RandomizeStatusCommand request, CancellationToken cancellationToken) | ||
{ | ||
var prefix = _configuration.CommandPrefix; | ||
var dbList = await _context.CustomStatuses.ToArrayAsync(cancellationToken); | ||
var activity = dbList[_rngService.IntFromRange(0, dbList.Length)]; | ||
_logger.LogDebug("i choose {Name}", activity.Name); | ||
|
||
await _presenceService.ChangeStatusAsync($"{activity.Name} | {prefix}help", activity.Activity); | ||
|
||
return Unit.Value; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using GarbageCan.Domain.Enums; | ||
|
||
namespace GarbageCan.Domain.Entities.Presence | ||
{ | ||
public class CustomStatus | ||
{ | ||
public int Id { get; set; } | ||
public Activity Activity { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
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,11 @@ | ||
namespace GarbageCan.Domain.Enums | ||
{ | ||
public enum Activity | ||
{ | ||
Playing, | ||
Streaming, | ||
ListeningTo, | ||
Watching, | ||
Competing | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
GarbageCan.Infrastructure/Discord/DiscordPresenceService.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,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using DSharpPlus; | ||
using DSharpPlus.Entities; | ||
using GarbageCan.Application.Common.Interfaces; | ||
using GarbageCan.Domain.Enums; | ||
|
||
namespace GarbageCan.Infrastructure.Discord | ||
{ | ||
public class DiscordPresenceService : IDiscordPresenceService | ||
{ | ||
private readonly DiscordClient _client; | ||
|
||
public DiscordPresenceService(DiscordClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public async Task ChangeStatusAsync(string name, Activity activity) | ||
{ | ||
if (!Enum.TryParse(activity.ToString(), out ActivityType discordActivity)) | ||
throw new InvalidOperationException("Parsing activity type failed"); | ||
|
||
await _client.UpdateStatusAsync(new DiscordActivity(name, discordActivity)); | ||
} | ||
} | ||
} |
80 changes: 41 additions & 39 deletions
80
GarbageCan.Infrastructure/Persistence/ApplicationDbContext.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 |
---|---|---|
@@ -1,39 +1,41 @@ | ||
using GarbageCan.Application.Common.Interfaces; | ||
using GarbageCan.Domain.Entities.Boosters; | ||
using GarbageCan.Domain.Entities.Config; | ||
using GarbageCan.Domain.Entities.Moderation; | ||
using GarbageCan.Domain.Entities.Roles; | ||
using GarbageCan.Domain.Entities.XP; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace GarbageCan.Infrastructure.Persistence | ||
{ | ||
public class ApplicationDbContext : DbContext, IApplicationDbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions options) : base(options) | ||
{ | ||
} | ||
|
||
public DbSet<ConditionalRole> ConditionalRoles { get; set; } | ||
public DbSet<Config> Config { get; set; } | ||
public DbSet<JoinRole> JoinRoles { get; set; } | ||
public DbSet<WatchedUser> JoinWatchlist { get; set; } | ||
public DbSet<LevelRole> LevelRoles { get; set; } | ||
public DbSet<ActionLog> ModerationActionLogs { get; set; } | ||
public DbSet<ActiveChannelRestrict> ModerationActiveChannelRestricts { get; set; } | ||
public DbSet<ActiveMute> ModerationActiveMutes { get; set; } | ||
public DbSet<ReactionRole> ReactionRoles { get; set; } | ||
public DbSet<ActiveBooster> XPActiveBoosters { get; set; } | ||
public DbSet<AvailableSlot> XPAvailableSlots { get; set; } | ||
public DbSet<ExcludedChannel> XPExcludedChannels { get; set; } | ||
public DbSet<QueuedBooster> XPQueuedBoosters { get; set; } | ||
public DbSet<UserBooster> XPUserBoosters { get; set; } | ||
public DbSet<User> XPUsers { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
builder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly); | ||
base.OnModelCreating(builder); | ||
} | ||
} | ||
} | ||
using GarbageCan.Application.Common.Interfaces; | ||
using GarbageCan.Domain.Entities.Boosters; | ||
using GarbageCan.Domain.Entities.Config; | ||
using GarbageCan.Domain.Entities.Moderation; | ||
using GarbageCan.Domain.Entities.Presence; | ||
using GarbageCan.Domain.Entities.Roles; | ||
using GarbageCan.Domain.Entities.XP; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace GarbageCan.Infrastructure.Persistence | ||
{ | ||
public class ApplicationDbContext : DbContext, IApplicationDbContext | ||
{ | ||
public ApplicationDbContext(DbContextOptions options) : base(options) | ||
{ | ||
} | ||
|
||
public DbSet<ConditionalRole> ConditionalRoles { get; set; } | ||
public DbSet<Config> Config { get; set; } | ||
public DbSet<JoinRole> JoinRoles { get; set; } | ||
public DbSet<WatchedUser> JoinWatchlist { get; set; } | ||
public DbSet<LevelRole> LevelRoles { get; set; } | ||
public DbSet<ActionLog> ModerationActionLogs { get; set; } | ||
public DbSet<ActiveChannelRestrict> ModerationActiveChannelRestricts { get; set; } | ||
public DbSet<ActiveMute> ModerationActiveMutes { get; set; } | ||
public DbSet<ReactionRole> ReactionRoles { get; set; } | ||
public DbSet<ActiveBooster> XPActiveBoosters { get; set; } | ||
public DbSet<AvailableSlot> XPAvailableSlots { get; set; } | ||
public DbSet<ExcludedChannel> XPExcludedChannels { get; set; } | ||
public DbSet<QueuedBooster> XPQueuedBoosters { get; set; } | ||
public DbSet<UserBooster> XPUserBoosters { get; set; } | ||
public DbSet<User> XPUsers { get; set; } | ||
public DbSet<CustomStatus> CustomStatuses { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder builder) | ||
{ | ||
builder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly); | ||
base.OnModelCreating(builder); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
GarbageCan.Infrastructure/Persistence/Configurations/CustomStatusConfiguration.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,17 @@ | ||
using GarbageCan.Domain.Entities.Presence; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace GarbageCan.Infrastructure.Persistence.Configurations | ||
{ | ||
public class CustomStatusConfiguration : IEntityTypeConfiguration<CustomStatus> | ||
{ | ||
public void Configure(EntityTypeBuilder<CustomStatus> builder) | ||
{ | ||
builder.ToTable("customStatuses"); | ||
builder.HasKey(t => t.Id); | ||
builder.Property(t => t.Activity).HasColumnName("activity"); | ||
builder.Property(t => t.Name).HasColumnName("name"); | ||
} | ||
} | ||
} |
Oops, something went wrong.