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
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Cat(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("cat", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Return a random image of a cat.")]
|
||||
public async Task Say()
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.BaseAddress = new Uri("http://random.cat");
|
||||
var response = await client.GetAsync("/meow.php");
|
||||
response.EnsureSuccessStatusCode();
|
||||
try
|
||||
{
|
||||
client.BaseAddress = new Uri("http://random.cat");
|
||||
var response = await client.GetAsync("/meow.php");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
|
||||
await ReplyAsync(catFile.file);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog cought the cat (error occured)\r\n{e.Message}");
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
|
||||
await ReplyAsync(catFile.file);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
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 Geekbot.net.Lib;
|
||||
using Geekbot.net.Lib.Media;
|
||||
using Serilog;
|
||||
|
||||
namespace Geekbot.net.Commands
|
||||
{
|
||||
public class CheckEm : ModuleBase
|
||||
{
|
||||
private readonly IMediaProvider checkEmImages;
|
||||
private readonly Random rnd;
|
||||
private readonly ILogger logger;
|
||||
private readonly IErrorHandler errorHandler;
|
||||
private readonly IMediaProvider _checkEmImages;
|
||||
private readonly Random _rnd;
|
||||
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;
|
||||
this.checkEmImages = mediaProvider;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
_rnd = RandomClient;
|
||||
_checkEmImages = mediaProvider;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("checkem", RunMode = RunMode.Async)]
|
||||
|
@ -31,7 +28,7 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
try
|
||||
{
|
||||
var number = rnd.Next(10000000, 99999999);
|
||||
var number = _rnd.Next(10000000, 99999999);
|
||||
var dubtriqua = "";
|
||||
|
||||
var ns = GetIntArray(number);
|
||||
|
@ -51,13 +48,13 @@ namespace Geekbot.net.Commands
|
|||
sb.AppendLine($"**{number}**");
|
||||
if (!string.IsNullOrEmpty(dubtriqua))
|
||||
sb.AppendLine($":tada: {dubtriqua} :tada:");
|
||||
sb.AppendLine(checkEmImages.getCheckem());
|
||||
sb.AppendLine(_checkEmImages.getCheckem());
|
||||
|
||||
await ReplyAsync(sb.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorHandler.HandleCommandException(e, Context);
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,13 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
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)]
|
||||
|
@ -19,9 +21,16 @@ namespace Geekbot.net.Commands
|
|||
[Summary("Let the bot choose for you, seperate options with a semicolon.")]
|
||||
public async Task Command([Remainder] [Summary("option1;option2")] string choices)
|
||||
{
|
||||
var choicesArray = choices.Split(';');
|
||||
var choice = rnd.Next(choicesArray.Length);
|
||||
await ReplyAsync($"I choose **{choicesArray[choice]}**");
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
private readonly ILogger logger;
|
||||
private readonly IErrorHandler errorHandler;
|
||||
private readonly IDatabase _redis;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Counters(IDatabase redis, ILogger logger, IErrorHandler errorHandler)
|
||||
public Counters(IDatabase redis, IErrorHandler errorHandler)
|
||||
{
|
||||
this.redis = redis;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
_redis = redis;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("good", RunMode = RunMode.Async)]
|
||||
|
@ -28,7 +26,7 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
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());
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
|
@ -41,8 +39,8 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
var newKarma = redis.HashIncrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||
redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||
var newKarma = _redis.HashIncrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||
_redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString("u"))});
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
|
@ -60,7 +58,7 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorHandler.HandleCommandException(e, Context);
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +69,7 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
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());
|
||||
if (user.Id == Context.User.Id)
|
||||
{
|
||||
|
@ -84,8 +82,8 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
var newKarma = redis.HashDecrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||
redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||
var newKarma = _redis.HashDecrement($"{Context.Guild.Id}:Karma", user.Id.ToString());
|
||||
_redis.HashSet($"{Context.Guild.Id}:KarmaTimeout",
|
||||
new HashEntry[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString())});
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
|
@ -103,7 +101,7 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
errorHandler.HandleCommandException(e, Context);
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,28 +9,42 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
public class Dog : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Dog(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("dog", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Return a random image of a dog.")]
|
||||
public async Task Say()
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
try
|
||||
{
|
||||
try
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.BaseAddress = new Uri("http://random.dog");
|
||||
var response = await client.GetAsync("/woof.json");
|
||||
response.EnsureSuccessStatusCode();
|
||||
try
|
||||
{
|
||||
client.BaseAddress = new Uri("http://random.dog");
|
||||
var response = await client.GetAsync("/woof.json");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
|
||||
await ReplyAsync(dogFile.url);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
await ReplyAsync($"Seems like the dog got lost (error occured)\r\n{e.Message}");
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
|
||||
await ReplyAsync(dogFile.url);
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
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
|
||||
{
|
||||
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)]
|
||||
|
@ -20,32 +22,39 @@ namespace Geekbot.net.Commands
|
|||
[Summary("Ask 8Ball a Question.")]
|
||||
public async Task Ball([Remainder] [Summary("Question")] string echo)
|
||||
{
|
||||
var replies = new List<string>
|
||||
try
|
||||
{
|
||||
"It is certain",
|
||||
"It is decidedly so",
|
||||
"Without a doubt",
|
||||
"Yes, definitely",
|
||||
"You may rely on it",
|
||||
"As I see it, yes",
|
||||
"Most likely",
|
||||
"Outlook good",
|
||||
"Yes",
|
||||
"Signs point to yes",
|
||||
"Reply hazy try again",
|
||||
"Ask again later",
|
||||
"Better not tell you now",
|
||||
"Cannot predict now",
|
||||
"Concentrate and ask again",
|
||||
"Don't count on it",
|
||||
"My reply is no",
|
||||
"My sources say no",
|
||||
"Outlook not so good",
|
||||
"Very doubtful"
|
||||
};
|
||||
var replies = new List<string>
|
||||
{
|
||||
"It is certain",
|
||||
"It is decidedly so",
|
||||
"Without a doubt",
|
||||
"Yes, definitely",
|
||||
"You may rely on it",
|
||||
"As I see it, yes",
|
||||
"Most likely",
|
||||
"Outlook good",
|
||||
"Yes",
|
||||
"Signs point to yes",
|
||||
"Reply hazy try again",
|
||||
"Ask again later",
|
||||
"Better not tell you now",
|
||||
"Cannot predict now",
|
||||
"Concentrate and ask again",
|
||||
"Don't count on it",
|
||||
"My reply is no",
|
||||
"My sources say no",
|
||||
"Outlook not so good",
|
||||
"Very doubtful"
|
||||
};
|
||||
|
||||
var answer = rnd.Next(replies.Count);
|
||||
await ReplyAsync(replies[answer]);
|
||||
var answer = _rnd.Next(replies.Count);
|
||||
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 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.AddInlineField("Level", level)
|
||||
|
|
|
@ -26,22 +26,7 @@ namespace Geekbot.net.Commands
|
|||
try
|
||||
{
|
||||
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("https://geekbot.pizzaandcoffee.rocks/commands");
|
||||
var dm = await Context.User.GetOrCreateDMChannelAsync();
|
||||
|
@ -52,11 +37,5 @@ namespace Geekbot.net.Commands
|
|||
_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.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
@ -7,14 +8,28 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
public class Say : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Say(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[RequireUserPermission(GuildPermission.Administrator)]
|
||||
[Command("say", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Admin)]
|
||||
[Summary("Say Something.")]
|
||||
public async Task Echo([Remainder] [Summary("What?")] string echo)
|
||||
{
|
||||
await Context.Message.DeleteAsync();
|
||||
await ReplyAsync(echo);
|
||||
try
|
||||
{
|
||||
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
|
||||
{
|
||||
private readonly IDatabase redis;
|
||||
private readonly Random rnd;
|
||||
private readonly IDatabase _redis;
|
||||
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;
|
||||
rnd = RandomClient;
|
||||
_redis = redis;
|
||||
_rnd = randomClient;
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("Ship", RunMode = RunMode.Async)]
|
||||
|
@ -23,29 +25,35 @@ namespace Geekbot.net.Commands
|
|||
[Summary("Ask the Shipping meter")]
|
||||
public async Task Command([Summary("@User1")] IUser user1, [Summary("@User2")] IUser user2)
|
||||
{
|
||||
// Create a String
|
||||
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)
|
||||
try
|
||||
{
|
||||
shippingRate = rnd.Next(1, 100);
|
||||
redis.HashSet($"{Context.Guild.Id}:Ships", dbstring, shippingRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
shippingRate = int.Parse(dbval.ToString());
|
||||
}
|
||||
var dbstring = "";
|
||||
if (user1.Id > user2.Id)
|
||||
dbstring = $"{user1.Id}-{user2.Id}";
|
||||
else
|
||||
dbstring = $"{user2.Id}-{user1.Id}";
|
||||
|
||||
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);
|
||||
var dbval = _redis.HashGet($"{Context.Guild.Id}:Ships", dbstring);
|
||||
var shippingRate = 0;
|
||||
if (dbval.IsNullOrEmpty)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Geekbot.net.Commands
|
|||
|
||||
var messages = (int) _redis.HashGet($"{Context.Guild.Id}:Messages", userInfo.Id.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);
|
||||
|
||||
|
|
|
@ -10,11 +10,13 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
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)]
|
||||
|
@ -22,7 +24,7 @@ namespace Geekbot.net.Commands
|
|||
[Summary("Search for something on youtube.")]
|
||||
public async Task Yt([Remainder] [Summary("Title")] string searchQuery)
|
||||
{
|
||||
var key = redis.StringGet("youtubeKey");
|
||||
var key = _redis.StringGet("youtubeKey");
|
||||
if (key.IsNullOrEmpty)
|
||||
{
|
||||
await ReplyAsync("No youtube key set, please tell my senpai to set one");
|
||||
|
@ -50,11 +52,7 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await ReplyAsync("Something went wrong... informing my senpai...");
|
||||
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```");
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<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.RollingFile" Version="3.3.1-dev-00771" />
|
||||
<PackageReference Include="Serilog.Sinks.SentryIO" Version="1.0.3" />
|
||||
<PackageReference Include="StackExchange.Redis">
|
||||
<Version>1.2.6</Version>
|
||||
</PackageReference>
|
||||
|
|
|
@ -78,17 +78,25 @@ namespace Geekbot.net
|
|||
|
||||
public Task UserJoined(SocketGuildUser user)
|
||||
{
|
||||
if (!user.IsBot)
|
||||
try
|
||||
{
|
||||
var message = _redis.HashGet($"{user.Guild.Id}:Settings", "WelcomeMsg");
|
||||
if (!message.IsNullOrEmpty)
|
||||
if (!user.IsBot)
|
||||
{
|
||||
message = message.ToString().Replace("$user", user.Mention);
|
||||
user.Guild.DefaultChannel.SendMessageAsync(message);
|
||||
var message = _redis.HashGet($"{user.Guild.Id}:Settings", "WelcomeMsg");
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Geekbot.net.Lib
|
|||
public void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "Something went wrong :confused:")
|
||||
{
|
||||
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);
|
||||
if (!string.IsNullOrEmpty(errorMessage))
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
|
@ -19,12 +20,12 @@ namespace Geekbot.net.Lib
|
|||
_levels = levels.ToArray();
|
||||
}
|
||||
|
||||
public int GetLevelAtExperience(int experience)
|
||||
public int GetLevel(int messages)
|
||||
{
|
||||
var returnVal = 1;
|
||||
foreach (var level in _levels)
|
||||
{
|
||||
if (level > experience) break;
|
||||
if (level > messages) break;
|
||||
returnVal++;
|
||||
}
|
||||
return returnVal;
|
||||
|
@ -33,6 +34,6 @@ namespace Geekbot.net.Lib
|
|||
|
||||
public interface ILevelCalc
|
||||
{
|
||||
int GetLevelAtExperience(int experience);
|
||||
int GetLevel(int experience);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Serilog;
|
||||
using System;
|
||||
using Serilog;
|
||||
using System.Linq;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
|
@ -10,6 +11,13 @@ namespace Geekbot.net.Lib
|
|||
var loggerCreation = new LoggerConfiguration()
|
||||
.WriteTo.LiterateConsole()
|
||||
.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"))
|
||||
{
|
||||
loggerCreation.MinimumLevel.Verbose();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -32,7 +33,6 @@ namespace Geekbot.net
|
|||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var logger = LoggerFactory.createLogger(args);
|
||||
var logo = new StringBuilder();
|
||||
logo.AppendLine(@" ____ _____ _____ _ ______ ___ _____");
|
||||
logo.AppendLine(@" / ___| ____| ____| |/ / __ ) / _ \\_ _|");
|
||||
|
@ -41,8 +41,16 @@ namespace Geekbot.net
|
|||
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||
logo.AppendLine("=========================================");
|
||||
Console.WriteLine(logo.ToString());
|
||||
var logger = LoggerFactory.createLogger(args);
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue