-
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 #11 from theiam79/dev
Adds play file subscriptions
- Loading branch information
Showing
15 changed files
with
423 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using BGStats.Bot.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BGStats.Bot.Context | ||
{ | ||
public class SubscriberContext : DbContext | ||
{ | ||
public SubscriberContext(DbContextOptions<SubscriberContext> options) : base(options) { } | ||
|
||
public DbSet<Subscriber> Subscribers { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.Entity<Subscriber>() | ||
.Property(p => p.SubscriberId) | ||
.ValueGeneratedOnAdd(); | ||
} | ||
} | ||
|
||
public class SubscriberContextFactory : IDesignTimeDbContextFactory<SubscriberContext> | ||
{ | ||
public SubscriberContext CreateDbContext(string[] args) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder<SubscriberContext>().UseSqlite("Data Source = TestSubscribers.db"); | ||
return new SubscriberContext(optionsBuilder.Options); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/BGStats.Bot/Migrations/20200822044922_init.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace BGStats.Bot.Migrations | ||
{ | ||
public partial class init : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Subscribers", | ||
columns: table => new | ||
{ | ||
SubscriberId = table.Column<int>(nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
DiscordId = table.Column<ulong>(nullable: false), | ||
PlayerName = table.Column<string>(nullable: true) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Subscribers", x => x.SubscriberId); | ||
}); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Subscribers"); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/BGStats.Bot/Migrations/20200822050642_autoId.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
namespace BGStats.Bot.Migrations | ||
{ | ||
public partial class autoId : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
|
||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
|
||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/BGStats.Bot/Migrations/SubscriberContextModelSnapshot.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 @@ | ||
// <auto-generated /> | ||
using BGStats.Bot.Context; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
|
||
namespace BGStats.Bot.Migrations | ||
{ | ||
[DbContext(typeof(SubscriberContext))] | ||
partial class SubscriberContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "3.1.7"); | ||
|
||
modelBuilder.Entity("BGStats.Bot.Models.Subscriber", b => | ||
{ | ||
b.Property<int>("SubscriberId") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("INTEGER"); | ||
b.Property<ulong>("DiscordId") | ||
.HasColumnType("INTEGER"); | ||
b.Property<string>("PlayerName") | ||
.HasColumnType("TEXT"); | ||
b.HasKey("SubscriberId"); | ||
b.ToTable("Subscribers"); | ||
}); | ||
#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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BGStats.Bot.Models | ||
{ | ||
public class Subscriber | ||
{ | ||
|
||
public int SubscriberId { get; set; } | ||
public ulong DiscordId { get; set; } | ||
public string PlayerName { 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
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,66 @@ | ||
using BGStats.Bot.Services; | ||
using Discord.Commands; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BGStats.Bot.Modules | ||
{ | ||
[Group("subscription")] | ||
public class SubscribeModule : ModuleBase<SocketCommandContext> | ||
{ | ||
private readonly INotificationService _notificationService; | ||
|
||
public SubscribeModule(INotificationService notificationService) | ||
{ | ||
_notificationService = notificationService; | ||
} | ||
|
||
[Command("add")] | ||
[Summary("Subscribe to recieve any play files sent by others that include the given player name")] | ||
public async Task Subscribe([Remainder] string playerName) | ||
{ | ||
await _notificationService.Subscribe(Context.User.Id, playerName); | ||
await ReplyAsync($"Successfully subscribed to plays that include {playerName}"); | ||
} | ||
|
||
[Command("remove")] | ||
[Summary("Remove one of your existing subscriptions")] | ||
public async Task Unsubscribe([Remainder] string playerName) | ||
{ | ||
await _notificationService.Unsubscribe(Context.User.Id, playerName); | ||
await ReplyAsync($"Successfully unsubscribed from plays that include {playerName}"); | ||
} | ||
|
||
[Command("removeAll")] | ||
[Summary("Remove all of your existing subscriptions")] | ||
public async Task UnsubscribeAll() | ||
{ | ||
await _notificationService.Unsubscribe(Context.User.Id); | ||
await ReplyAsync($"Successfully unsubscribed from all plays"); | ||
} | ||
|
||
[Command("list")] | ||
[Summary("List all of your current subscriptions")] | ||
public async Task ListSubscriptions() | ||
{ | ||
var subs = await _notificationService.GetSubscriptions(Context.User.Id); | ||
|
||
var message = new StringBuilder().AppendLine($"Found {subs.Count} subscriptions for {Context.User.Username}").AppendJoin('\n', subs.Where(s => s.DiscordId == Context.User.Id).Select(s => s.PlayerName)).ToString(); | ||
var channel = await Context.User.GetOrCreateDMChannelAsync(); | ||
await channel.SendMessageAsync(message); | ||
} | ||
|
||
[Command("listAll")] | ||
[RequireOwner] | ||
public async Task ListAllSubscriptions() | ||
{ | ||
var subs = await _notificationService.GetAllSubscriptions(); | ||
var message = new StringBuilder().AppendLine($"Found {subs.Count} total subscriptions").AppendJoin('\n', subs.Select(s => $"{Context.Client.GetUser(s.DiscordId).Username} - {s.PlayerName}")).ToString(); | ||
var channel = await Context.User.GetOrCreateDMChannelAsync(); | ||
await channel.SendMessageAsync(message); | ||
} | ||
} | ||
} |
Oops, something went wrong.