2017-09-14 22:11:19 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2017-10-12 16:34:10 +02:00
|
|
|
|
using Geekbot.net.Lib;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
using Geekbot.net.Lib.ErrorHandling;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
2018-05-03 00:56:06 +02:00
|
|
|
|
namespace Geekbot.net.Commands.Randomness
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
public class Ship : ModuleBase
|
|
|
|
|
{
|
2017-12-29 01:53:50 +01:00
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2017-10-26 00:55:04 +02:00
|
|
|
|
private readonly IDatabase _redis;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
|
2018-02-14 23:01:28 +01:00
|
|
|
|
public Ship(IDatabase redis, IErrorHandler errorHandler)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
_redis = redis;
|
|
|
|
|
_errorHandler = errorHandler;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Command("Ship", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Fun)]
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Summary("Ask the Shipping meter")]
|
|
|
|
|
public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
try
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
var dbstring = "";
|
|
|
|
|
if (user1.Id > user2.Id)
|
|
|
|
|
dbstring = $"{user1.Id}-{user2.Id}";
|
|
|
|
|
else
|
|
|
|
|
dbstring = $"{user2.Id}-{user1.Id}";
|
|
|
|
|
|
|
|
|
|
var dbval = _redis.HashGet($"{Context.Guild.Id}:Ships", dbstring);
|
|
|
|
|
var shippingRate = 0;
|
|
|
|
|
if (dbval.IsNullOrEmpty)
|
|
|
|
|
{
|
2018-02-14 23:01:28 +01:00
|
|
|
|
shippingRate = new Random().Next(1, 100);
|
2017-10-26 00:55:04 +02:00
|
|
|
|
_redis.HashSet($"{Context.Guild.Id}:Ships", dbstring, shippingRate);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shippingRate = int.Parse(dbval.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n";
|
|
|
|
|
reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
|
|
|
|
reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
|
|
|
|
await ReplyAsync(reply);
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
2017-10-26 00:55:04 +02:00
|
|
|
|
catch (Exception e)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-26 00:55:04 +02:00
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string DeterminateSuccess(int rate)
|
|
|
|
|
{
|
|
|
|
|
if (rate < 20)
|
|
|
|
|
return "Not gonna happen";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
if (rate >= 20 && rate < 40)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
return "Not such a good idea";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
if (rate >= 40 && rate < 60)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
return "There might be a chance";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
if (rate >= 60 && rate < 80)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
return "Almost a match, but could work";
|
2018-04-30 23:44:19 +02:00
|
|
|
|
return rate >= 80 ? "It's a match" : "a";
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BlockCounter(int rate)
|
|
|
|
|
{
|
|
|
|
|
var amount = Math.Floor(decimal.Floor(rate / 10));
|
|
|
|
|
Console.WriteLine(amount);
|
|
|
|
|
var blocks = "";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
for (var i = 1; i <= 10; i++)
|
|
|
|
|
if (i <= amount)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
blocks = blocks + ":white_medium_small_square:";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
if (i == amount)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
blocks = blocks + $" {rate}% ";
|
2017-09-15 22:56:03 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
blocks = blocks + ":black_medium_small_square:";
|
|
|
|
|
}
|
2017-12-29 01:53:50 +01:00
|
|
|
|
|
2017-09-14 22:11:19 +02:00
|
|
|
|
return blocks;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-15 21:14:38 +02:00
|
|
|
|
}
|