Cards against humanity

This commit is contained in:
2022-07-30 22:24:59 +02:00
parent 8ce463c40b
commit 019ca2d543
9 changed files with 6818 additions and 5224 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
@@ -10,12 +11,15 @@ namespace LaDOSE.DiscordBot.Command
public class Public
{
private readonly Dependencies dep;
private List<string> Quotes { get; set; }
private static List<string> Quotes { get; set; }
private static List<string> Questions { get; set; }
private static List<string> Answers { get; set; }
private Random rnd { get; set; }
public Public(Dependencies d)
{
dep = d;
rnd = new Random(DateTime.Now.Millisecond);
}
[Command("twitch")]
@@ -24,10 +28,51 @@ namespace LaDOSE.DiscordBot.Command
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
}
[Command("cards")]
public async Task CardssAsync(CommandContext ctx)
{
if (Questions == null)
LoadCards();
var response = string.Empty;
var q = Questions[rnd.Next(Questions.Count - 1)];
var s = q.Split('_', StringSplitOptions.RemoveEmptyEntries);
for(int i = 0; i< s.Length; i++)
{
if (i < s.Length-1)
{
response += s[i] + Answers[rnd.Next(Answers.Count - 1)];
}
else
{
response += s[i];
}
}
await ctx.RespondAsync(response);
}
private void LoadCards()
{
try
{
Questions = File.ReadAllLines("questions.txt").ToList();
Answers = File.ReadAllLines("answers.txt").ToList();
}
catch (FileNotFoundException)
{
Questions = new List<string>();
Answers = new List<string>();
}
}
[Command("Quote")]
public async Task QuotesAsync(CommandContext ctx)
{
if (Quotes == null)
LoadQuote();