From 501e19290044ae4eb8ff2b2fdc5d8a85780e6590 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Sat, 30 Jul 2022 22:55:46 +0200 Subject: [PATCH] Suppression Challonge in Db. --- .../LaDOSE.DiscordBot/Command/Public.cs | 57 ++++++++++++------- .../Challonge/ChallongeParticipent.cs | 4 +- .../Challonge/ChallongeTournament.cs | 3 +- .../LaDOSE.Entity/Context/LaDOSEDbContext.cs | 17 +++--- 4 files changed, 50 insertions(+), 31 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs index f98e8b1..3bdad0b 100644 --- a/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs +++ b/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -19,7 +20,6 @@ namespace LaDOSE.DiscordBot.Command { dep = d; rnd = new Random(DateTime.Now.Millisecond); - } [Command("twitch")] @@ -28,8 +28,29 @@ namespace LaDOSE.DiscordBot.Command await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV"); } + + + [Command("roll")] + public async Task RollAsync(CommandContext ctx, string command = "") + { + int next = 6; + + if (!string.IsNullOrEmpty(command)) + { + if(!int.TryParse(command, System.Globalization.NumberStyles.Integer, CultureInfo.InvariantCulture, out next)) + { + await ctx.RespondAsync("Stupid"); + return; + } + } + await ctx.RespondAsync(rnd.Next(1,next+1).ToString()); + + } + + + #region Cards Against Humanity [Command("cards")] - public async Task CardssAsync(CommandContext ctx) + public async Task CardsAsync(CommandContext ctx) { if (Questions == null) LoadCards(); @@ -38,19 +59,13 @@ namespace LaDOSE.DiscordBot.Command var q = Questions[rnd.Next(Questions.Count - 1)]; var s = q.Split('_', StringSplitOptions.RemoveEmptyEntries); - for(int i = 0; i< s.Length; i++) + for (int i = 0; i < s.Length - 1; i++) { - if (i < s.Length-1) - { - response += s[i] + Answers[rnd.Next(Answers.Count - 1)]; - } - else - { - response += s[i]; - } - + response += s[i] + Answers[rnd.Next(Answers.Count - 1)]; } - + response += s[s.Length-1]; + + await ctx.RespondAsync(response); } @@ -67,26 +82,29 @@ namespace LaDOSE.DiscordBot.Command Questions = new List(); Answers = new List(); } - - } + } + #endregion + #region Quotes [Command("Quote")] public async Task QuotesAsync(CommandContext ctx) { if (Quotes == null) LoadQuote(); - await ctx.RespondAsync("```"+ Quotes[rnd.Next(Quotes.Count-1)] + "```"); + await ctx.RespondAsync("```" + Quotes[rnd.Next(Quotes.Count - 1)] + "```"); } + + private void LoadQuote() { Quotes = new List(); string[] fileQuotes = File.ReadAllLines("quotes.txt"); string currentQuote = string.Empty; - for(int i = 0; i < fileQuotes.Length; i++) + for (int i = 0; i < fileQuotes.Length; i++) { - if(String.IsNullOrEmpty(fileQuotes[i])) + if (String.IsNullOrEmpty(fileQuotes[i])) { Quotes.Add(currentQuote); currentQuote = string.Empty; @@ -94,7 +112,8 @@ namespace LaDOSE.DiscordBot.Command currentQuote += fileQuotes[i] + (!String.IsNullOrEmpty(currentQuote) ? "\r\n" : ""); } - + } + #endregion } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeParticipent.cs b/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeParticipent.cs index 3f78f25..8cc6d43 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeParticipent.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeParticipent.cs @@ -2,9 +2,9 @@ namespace LaDOSE.Entity.Challonge { - public class ChallongeParticipent : Context.Entity - + public class ChallongeParticipent { + public int Id { get; set; } public ChallongeTournament ChallongeTournament { get; set; } public int ChallongeTournamentId { get; set; } public int ChallongeId { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeTournament.cs b/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeTournament.cs index ebe6c99..1ae00bb 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeTournament.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Challonge/ChallongeTournament.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; namespace LaDOSE.Entity.Challonge { - public class ChallongeTournament : Context.Entity + public class ChallongeTournament { + public int Id { get; set; } public int ChallongeId { get; set; } public string Name { get; set; } public Game Game { get; set; } diff --git a/LaDOSE.Src/LaDOSE.Entity/Context/LaDOSEDbContext.cs b/LaDOSE.Src/LaDOSE.Entity/Context/LaDOSEDbContext.cs index 34dbe0d..570816b 100644 --- a/LaDOSE.Src/LaDOSE.Entity/Context/LaDOSEDbContext.cs +++ b/LaDOSE.Src/LaDOSE.Entity/Context/LaDOSEDbContext.cs @@ -29,8 +29,8 @@ namespace LaDOSE.Entity.Context public DbSet Set { get; set; } #endregion - public DbSet ChallongeParticipent { get; set; } - public DbSet ChallongeTournament { get; set; } + //public DbSet ChallongeParticipent { get; set; } + //public DbSet ChallongeTournament { get; set; } #region BotEvents public DbSet BotEvent { get; set; } @@ -47,7 +47,6 @@ namespace LaDOSE.Entity.Context base.OnModelCreating(modelBuilder); - modelBuilder.Entity() .HasMany(s => s.Tournaments); @@ -139,12 +138,12 @@ namespace LaDOSE.Entity.Context .HasForeignKey(pt => pt.WPUserId); #endregion - #region Challonge - modelBuilder.Entity() - .HasOne(pt => pt.ChallongeTournament) - .WithMany(p => p.Participents) - .HasForeignKey(pt => pt.ChallongeTournamentId); - #endregion + //#region Challonge + //modelBuilder.Entity() + // .HasOne(pt => pt.ChallongeTournament) + // .WithMany(p => p.Participents) + // .HasForeignKey(pt => pt.ChallongeTournamentId); + //#endregion } }