Fixed code inconsistencies and adding support for logging to sentryio
This commit is contained in:
parent
2e083bc188
commit
9efac29956
18 changed files with 228 additions and 161 deletions
|
@ -9,28 +9,42 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Cat : ModuleBase
|
public class Cat : ModuleBase
|
||||||
{
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
public Cat(IErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
[Command("cat", RunMode = RunMode.Async)]
|
[Command("cat", RunMode = RunMode.Async)]
|
||||||
[Remarks(CommandCategories.Randomness)]
|
[Remarks(CommandCategories.Randomness)]
|
||||||
[Summary("Return a random image of a cat.")]
|
[Summary("Return a random image of a cat.")]
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
try
|
||||||
{
|
{
|
||||||
try
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("http://random.cat");
|
try
|
||||||
var response = await client.GetAsync("/meow.php");
|
{
|
||||||
response.EnsureSuccessStatusCode();
|
client.BaseAddress = new Uri("http://random.cat");
|
||||||
|
var response = await client.GetAsync("/meow.php");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||||
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
|
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
|
||||||
await ReplyAsync(catFile.file);
|
await ReplyAsync(catFile.file);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
|
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,23 +5,20 @@ using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
using Geekbot.net.Lib.Media;
|
using Geekbot.net.Lib.Media;
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Geekbot.net.Commands
|
namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class CheckEm : ModuleBase
|
public class CheckEm : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IMediaProvider checkEmImages;
|
private readonly IMediaProvider _checkEmImages;
|
||||||
private readonly Random rnd;
|
private readonly Random _rnd;
|
||||||
private readonly ILogger logger;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IErrorHandler errorHandler;
|
|
||||||
|
|
||||||
public CheckEm(Random RandomClient, IMediaProvider mediaProvider, ILogger logger, IErrorHandler errorHandler)
|
public CheckEm(Random RandomClient, IMediaProvider mediaProvider, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
this.rnd = RandomClient;
|
_rnd = RandomClient;
|
||||||
this.checkEmImages = mediaProvider;
|
_checkEmImages = mediaProvider;
|
||||||
this.logger = logger;
|
_errorHandler = errorHandler;
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("checkem", RunMode = RunMode.Async)]
|
[Command("checkem", RunMode = RunMode.Async)]
|
||||||
|
@ -31,7 +28,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var number = rnd.Next(10000000, 99999999);
|
var number = _rnd.Next(10000000, 99999999);
|
||||||
var dubtriqua = "";
|
var dubtriqua = "";
|
||||||
|
|
||||||
var ns = GetIntArray(number);
|
var ns = GetIntArray(number);
|
||||||
|
@ -51,13 +48,13 @@ namespace Geekbot.net.Commands
|
||||||
sb.AppendLine($"**{number}**");
|
sb.AppendLine($"**{number}**");
|
||||||
if (!string.IsNullOrEmpty(dubtriqua))
|
if (!string.IsNullOrEmpty(dubtriqua))
|
||||||
sb.AppendLine($":tada: {dubtriqua} :tada:");
|
sb.AppendLine($":tada: {dubtriqua} :tada:");
|
||||||
sb.AppendLine(checkEmImages.getCheckem());
|
sb.AppendLine(_checkEmImages.getCheckem());
|
||||||
|
|
||||||
await ReplyAsync(sb.ToString());
|
await ReplyAsync(sb.ToString());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
errorHandler.HandleCommandException(e, Context);
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,13 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Choose : ModuleBase
|
public class Choose : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly Random rnd;
|
private readonly Random _rnd;
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
public Choose(Random RandomClient)
|
public Choose(Random RandomClient, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
rnd = RandomClient;
|
_rnd = RandomClient;
|
||||||
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("choose", RunMode = RunMode.Async)]
|
[Command("choose", RunMode = RunMode.Async)]
|
||||||
|
@ -19,9 +21,16 @@ namespace Geekbot.net.Commands
|
||||||
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
|
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
|
||||||
public async Task Command([Remainder] [Summary("option1;option2")] string choices)
|
public async Task Command([Remainder] [Summary("option1;option2")] string choices)
|
||||||
{
|
{
|
||||||
var choicesArray = choices.Split(';');
|
try
|
||||||
var choice = rnd.Next(choicesArray.Length);
|
{
|
||||||
await ReplyAsync($"I choose **{choicesArray[choice]}**");
|
var choicesArray = choices.Split(';');
|
||||||
|
var choice = _rnd.Next(choicesArray.Length);
|
||||||
|
await ReplyAsync($"I choose **{choicesArray[choice]}**");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,15 +10,13 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Counters : ModuleBase
|
public class Counters : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IDatabase redis;
|
private readonly IDatabase _redis;
|
||||||
private readonly ILogger logger;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IErrorHandler errorHandler;
|
|
||||||
|
|
||||||
public Counters(IDatabase redis, ILogger logger, IErrorHandler errorHandler)
|
public Counters(IDatabase redis, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
this.redis = redis;
|
_redis = redis;
|
||||||
this.logger = logger;
|
_errorHandler = errorHandler;
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("good", RunMode = RunMode.Async)]
|
[Command("good", RunMode = RunMode.Async)]
|
||||||
|
@ -28,7 +26,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var lastKarmaFromRedis = redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
|
var lastKarmaFromRedis = _redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
|
||||||
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
|
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
|
||||||
if (user.Id == Context.User.Id)
|
if (user.Id == Context.User.Id)
|
||||||
{
|
{
|
||||||
|
@ -41,8 +39,8 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var newKarma = redis.HashIncrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
var newKarma = _redis.HashIncrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||||
redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
_redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||||
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString("u"))});
|
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString("u"))});
|
||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
|
@ -60,7 +58,7 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
errorHandler.HandleCommandException(e, Context);
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +69,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var lastKarmaFromRedis = redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
|
var lastKarmaFromRedis = _redis.HashGet($"{Context.Guild.Id}:KarmaTimeout", Context.User.Id.ToString());
|
||||||
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
|
var lastKarma = ConvertToDateTimeOffset(lastKarmaFromRedis.ToString());
|
||||||
if (user.Id == Context.User.Id)
|
if (user.Id == Context.User.Id)
|
||||||
{
|
{
|
||||||
|
@ -84,8 +82,8 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var newKarma = redis.HashDecrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
var newKarma = _redis.HashDecrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||||
redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
_redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||||
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString())});
|
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString())});
|
||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
|
@ -103,7 +101,7 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
errorHandler.HandleCommandException(e, Context);
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,28 +9,42 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Dog : ModuleBase
|
public class Dog : ModuleBase
|
||||||
{
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
public Dog(IErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
[Command("dog", RunMode = RunMode.Async)]
|
[Command("dog", RunMode = RunMode.Async)]
|
||||||
[Remarks(CommandCategories.Randomness)]
|
[Remarks(CommandCategories.Randomness)]
|
||||||
[Summary("Return a random image of a dog.")]
|
[Summary("Return a random image of a dog.")]
|
||||||
public async Task Say()
|
public async Task Say()
|
||||||
{
|
{
|
||||||
using (var client = new HttpClient())
|
try
|
||||||
{
|
{
|
||||||
try
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri("http://random.dog");
|
try
|
||||||
var response = await client.GetAsync("/woof.json");
|
{
|
||||||
response.EnsureSuccessStatusCode();
|
client.BaseAddress = new Uri("http://random.dog");
|
||||||
|
var response = await client.GetAsync("/woof.json");
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||||
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
|
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
|
||||||
await ReplyAsync(dogFile.url);
|
await ReplyAsync(dogFile.url);
|
||||||
}
|
}
|
||||||
catch (HttpRequestException e)
|
catch (HttpRequestException e)
|
||||||
{
|
{
|
||||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,13 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class EightBall : ModuleBase
|
public class EightBall : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly Random rnd;
|
private readonly Random _rnd;
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
public EightBall(Random RandomClient)
|
public EightBall(Random RandomClient, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
rnd = RandomClient;
|
_rnd = RandomClient;
|
||||||
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("8ball", RunMode = RunMode.Async)]
|
[Command("8ball", RunMode = RunMode.Async)]
|
||||||
|
@ -20,32 +22,39 @@ namespace Geekbot.net.Commands
|
||||||
[Summary("Ask 8Ball a Question.")]
|
[Summary("Ask 8Ball a Question.")]
|
||||||
public async Task Ball([Remainder] [Summary("Question")] string echo)
|
public async Task Ball([Remainder] [Summary("Question")] string echo)
|
||||||
{
|
{
|
||||||
var replies = new List<string>
|
try
|
||||||
{
|
{
|
||||||
"It is certain",
|
var replies = new List<string>
|
||||||
"It is decidedly so",
|
{
|
||||||
"Without a doubt",
|
"It is certain",
|
||||||
"Yes, definitely",
|
"It is decidedly so",
|
||||||
"You may rely on it",
|
"Without a doubt",
|
||||||
"As I see it, yes",
|
"Yes, definitely",
|
||||||
"Most likely",
|
"You may rely on it",
|
||||||
"Outlook good",
|
"As I see it, yes",
|
||||||
"Yes",
|
"Most likely",
|
||||||
"Signs point to yes",
|
"Outlook good",
|
||||||
"Reply hazy try again",
|
"Yes",
|
||||||
"Ask again later",
|
"Signs point to yes",
|
||||||
"Better not tell you now",
|
"Reply hazy try again",
|
||||||
"Cannot predict now",
|
"Ask again later",
|
||||||
"Concentrate and ask again",
|
"Better not tell you now",
|
||||||
"Don't count on it",
|
"Cannot predict now",
|
||||||
"My reply is no",
|
"Concentrate and ask again",
|
||||||
"My sources say no",
|
"Don't count on it",
|
||||||
"Outlook not so good",
|
"My reply is no",
|
||||||
"Very doubtful"
|
"My sources say no",
|
||||||
};
|
"Outlook not so good",
|
||||||
|
"Very doubtful"
|
||||||
|
};
|
||||||
|
|
||||||
var answer = rnd.Next(replies.Count);
|
var answer = _rnd.Next(replies.Count);
|
||||||
await ReplyAsync(replies[answer]);
|
await ReplyAsync(replies[answer]);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@ namespace Geekbot.net.Commands
|
||||||
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
||||||
|
|
||||||
var messages = _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
var messages = _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
||||||
var level = _levelCalc.GetLevelAtExperience((int) messages);
|
var level = _levelCalc.GetLevel((int) messages);
|
||||||
|
|
||||||
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
||||||
eb.AddInlineField("Level", level)
|
eb.AddInlineField("Level", level)
|
||||||
|
|
|
@ -26,22 +26,7 @@ namespace Geekbot.net.Commands
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
// sb.AppendLine("```");
|
|
||||||
// sb.AppendLine("**Geekbot Command list**");
|
|
||||||
// sb.AppendLine("");
|
|
||||||
// sb.AppendLine(tp("Name", 15) + tp("Parameters", 19) + "Description");
|
|
||||||
// foreach (var cmd in _commands.Commands)
|
|
||||||
// {
|
|
||||||
// var param = string.Join(", !", cmd.Aliases);
|
|
||||||
// if (!param.Contains("admin"))
|
|
||||||
// if (cmd.Parameters.Any())
|
|
||||||
// sb.AppendLine(tp(param, 15) +
|
|
||||||
// tp(string.Join(" ", cmd.Parameters.Select(e => e.Summary)), 19) +
|
|
||||||
// cmd.Summary);
|
|
||||||
// else
|
|
||||||
// sb.AppendLine(tp(param, 34) + cmd.Summary);
|
|
||||||
// }
|
|
||||||
// sb.AppendLine("```");
|
|
||||||
sb.AppendLine("For a list of all commands, please visit the following page");
|
sb.AppendLine("For a list of all commands, please visit the following page");
|
||||||
sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands");
|
sb.AppendLine("https://geekbot.pizzaandcoffee.rocks/commands");
|
||||||
var dm = await Context.User.GetOrCreateDMChannelAsync();
|
var dm = await Context.User.GetOrCreateDMChannelAsync();
|
||||||
|
@ -52,11 +37,5 @@ namespace Geekbot.net.Commands
|
||||||
_errorHandler.HandleCommandException(e, Context);
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table Padding, short function name because of many usages
|
|
||||||
private string tp(string text, int shouldHave)
|
|
||||||
{
|
|
||||||
return text.PadRight(shouldHave);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Threading.Tasks;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
|
@ -7,14 +8,28 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Say : ModuleBase
|
public class Say : ModuleBase
|
||||||
{
|
{
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
|
public Say(IErrorHandler errorHandler)
|
||||||
|
{
|
||||||
|
_errorHandler = errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
[RequireUserPermission(GuildPermission.Administrator)]
|
[RequireUserPermission(GuildPermission.Administrator)]
|
||||||
[Command("say", RunMode = RunMode.Async)]
|
[Command("say", RunMode = RunMode.Async)]
|
||||||
[Remarks(CommandCategories.Admin)]
|
[Remarks(CommandCategories.Admin)]
|
||||||
[Summary("Say Something.")]
|
[Summary("Say Something.")]
|
||||||
public async Task Echo([Remainder] [Summary("What?")] string echo)
|
public async Task Echo([Remainder] [Summary("What?")] string echo)
|
||||||
{
|
{
|
||||||
await Context.Message.DeleteAsync();
|
try
|
||||||
await ReplyAsync(echo);
|
{
|
||||||
|
await Context.Message.DeleteAsync();
|
||||||
|
await ReplyAsync(echo);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,13 +9,15 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Ship : ModuleBase
|
public class Ship : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IDatabase redis;
|
private readonly IDatabase _redis;
|
||||||
private readonly Random rnd;
|
private readonly Random _rnd;
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
public Ship(IDatabase redis, Random RandomClient)
|
public Ship(IDatabase redis, Random randomClient, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
this.redis = redis;
|
_redis = redis;
|
||||||
rnd = RandomClient;
|
_rnd = randomClient;
|
||||||
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("Ship", RunMode = RunMode.Async)]
|
[Command("Ship", RunMode = RunMode.Async)]
|
||||||
|
@ -23,29 +25,35 @@ namespace Geekbot.net.Commands
|
||||||
[Summary("Ask the Shipping meter")]
|
[Summary("Ask the Shipping meter")]
|
||||||
public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2)
|
public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2)
|
||||||
{
|
{
|
||||||
// Create a String
|
try
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
shippingRate = rnd.Next(1, 100);
|
var dbstring = "";
|
||||||
redis.HashSet($"{Context.Guild.Id}:Ships", dbstring, shippingRate);
|
if (user1.Id > user2.Id)
|
||||||
}
|
dbstring = $"{user1.Id}-{user2.Id}";
|
||||||
else
|
else
|
||||||
{
|
dbstring = $"{user2.Id}-{user1.Id}";
|
||||||
shippingRate = int.Parse(dbval.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
var reply = ":heartpulse: **Matchmaking** :heartpulse:\r\n";
|
var dbval = _redis.HashGet($"{Context.Guild.Id}:Ships", dbstring);
|
||||||
reply = reply + $":two_hearts: {user1.Mention} :heart: {user2.Mention} :two_hearts:\r\n";
|
var shippingRate = 0;
|
||||||
reply = reply + $"0% [{BlockCounter(shippingRate)}] 100% - {DeterminateSuccess(shippingRate)}";
|
if (dbval.IsNullOrEmpty)
|
||||||
await ReplyAsync(reply);
|
{
|
||||||
|
shippingRate = _rnd.Next(1, 100);
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string DeterminateSuccess(int rate)
|
private string DeterminateSuccess(int rate)
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace Geekbot.net.Commands
|
||||||
|
|
||||||
var messages = (int) _redis.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.ToString());
|
var messages = (int) _redis.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.ToString());
|
||||||
var guildMessages = (int) _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
var guildMessages = (int) _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
||||||
var level = _levelCalc.GetLevelAtExperience(messages);
|
var level = _levelCalc.GetLevel(messages);
|
||||||
|
|
||||||
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
var percent = Math.Round((double) (100 * messages) / guildMessages, 2);
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,13 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Youtube : ModuleBase
|
public class Youtube : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IDatabase redis;
|
private readonly IDatabase _redis;
|
||||||
|
private readonly IErrorHandler _errorHandler;
|
||||||
|
|
||||||
public Youtube(IDatabase redis)
|
public Youtube(IDatabase redis, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
this.redis = redis;
|
_redis = redis;
|
||||||
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("yt", RunMode = RunMode.Async)]
|
[Command("yt", RunMode = RunMode.Async)]
|
||||||
|
@ -22,7 +24,7 @@ namespace Geekbot.net.Commands
|
||||||
[Summary("Search for something on youtube.")]
|
[Summary("Search for something on youtube.")]
|
||||||
public async Task Yt([Remainder] [Summary("Title")] string searchQuery)
|
public async Task Yt([Remainder] [Summary("Title")] string searchQuery)
|
||||||
{
|
{
|
||||||
var key = redis.StringGet("youtubeKey");
|
var key = _redis.StringGet("youtubeKey");
|
||||||
if (key.IsNullOrEmpty)
|
if (key.IsNullOrEmpty)
|
||||||
{
|
{
|
||||||
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||||
|
@ -50,11 +52,7 @@ namespace Geekbot.net.Commands
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
await ReplyAsync("Something went wrong... informing my senpai...");
|
_errorHandler.HandleCommandException(e, Context);
|
||||||
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(redis.StringGet("botOwner"))).Result;
|
|
||||||
var dm = await botOwner.GetOrCreateDMChannelAsync();
|
|
||||||
await dm.SendMessageAsync(
|
|
||||||
$"Something went wrong while getting a video from youtube:\r\n```\r\n{e.Message}\r\n```");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1-dev-00757" />
|
||||||
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
|
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
|
||||||
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
|
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.SentryIO" Version="1.0.3" />
|
||||||
<PackageReference Include="StackExchange.Redis">
|
<PackageReference Include="StackExchange.Redis">
|
||||||
<Version>1.2.6</Version>
|
<Version>1.2.6</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|
|
@ -78,17 +78,25 @@ namespace Geekbot.net
|
||||||
|
|
||||||
public Task UserJoined(SocketGuildUser user)
|
public Task UserJoined(SocketGuildUser user)
|
||||||
{
|
{
|
||||||
if (!user.IsBot)
|
try
|
||||||
{
|
{
|
||||||
var message = _redis.HashGet($"{user.Guild.Id}:Settings", "WelcomeMsg");
|
if (!user.IsBot)
|
||||||
if (!message.IsNullOrEmpty)
|
|
||||||
{
|
{
|
||||||
message = message.ToString().Replace("$user", user.Mention);
|
var message = _redis.HashGet($"{user.Guild.Id}:Settings", "WelcomeMsg");
|
||||||
user.Guild.DefaultChannel.SendMessageAsync(message);
|
if (!message.IsNullOrEmpty)
|
||||||
|
{
|
||||||
|
message = message.ToString().Replace("$user", user.Mention);
|
||||||
|
user.Guild.DefaultChannel.SendMessageAsync(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
_userRepository.Update(user);
|
||||||
|
_logger.Information(
|
||||||
|
$"[Geekbot] {user.Id} ({user.Username}) joined {user.Guild.Id} ({user.Guild.Name})");
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(e, "[Geekbot] Failed to send welcome message");
|
||||||
}
|
}
|
||||||
_userRepository.Update(user);
|
|
||||||
_logger.Information($"[Geekbot] {user.Id} ({user.Username}) joined {user.Guild.Id} ({user.Guild.Name})");
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Geekbot.net.Lib
|
||||||
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:")
|
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:")
|
||||||
{
|
{
|
||||||
var errorMsg =
|
var errorMsg =
|
||||||
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\"";
|
$"Error Occured while executing \"{Context.Message.Content}\", executed by \"{Context.User.Username}\" in \"{Context.Guild.Name}/{Context.Channel.Name}\"";
|
||||||
_logger.Error(e, errorMsg);
|
_logger.Error(e, errorMsg);
|
||||||
if (!string.IsNullOrEmpty(errorMessage))
|
if (!string.IsNullOrEmpty(errorMessage))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
{
|
{
|
||||||
|
@ -19,12 +20,12 @@ namespace Geekbot.net.Lib
|
||||||
_levels = levels.ToArray();
|
_levels = levels.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetLevelAtExperience(int experience)
|
public int GetLevel(int messages)
|
||||||
{
|
{
|
||||||
var returnVal = 1;
|
var returnVal = 1;
|
||||||
foreach (var level in _levels)
|
foreach (var level in _levels)
|
||||||
{
|
{
|
||||||
if (level > experience) break;
|
if (level > messages) break;
|
||||||
returnVal++;
|
returnVal++;
|
||||||
}
|
}
|
||||||
return returnVal;
|
return returnVal;
|
||||||
|
@ -33,6 +34,6 @@ namespace Geekbot.net.Lib
|
||||||
|
|
||||||
public interface ILevelCalc
|
public interface ILevelCalc
|
||||||
{
|
{
|
||||||
int GetLevelAtExperience(int experience);
|
int GetLevel(int experience);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
using Serilog;
|
using System;
|
||||||
|
using Serilog;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib
|
namespace Geekbot.net.Lib
|
||||||
|
@ -10,6 +11,13 @@ namespace Geekbot.net.Lib
|
||||||
var loggerCreation = new LoggerConfiguration()
|
var loggerCreation = new LoggerConfiguration()
|
||||||
.WriteTo.LiterateConsole()
|
.WriteTo.LiterateConsole()
|
||||||
.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true);
|
.WriteTo.RollingFile("Logs/geekbot-{Date}.txt", shared: true);
|
||||||
|
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY");
|
||||||
|
if (!string.IsNullOrEmpty(sentryDsn))
|
||||||
|
{
|
||||||
|
loggerCreation.WriteTo.SentryIO(sentryDsn)
|
||||||
|
.Enrich.FromLogContext();
|
||||||
|
Console.WriteLine($"Logging to Sentry Enabled: {sentryDsn}");
|
||||||
|
}
|
||||||
if (args.Contains("--verbose"))
|
if (args.Contains("--verbose"))
|
||||||
{
|
{
|
||||||
loggerCreation.MinimumLevel.Verbose();
|
loggerCreation.MinimumLevel.Verbose();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
@ -32,7 +33,6 @@ namespace Geekbot.net
|
||||||
|
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var logger = LoggerFactory.createLogger(args);
|
|
||||||
var logo = new StringBuilder();
|
var logo = new StringBuilder();
|
||||||
logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____");
|
logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||||
logo.AppendLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
logo.AppendLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||||
|
@ -41,8 +41,16 @@ namespace Geekbot.net
|
||||||
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||||
logo.AppendLine("=========================================");
|
logo.AppendLine("=========================================");
|
||||||
Console.WriteLine(logo.ToString());
|
Console.WriteLine(logo.ToString());
|
||||||
|
var logger = LoggerFactory.createLogger(args);
|
||||||
logger.Information("[Geekbot] Starting...");
|
logger.Information("[Geekbot] Starting...");
|
||||||
new Program().MainAsync(args, logger).GetAwaiter().GetResult();
|
try
|
||||||
|
{
|
||||||
|
new Program().MainAsync(args, logger).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Fatal(e, "[Geekbot] RIP");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MainAsync(string[] args, ILogger logger)
|
private async Task MainAsync(string[] args, ILogger logger)
|
||||||
|
|
Loading…
Reference in a new issue