Files
LaDOSE/LaDOSE.Src/LaDOSE.DiscordBot/Command/Public.cs

130 lines
3.6 KiB
C#
Raw Normal View History

2022-07-30 18:22:49 +02:00
using System;
using System.Collections.Generic;
2022-07-30 22:55:46 +02:00
using System.Globalization;
2022-07-30 18:22:49 +02:00
using System.IO;
2022-07-30 22:24:59 +02:00
using System.Linq;
2022-07-30 18:22:49 +02:00
using System.Threading.Tasks;
2025-03-07 14:55:00 +01:00
using DSharpPlus.Commands;
2022-07-30 18:22:49 +02:00
namespace LaDOSE.DiscordBot.Command
{
2025-03-07 14:55:00 +01:00
public class Public
2022-07-30 18:22:49 +02:00
{
2022-09-14 23:29:22 +02:00
2022-07-30 22:24:59 +02:00
private static List<string> Quotes { get; set; }
private static List<string> Questions { get; set; }
private static List<string> Answers { get; set; }
2022-07-30 18:22:49 +02:00
private Random rnd { get; set; }
2022-09-14 23:29:22 +02:00
public Public()
2022-07-30 18:22:49 +02:00
{
2022-09-14 23:29:22 +02:00
2022-07-30 18:22:49 +02:00
rnd = new Random(DateTime.Now.Millisecond);
}
[Command("twitch")]
public async Task TwitchAsync(CommandContext ctx)
{
await ctx.RespondAsync("https://www.twitch.tv/LaDOSETV");
}
2022-07-30 22:55:46 +02:00
[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
2022-07-30 22:24:59 +02:00
[Command("cards")]
2022-07-30 22:55:46 +02:00
public async Task CardsAsync(CommandContext ctx)
2022-07-30 22:24:59 +02:00
{
if (Questions == null)
LoadCards();
var response = string.Empty;
var q = Questions[rnd.Next(Questions.Count - 1)];
2022-07-31 02:06:26 +02:00
var s = q.Split('_', StringSplitOptions.None);
2022-07-31 01:38:08 +02:00
if (s.Length == 1)
2022-07-30 22:24:59 +02:00
{
2022-07-31 01:38:08 +02:00
response += q + " " + Answers[rnd.Next(Answers.Count - 1)];
}
else
{
2022-09-14 23:29:22 +02:00
2022-07-31 01:38:08 +02:00
for (int i = 0; i < s.Length - 1; i++)
{
2022-09-14 23:29:22 +02:00
if (s[i] == "" && i==0)
{
response += Answers[rnd.Next(Answers.Count - 1)];
}
else
{
response += s[i] + "***" + Answers[rnd.Next(Answers.Count - 1)].ToLower() + "***";
}
2022-07-31 01:38:08 +02:00
}
response += s[s.Length - 1];
2022-07-30 22:24:59 +02:00
}
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>();
}
2022-07-30 22:55:46 +02:00
}
#endregion
#region Quotes
2022-07-30 18:22:49 +02:00
[Command("Quote")]
public async Task QuotesAsync(CommandContext ctx)
{
if (Quotes == null)
LoadQuote();
2022-07-30 22:55:46 +02:00
await ctx.RespondAsync("```" + Quotes[rnd.Next(Quotes.Count - 1)] + "```");
2022-07-30 18:22:49 +02:00
}
2022-07-30 22:55:46 +02:00
2022-07-30 18:22:49 +02:00
private void LoadQuote()
{
Quotes = new List<string>();
string[] fileQuotes = File.ReadAllLines("quotes.txt");
string currentQuote = string.Empty;
2022-07-30 22:55:46 +02:00
for (int i = 0; i < fileQuotes.Length; i++)
2022-07-30 18:22:49 +02:00
{
2022-07-30 22:55:46 +02:00
if (String.IsNullOrEmpty(fileQuotes[i]))
2022-07-30 18:22:49 +02:00
{
Quotes.Add(currentQuote);
currentQuote = string.Empty;
}
currentQuote += fileQuotes[i] + (!String.IsNullOrEmpty(currentQuote) ? "\r\n" : "");
}
2022-07-30 22:55:46 +02:00
2022-07-30 18:22:49 +02:00
}
2022-07-30 22:55:46 +02:00
#endregion
2022-07-30 18:22:49 +02:00
}
}