geekbot/Geekbot.net/Commands/CheckEm.cs

74 lines
2.1 KiB
C#
Raw Normal View History

2017-09-15 12:58:49 +02:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Media;
2017-09-15 12:58:49 +02:00
namespace Geekbot.net.Commands
2017-09-15 12:58:49 +02:00
{
public class CheckEm : ModuleBase
{
private readonly IMediaProvider _checkEmImages;
private readonly IErrorHandler _errorHandler;
2017-12-29 01:53:50 +01:00
private readonly Random _rnd;
2017-09-15 22:56:03 +02:00
public CheckEm(Random RandomClient, IMediaProvider mediaProvider, IErrorHandler errorHandler)
2017-09-15 12:58:49 +02:00
{
_rnd = RandomClient;
_checkEmImages = mediaProvider;
_errorHandler = errorHandler;
2017-09-15 12:58:49 +02:00
}
2017-09-15 22:56:03 +02:00
[Command("checkem", RunMode = RunMode.Async)]
2017-10-12 16:34:10 +02:00
[Remarks(CommandCategories.Randomness)]
2017-09-15 22:56:03 +02:00
[Summary("Check for dubs")]
2017-09-15 12:58:49 +02:00
public async Task MuhDubs()
{
2017-09-15 22:56:03 +02:00
try
{
var number = _rnd.Next(10000000, 99999999);
2017-09-15 22:56:03 +02:00
var dubtriqua = "";
var ns = GetIntArray(number);
if (ns[7] == ns[6])
{
dubtriqua = "DUBS";
if (ns[6] == ns[5])
{
dubtriqua = "TRIPS";
if (ns[5] == ns[4])
dubtriqua = "QUADS";
}
}
var sb = new StringBuilder();
sb.AppendLine($"Check em {Context.User.Mention}");
sb.AppendLine($"**{number}**");
if (!string.IsNullOrEmpty(dubtriqua))
sb.AppendLine($":tada: {dubtriqua} :tada:");
sb.AppendLine(_checkEmImages.getCheckem());
2017-09-15 22:56:03 +02:00
await ReplyAsync(sb.ToString());
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
2017-09-15 12:58:49 +02:00
}
}
2017-09-15 22:56:03 +02:00
private int[] GetIntArray(int num)
{
var listOfInts = new List<int>();
while (num > 0)
{
listOfInts.Add(num % 10);
num = num / 10;
}
2017-12-29 01:53:50 +01:00
2017-09-15 22:56:03 +02:00
listOfInts.Reverse();
return listOfInts.ToArray();
2017-09-15 12:58:49 +02:00
}
}
}