Code Cleanup, thanks resharper

This commit is contained in:
runebaas 2017-12-29 01:53:50 +01:00
parent 00035ac4b1
commit 813698394a
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
34 changed files with 298 additions and 325 deletions

View file

@ -13,12 +13,13 @@ namespace Geekbot.net.Commands
[RequireUserPermission(GuildPermission.Administrator)]
public class Admin : ModuleBase
{
private readonly IDatabase _redis;
private readonly DiscordSocketClient _client;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly ITranslationHandler _translation;
public Admin(IDatabase redis, DiscordSocketClient client, IErrorHandler errorHandler, ITranslationHandler translationHandler)
public Admin(IDatabase redis, DiscordSocketClient client, IErrorHandler errorHandler,
ITranslationHandler translationHandler)
{
_redis = redis;
_client = client;
@ -31,7 +32,7 @@ namespace Geekbot.net.Commands
[Summary("Set a Welcome Message (use '$user' to mention the new joined user).")]
public async Task SetWelcomeMessage([Remainder] [Summary("message")] string welcomeMessage)
{
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] { new HashEntry("WelcomeMsg", welcomeMessage) });
_redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("WelcomeMsg", welcomeMessage)});
var formatedMessage = welcomeMessage.Replace("$user", Context.User.Mention);
await ReplyAsync("Welcome message has been changed\r\nHere is an example of how it would look:\r\n" +
formatedMessage);
@ -49,7 +50,8 @@ namespace Geekbot.net.Commands
sb.AppendLine("- `!admin showleave true` - send message to mod channel when someone leaves");
sb.AppendLine("- `!admin showdel true` - send message to mod channel when someone deletes a message");
await channel.SendMessageAsync(sb.ToString());
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ModChannel", channel.Id.ToString())});
_redis.HashSet($"{Context.Guild.Id}:Settings",
new[] {new HashEntry("ModChannel", channel.Id.ToString())});
}
catch (Exception e)
{
@ -69,17 +71,18 @@ namespace Geekbot.net.Commands
if (enabled)
{
await modChannel.SendMessageAsync("Saved - now sending messages here when someone leaves");
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowLeave", true)});
_redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("ShowLeave", true)});
}
else
{
await modChannel.SendMessageAsync("Saved - stopping sending messages here when someone leaves");
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowLeave", false)});
_redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("ShowLeave", false)});
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
_errorHandler.HandleCommandException(e, Context,
"Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
}
}
@ -94,18 +97,21 @@ namespace Geekbot.net.Commands
var modChannel = (ISocketMessageChannel) _client.GetChannel(modChannelId);
if (enabled)
{
await modChannel.SendMessageAsync("Saved - now sending messages here when someone deletes a message");
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowDelete", true)});
await modChannel.SendMessageAsync(
"Saved - now sending messages here when someone deletes a message");
_redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("ShowDelete", true)});
}
else
{
await modChannel.SendMessageAsync("Saved - stopping sending messages here when someone deletes a message");
_redis.HashSet($"{Context.Guild.Id}:Settings", new HashEntry[] {new HashEntry("ShowDelete", false)});
await modChannel.SendMessageAsync(
"Saved - stopping sending messages here when someone deletes a message");
_redis.HashSet($"{Context.Guild.Id}:Settings", new[] {new HashEntry("ShowDelete", false)});
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, "Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
_errorHandler.HandleCommandException(e, Context,
"Modchannel doesn't seem to exist, please set one with `!admin modchannel [channelId]`");
}
}
@ -124,6 +130,7 @@ namespace Geekbot.net.Commands
await ReplyAsync(trans["NewLanguageSet"]);
return;
}
await ReplyAsync(
$"That doesn't seem to be a supported language\r\nSupported Languages are {string.Join(", ", _translation.GetSupportedLanguages())}");
}

View file

@ -18,14 +18,11 @@ namespace Geekbot.net.Commands
[Command("avatar", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Get someones avatar")]
public async Task getAvatar([Remainder, Summary("user")] IUser user = null)
public async Task getAvatar([Remainder] [Summary("user")] IUser user = null)
{
try
{
if (user == null)
{
user = Context.User;
}
if (user == null) user = Context.User;
var url = user.GetAvatarUrl().Replace("128", "1024");
await ReplyAsync(url);
}

View file

@ -2,7 +2,6 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using StackExchange.Redis;
namespace Geekbot.net.Commands
{
@ -10,13 +9,11 @@ namespace Geekbot.net.Commands
public class BattleTag : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly IUserRepository _userRepository;
public BattleTag(IErrorHandler errorHandler, IDatabase redis, IUserRepository userRepository)
public BattleTag(IErrorHandler errorHandler, IUserRepository userRepository)
{
_errorHandler = errorHandler;
_redis = redis;
_userRepository = userRepository;
}
@ -29,15 +26,10 @@ namespace Geekbot.net.Commands
{
var tag = _userRepository.getUserSetting(Context.User.Id, "BattleTag");
if (!string.IsNullOrEmpty(tag))
{
await ReplyAsync($"Your BattleTag is {tag}");
}
else
{
await ReplyAsync("You haven't set your BattleTag, set it with `!battletag user#1234`");
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
@ -71,7 +63,7 @@ namespace Geekbot.net.Commands
{
var splited = tag.Split("#");
if (splited.Length != 2) return false;
if (!int.TryParse(splited[1], out int discriminator)) return false;
if (!int.TryParse(splited[1], out var discriminator)) return false;
if (splited[1].Length == 4 || splited[1].Length == 5) return true;
return false;
}

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
@ -15,8 +14,8 @@ namespace Geekbot.net.Commands
{
public class Changelog : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly DiscordSocketClient _client;
private readonly IErrorHandler _errorHandler;
public Changelog(IErrorHandler errorHandler, DiscordSocketClient client)
{
@ -35,7 +34,8 @@ namespace Geekbot.net.Commands
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.github.com");
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "http://developer.github.com/v3/#user-agent-required");
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
"http://developer.github.com/v3/#user-agent-required");
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
response.EnsureSuccessStatusCode();
@ -43,7 +43,7 @@ namespace Geekbot.net.Commands
var commits = JsonConvert.DeserializeObject<List<Commit>>(stringResponse);
var eb = new EmbedBuilder();
eb.WithColor(new Color(143, 165, 102));
eb.WithAuthor(new EmbedAuthorBuilder()
eb.WithAuthor(new EmbedAuthorBuilder
{
IconUrl = _client.CurrentUser.GetAvatarUrl(),
Name = "Latest Updates",
@ -51,11 +51,9 @@ namespace Geekbot.net.Commands
});
var sb = new StringBuilder();
foreach (var commit in commits.Take(10))
{
sb.AppendLine($"- {commit.commit.message} ({commit.commit.author.date:yyyy-MM-dd})");
}
eb.Description = sb.ToString();
eb.WithFooter(new EmbedFooterBuilder()
eb.WithFooter(new EmbedFooterBuilder
{
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
});

View file

@ -11,8 +11,8 @@ namespace Geekbot.net.Commands
public class CheckEm : ModuleBase
{
private readonly IMediaProvider _checkEmImages;
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
private readonly Random _rnd;
public CheckEm(Random RandomClient, IMediaProvider mediaProvider, IErrorHandler errorHandler)
{
@ -66,6 +66,7 @@ namespace Geekbot.net.Commands
listOfInts.Add(num % 10);
num = num / 10;
}
listOfInts.Reverse();
return listOfInts.ToArray();
}

View file

@ -7,8 +7,8 @@ namespace Geekbot.net.Commands
{
public class Choose : ModuleBase
{
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
private readonly Random _rnd;
private readonly ITranslationHandler _translation;
public Choose(Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
@ -21,7 +21,8 @@ namespace Geekbot.net.Commands
[Command("choose", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[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)
{
try
{

View file

@ -10,11 +10,11 @@ namespace Geekbot.net.Commands
{
public class Dice : ModuleBase
{
private readonly Random rnd;
private readonly Random _rnd;
public Dice(Random RandomClient)
{
rnd = RandomClient;
_rnd = RandomClient;
}
[Command("dice", RunMode = RunMode.Async)]
@ -39,6 +39,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can only have one mod");
return;
}
mod = dice.mod;
}
}
@ -56,6 +57,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't throw more than 20 dices");
return;
}
if (dices.Any(d => d.sides > 120))
{
await ReplyAsync("A dice can't have more than 120 sides");
@ -73,32 +75,26 @@ namespace Geekbot.net.Commands
var results = new List<int>();
for (var i = 0; i < dice.times; i++)
{
var roll = rnd.Next(1, dice.sides);
var roll = _rnd.Next(1, dice.sides);
total += roll;
results.Add(roll);
if (roll == dice.sides)
{
extraText = "**Critical Hit!**";
}
if (roll == 1)
{
extraText = "**Critical Fail!**";
}
if (roll == dice.sides) extraText = "**Critical Hit!**";
if (roll == 1) extraText = "**Critical Fail!**";
}
resultStrings.Add($"{dice.diceType} ({string.Join(",", results)})");
}
rep.Append(string.Join(" + ", resultStrings));
if (mod != 0)
{
rep.Append($" + {mod}");
total += mod;
}
rep.AppendLine();
rep.AppendLine($"**Total:** {total}");
if (extraText != "")
{
rep.AppendLine(extraText);
}
if (extraText != "") rep.AppendLine(extraText);
await ReplyAsync(rep.ToString());
}
@ -106,29 +102,25 @@ namespace Geekbot.net.Commands
{
var diceParts = dice.Split('d');
if (diceParts.Length == 2
&& int.TryParse(diceParts[0], out int times)
&& int.TryParse(diceParts[1], out int max))
{
return new DiceTypeDto()
&& int.TryParse(diceParts[0], out var times)
&& int.TryParse(diceParts[1], out var max))
return new DiceTypeDto
{
diceType = dice,
times = times,
sides = max
};
}
if (dice.Length == 1
&& int.TryParse(diceParts[0], out int mod))
{
return new DiceTypeDto()
&& int.TryParse(diceParts[0], out var mod))
return new DiceTypeDto
{
mod = mod
};
}
return new DiceTypeDto();
}
}
class DiceTypeDto
internal class DiceTypeDto
{
public string diceType { get; set; }
public int times { get; set; }

View file

@ -8,8 +8,8 @@ namespace Geekbot.net.Commands
{
public class EightBall : ModuleBase
{
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
private readonly Random _rnd;
public EightBall(Random RandomClient, IErrorHandler errorHandler)
{

View file

@ -1,7 +1,5 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
@ -9,8 +7,8 @@ namespace Geekbot.net.Commands
{
public class Emojify : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IEmojiConverter _emojiConverter;
private readonly IErrorHandler _errorHandler;
public Emojify(IErrorHandler errorHandler, IEmojiConverter emojiConverter)
{
@ -21,26 +19,19 @@ namespace Geekbot.net.Commands
[Command("emojify", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Emojify text")]
public async Task Dflt([Remainder, Summary("text")] string text)
public async Task Dflt([Remainder] [Summary("text")] string text)
{
try
{
var sb = new StringBuilder();
var emojis = _emojiConverter.textToEmoji(text);
if (emojis.Length > 1999)
{
await ReplyAsync("I can't take that much at once!");
return;
}
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
{
IconUrl = Context.User.GetAvatarUrl(),
Name = $"{Context.User.Username}#{Context.User.Discriminator}"
});
eb.WithColor(new Color(59, 136, 195));
eb.Description = emojis;
await ReplyAsync("", false, eb.Build());
await ReplyAsync($"{Context.User.Username}#{Context.User.Discriminator} said:");
await ReplyAsync(emojis);
}
catch (Exception e)
{

View file

@ -7,11 +7,11 @@ namespace Geekbot.net.Commands
{
public class Fortune : ModuleBase
{
private readonly IFortunesProvider fortunes;
private readonly IFortunesProvider _fortunes;
public Fortune(IFortunesProvider fortunes)
{
this.fortunes = fortunes;
_fortunes = fortunes;
}
[Command("fortune", RunMode = RunMode.Async)]
@ -19,7 +19,7 @@ namespace Geekbot.net.Commands
[Summary("Get a random fortune")]
public async Task GetAFortune()
{
await ReplyAsync(fortunes.GetRandomFortune());
await ReplyAsync(_fortunes.GetRandomFortune());
}
}
}

View file

@ -1,19 +0,0 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Commands
{
public class Google : ModuleBase
{
[Command("google", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Fun)]
[Summary("Google Something.")]
public async Task Eyes([Remainder, Summary("SearchText")] string searchText)
{
var url = $"http://lmgtfy.com/?q={searchText.Replace(' ', '+')}";
await ReplyAsync($"Please click here :unamused:\r\n{url}");
}
}
}

View file

@ -10,9 +10,9 @@ namespace Geekbot.net.Commands
{
public class GuildInfo : ModuleBase
{
private readonly IDatabase _redis;
private readonly ILevelCalc _levelCalc;
private readonly IErrorHandler _errorHandler;
private readonly ILevelCalc _levelCalc;
private readonly IDatabase _redis;
public GuildInfo(IDatabase redis, ILevelCalc levelCalc, IErrorHandler errorHandler)
{

View file

@ -12,10 +12,10 @@ namespace Geekbot.net.Commands
{
public class Info : ModuleBase
{
private readonly IDatabase _redis;
private readonly IErrorHandler _errorHandler;
private readonly DiscordSocketClient _client;
private readonly CommandService _commands;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
public Info(IDatabase redis, IErrorHandler errorHandler, DiscordSocketClient client, CommandService commands)
{
@ -38,7 +38,7 @@ namespace Geekbot.net.Commands
.WithIconUrl(_client.CurrentUser.GetAvatarUrl())
.WithName($"{Constants.Name} V{Constants.BotVersion}"));
var botOwner = await Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner")));
var uptime = (DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime));
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
eb.AddInlineField("Bot Name", _client.CurrentUser.Username);
eb.AddInlineField("Bot Owner", $"{botOwner.Username}#{botOwner.Discriminator}");
@ -64,7 +64,7 @@ namespace Geekbot.net.Commands
{
try
{
var uptime = (DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime));
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
await ReplyAsync($"{uptime.Days}D {uptime.Hours}H {uptime.Minutes}M {uptime.Seconds}S");
}
catch (Exception e)

View file

@ -3,18 +3,17 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Serilog;
using StackExchange.Redis;
namespace Geekbot.net.Commands
{
public class Counters : ModuleBase
public class Karma : ModuleBase
{
private readonly IDatabase _redis;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly ITranslationHandler _translation;
public Counters(IDatabase redis, IErrorHandler errorHandler, ITranslationHandler translation)
public Karma(IDatabase redis, IErrorHandler errorHandler, ITranslationHandler translation)
{
_redis = redis;
_errorHandler = errorHandler;
@ -37,13 +36,14 @@ namespace Geekbot.net.Commands
}
else if (TimeoutFinished(lastKarma))
{
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, GetTimeLeft(lastKarma)));
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username,
GetTimeLeft(lastKarma)));
}
else
{
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"))});
new[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString("u"))});
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
@ -80,13 +80,14 @@ namespace Geekbot.net.Commands
}
else if (TimeoutFinished(lastKarma))
{
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username, GetTimeLeft(lastKarma)));
await ReplyAsync(string.Format(transDict["WaitUntill"], Context.User.Username,
GetTimeLeft(lastKarma)));
}
else
{
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())});
new[] {new HashEntry(Context.User.Id.ToString(), DateTimeOffset.Now.ToString())});
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
@ -109,7 +110,8 @@ namespace Geekbot.net.Commands
private DateTimeOffset ConvertToDateTimeOffset(string dateTimeOffsetString)
{
if(string.IsNullOrEmpty(dateTimeOffsetString)) return DateTimeOffset.Now.Subtract(new TimeSpan(7, 18, 0, 0));
if (string.IsNullOrEmpty(dateTimeOffsetString))
return DateTimeOffset.Now.Subtract(new TimeSpan(7, 18, 0, 0));
return DateTimeOffset.Parse(dateTimeOffsetString);
}

View file

@ -1,24 +1,20 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using MtgApiManager.Lib.Service;
using Serilog;
namespace Geekbot.net.Commands
{
public class Magicthegathering : ModuleBase
{
private ILogger _logger;
private IErrorHandler _errorHandler;
private readonly IErrorHandler _errorHandler;
public Magicthegathering(ILogger logger, IErrorHandler errorHandler)
public Magicthegathering(IErrorHandler errorHandler)
{
_logger = logger;
_errorHandler = errorHandler;
}
@ -38,6 +34,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("I couldn't find that card...");
return;
}
var eb = new EmbedBuilder();
eb.Title = card.Name;
eb.Description = card.Type;
@ -57,7 +54,8 @@ namespace Geekbot.net.Commands
if (!string.IsNullOrEmpty(card.ManaCost)) eb.AddInlineField("Cost", card.ManaCost);
if (!string.IsNullOrEmpty(card.Rarity)) eb.AddInlineField("Rarity", card.Rarity);
if (card.Legalities != null) eb.AddField("Legality", string.Join(", ", card.Legalities.Select(e => e.Format)));
if (card.Legalities != null)
eb.AddField("Legality", string.Join(", ", card.Legalities.Select(e => e.Format)));
await ReplyAsync("", false, eb.Build());
}

View file

@ -15,12 +15,13 @@ namespace Geekbot.net.Commands
[RequireUserPermission(GuildPermission.ManageRoles)]
public class Mod : ModuleBase
{
private readonly IUserRepository _userRepository;
private readonly DiscordSocketClient _client;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly DiscordSocketClient _client;
private readonly IUserRepository _userRepository;
public Mod(IUserRepository userRepositry, IErrorHandler errorHandler, IDatabase redis, DiscordSocketClient client)
public Mod(IUserRepository userRepositry, IErrorHandler errorHandler, IDatabase redis,
DiscordSocketClient client)
{
_userRepository = userRepositry;
_errorHandler = errorHandler;
@ -38,30 +39,26 @@ namespace Geekbot.net.Commands
var userRepo = _userRepository.Get(user.Id);
var sb = new StringBuilder();
sb.AppendLine($":bust_in_silhouette: {user.Username} has been known as:");
foreach (var name in userRepo.UsedNames)
{
sb.AppendLine($"- `{name}`");
}
foreach (var name in userRepo.UsedNames) sb.AppendLine($"- `{name}`");
await ReplyAsync(sb.ToString());
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, $"I don't have enough permissions to give {user.Username} that role");
_errorHandler.HandleCommandException(e, Context,
$"I don't have enough permissions to give {user.Username} that role");
}
}
[Command("kick", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Admin)]
[Summary("Ban a user")]
public async Task kick([Summary("@user")] IUser userNormal, [Summary("reason"), Remainder] string reason = "none")
public async Task kick([Summary("@user")] IUser userNormal,
[Summary("reason")] [Remainder] string reason = "none")
{
try
{
var user = (IGuildUser)userNormal;
if (reason == "none")
{
reason = "No reason provided";
}
var user = (IGuildUser) userNormal;
if (reason == "none") reason = "No reason provided";
await user.GetOrCreateDMChannelAsync().Result.SendMessageAsync(
$"You have been kicked from {Context.Guild.Name} for the following reason: \"{reason}\"");
await user.KickAsync();

View file

@ -3,7 +3,6 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Google.Apis.Util;
using OverwatchAPI;
using OverwatchAPI.Config;
using Serilog;
@ -38,14 +37,15 @@ namespace Geekbot.net.Commands
await ReplyAsync("You have no battle Tag saved, use `!battletag`");
return;
}
var profile = await createProfile(tag);
if (profile == null)
{
await ReplyAsync("That player doesn't seem to exist");
return;
}
await ReplyAsync("", false, profile.Build());
await ReplyAsync("", false, profile.Build());
}
catch (Exception e)
{
@ -65,12 +65,14 @@ namespace Geekbot.net.Commands
await ReplyAsync("That doesn't seem to be a valid battletag...");
return;
}
var profile = await createProfile(tag);
if (profile == null)
{
await ReplyAsync("That player doesn't seem to exist");
return;
}
await ReplyAsync("", false, profile.Build());
}
catch (Exception e)
@ -92,12 +94,14 @@ namespace Geekbot.net.Commands
await ReplyAsync("This user didn't set a battletag");
return;
}
var profile = await createProfile(tag);
if (profile == null)
{
await ReplyAsync("That player doesn't seem to exist");
return;
}
await ReplyAsync("", false, profile.Build());
}
catch (Exception e)
@ -112,10 +116,7 @@ namespace Geekbot.net.Commands
using (var owClient = new OverwatchClient(owConfig))
{
var player = await owClient.GetPlayerAsync(battletag);
if (player.Username == null)
{
return null;
}
if (player.Username == null) return null;
_logger.Debug($"[OW] Username = {player.Username}");
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
@ -123,7 +124,8 @@ namespace Geekbot.net.Commands
.WithName(player.Username));
eb.Url = player.ProfileUrl;
eb.AddInlineField("Level", player.PlayerLevel);
eb.AddInlineField("Current Rank", player.CompetitiveRank > 0 ? player.CompetitiveRank.ToString() : "Unranked");
eb.AddInlineField("Current Rank",
player.CompetitiveRank > 0 ? player.CompetitiveRank.ToString() : "Unranked");
return eb;
}

View file

@ -13,13 +13,14 @@ namespace Geekbot.net.Commands
[RequireUserPermission(GuildPermission.Administrator)]
public class Owner : ModuleBase
{
private readonly IDatabase _redis;
private readonly DiscordSocketClient _client;
private readonly ILogger _logger;
private readonly IUserRepository _userRepository;
private readonly IErrorHandler _errorHandler;
private readonly ILogger _logger;
private readonly IDatabase _redis;
private readonly IUserRepository _userRepository;
public Owner(IDatabase redis, DiscordSocketClient client, ILogger logger, IUserRepository userRepositry, IErrorHandler errorHandler)
public Owner(IDatabase redis, DiscordSocketClient client, ILogger logger, IUserRepository userRepositry,
IErrorHandler errorHandler)
{
_redis = redis;
_client = client;
@ -36,7 +37,8 @@ namespace Geekbot.net.Commands
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result;
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
{
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
await ReplyAsync(
$"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
return;
}
@ -52,7 +54,8 @@ namespace Geekbot.net.Commands
var botOwner = Context.Guild.GetUserAsync(ulong.Parse(_redis.StringGet("botOwner"))).Result;
if (!Context.User.Id.ToString().Equals(botOwner.Id.ToString()))
{
await ReplyAsync($"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
await ReplyAsync(
$"Sorry, only the botowner can do this ({botOwner.Username}#{botOwner.Discriminator})");
return;
}
@ -83,6 +86,7 @@ namespace Geekbot.net.Commands
$"Sorry, only the botowner can do this");
return;
}
var success = 0;
var failed = 0;
try
@ -98,12 +102,15 @@ namespace Geekbot.net.Commands
var inc = succeded ? success++ : failed++;
}
}
_logger.Warning("[UserRepository] Finished Updating User Repositry");
await ReplyAsync($"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})");
await ReplyAsync(
$"Successfully Populated User Repository with {success} Users in {_client.Guilds.Count} Guilds (Failed: {failed})");
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context, "Couldn't complete User Repository, see console for more info");
_errorHandler.HandleCommandException(e, Context,
"Couldn't complete User Repository, see console for more info");
}
}
}

View file

@ -5,7 +5,6 @@ using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using PokeAPI;
using Serilog;
namespace Geekbot.net.Commands
{
@ -36,6 +35,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("I couldn't find that pokemon :confused:");
return;
}
var embed = await pokemonEmbedBuilder(pokemon);
await ReplyAsync("", false, embed.Build());
}
@ -52,8 +52,10 @@ namespace Geekbot.net.Commands
eb.Title = $"#{pokemon.ID} {toUpper(pokemon.Name)}";
eb.Description = species.FlavorTexts[1].FlavorText;
eb.ThumbnailUrl = pokemon.Sprites.FrontMale ?? pokemon.Sprites.FrontFemale;
eb.AddInlineField(getSingularOrPlural(pokemon.Types.Length, "Type"), string.Join(", ", pokemon.Types.Select(t => toUpper(t.Type.Name))));
eb.AddInlineField(getSingularOrPlural(pokemon.Abilities.Length, "Ability"), string.Join(", ", pokemon.Abilities.Select(t => toUpper(t.Ability.Name))));
eb.AddInlineField(getSingularOrPlural(pokemon.Types.Length, "Type"),
string.Join(", ", pokemon.Types.Select(t => toUpper(t.Type.Name))));
eb.AddInlineField(getSingularOrPlural(pokemon.Abilities.Length, "Ability"),
string.Join(", ", pokemon.Abilities.Select(t => toUpper(t.Ability.Name))));
eb.AddInlineField("Height", pokemon.Height);
eb.AddInlineField("Weight", pokemon.Mass);
return eb;
@ -61,22 +63,14 @@ namespace Geekbot.net.Commands
private string getSingularOrPlural(int lenght, string word)
{
if (lenght == 1)
{
return word;
}
return word.EndsWith("y") ? $"{word.Remove(word.Length-1)}ies" : $"{word}s";
if (lenght == 1) return word;
return word.EndsWith("y") ? $"{word.Remove(word.Length - 1)}ies" : $"{word}s";
}
private string toUpper(string s)
{
if (string.IsNullOrEmpty(s))
{
return string.Empty;
}
if (string.IsNullOrEmpty(s)) return string.Empty;
return char.ToUpper(s[0]) + s.Substring(1);
}
}
}

View file

@ -14,12 +14,13 @@ namespace Geekbot.net.Commands
[Group("poll")]
public class Poll : ModuleBase
{
private readonly IEmojiConverter _emojiConverter;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly IEmojiConverter _emojiConverter;
private readonly IUserRepository _userRepository;
public Poll(IErrorHandler errorHandler, IDatabase redis, IEmojiConverter emojiConverter, IUserRepository userRepository)
public Poll(IErrorHandler errorHandler, IDatabase redis, IEmojiConverter emojiConverter,
IUserRepository userRepository)
{
_errorHandler = errorHandler;
_redis = redis;
@ -41,6 +42,7 @@ namespace Geekbot.net.Commands
"There is no poll in this channel ongoing at the moment\r\nYou can create one with `!poll create question;option1;option2;option3`");
return;
}
await ReplyAsync("There is a poll running at the moment");
}
catch (Exception e)
@ -52,7 +54,8 @@ namespace Geekbot.net.Commands
[Command("create", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Create a poll")]
public async Task Create([Remainder, Summary("question;option1;option2")] string rawPollString)
public async Task Create([Remainder] [Summary("question;option1;option2")]
string rawPollString)
{
try
{
@ -62,6 +65,7 @@ namespace Geekbot.net.Commands
await ReplyAsync("You have not finished you last poll yet. To finish it use `!poll end`");
return;
}
var pollList = rawPollString.Split(';').ToList();
if (pollList.Count <= 2)
{
@ -88,7 +92,7 @@ namespace Geekbot.net.Commands
pollMessage.AddReactionAsync(new Emoji(_emojiConverter.numberToEmoji(i)));
i++;
});
var poll = new PollData()
var poll = new PollData
{
Creator = Context.User.Id,
MessageId = pollMessage.Id,
@ -97,7 +101,7 @@ namespace Geekbot.net.Commands
Options = pollList
};
var pollJson = JsonConvert.SerializeObject(poll);
_redis.HashSet($"{Context.Guild.Id}:Polls", new HashEntry[] {new HashEntry(Context.Channel.Id, pollJson)});
_redis.HashSet($"{Context.Guild.Id}:Polls", new[] {new HashEntry(Context.Channel.Id, pollJson)});
}
catch (Exception e)
{
@ -118,18 +122,16 @@ namespace Geekbot.net.Commands
await ReplyAsync("There is no ongoing poll at the moment");
return;
}
var results = await getPollResults(currentPoll);
var sb = new StringBuilder();
sb.AppendLine("**Poll Results**");
sb.AppendLine(currentPoll.Question);
foreach (var result in results)
{
sb.AppendLine($"{result.VoteCount} - {result.Option}");
}
foreach (var result in results) sb.AppendLine($"{result.VoteCount} - {result.Option}");
await ReplyAsync(sb.ToString());
currentPoll.IsFinshed = true;
var pollJson = JsonConvert.SerializeObject(currentPoll);
_redis.HashSet($"{Context.Guild.Id}:Polls", new HashEntry[] {new HashEntry(Context.Channel.Id, pollJson)});
_redis.HashSet($"{Context.Guild.Id}:Polls", new[] {new HashEntry(Context.Channel.Id, pollJson)});
}
catch (Exception e)
{
@ -152,14 +154,13 @@ namespace Geekbot.net.Commands
private async Task<List<PollResult>> getPollResults(PollData poll)
{
var message = (IUserMessage)(await Context.Channel.GetMessageAsync(poll.MessageId));
var message = (IUserMessage) await Context.Channel.GetMessageAsync(poll.MessageId);
var results = new List<PollResult>();
foreach (var r in message.Reactions)
{
try
{
var option = int.Parse(r.Key.Name.ToCharArray()[0].ToString());
var result = new PollResult()
var result = new PollResult
{
Option = poll.Options[option - 1],
VoteCount = r.Value.ReactionCount
@ -167,8 +168,8 @@ namespace Geekbot.net.Commands
results.Add(result);
}
catch {}
}
results.Sort((x,y) => y.VoteCount.CompareTo(x.VoteCount));
results.Sort((x, y) => y.VoteCount.CompareTo(x.VoteCount));
return results;
}

View file

@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Newtonsoft.Json;
using Serilog;
using StackExchange.Redis;
namespace Geekbot.net.Commands
@ -14,18 +12,16 @@ namespace Geekbot.net.Commands
[Group("quote")]
public class Quote : ModuleBase
{
private readonly IDatabase redis;
private readonly ILogger logger;
private readonly IErrorHandler errorHandler;
private readonly IDatabase redis;
public Quote(IDatabase redis, ILogger logger, IErrorHandler errorHandler)
public Quote(IDatabase redis, IErrorHandler errorHandler)
{
this.redis = redis;
this.logger = logger;
this.errorHandler = errorHandler;
}
[Command()]
[Command]
[Remarks(CommandCategories.Quotes)]
[Summary("Return a random quoute from the database")]
public async Task getRandomQuote()
@ -55,11 +51,13 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't save your own quotes...");
return;
}
if (user.IsBot)
{
await ReplyAsync("You can't save quotes by a bot...");
return;
}
var lastMessage = await getLastMessageByUser(user);
var quote = createQuoteObject(lastMessage);
var quoteStore = JsonConvert.SerializeObject(quote);
@ -69,7 +67,8 @@ namespace Geekbot.net.Commands
}
catch (Exception e)
{
errorHandler.HandleCommandException(e, Context, "I counldn't find a quote from that user :disappointed:");
errorHandler.HandleCommandException(e, Context,
"I counldn't find a quote from that user :disappointed:");
}
}
@ -86,21 +85,23 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't save your own quotes...");
return;
}
if (message.Author.IsBot)
{
await ReplyAsync("You can't save quotes by a bot...");
return;
}
var quote = createQuoteObject(message);
var quoteStore = JsonConvert.SerializeObject(quote);
redis.SetAdd($"{Context.Guild.Id}:Quotes", quoteStore);
var embed = quoteBuilder(quote);
await ReplyAsync("**Quote Added**", false, embed.Build());
}
catch (Exception e)
{
errorHandler.HandleCommandException(e, Context, "I couldn't find a message with that id :disappointed:");
errorHandler.HandleCommandException(e, Context,
"I couldn't find a message with that id :disappointed:");
}
}
@ -118,7 +119,8 @@ namespace Geekbot.net.Commands
}
catch (Exception e)
{
errorHandler.HandleCommandException(e, Context, "I counldn't find a quote from that user :disappointed:");
errorHandler.HandleCommandException(e, Context,
"I counldn't find a quote from that user :disappointed:");
}
}
@ -136,13 +138,14 @@ namespace Geekbot.net.Commands
}
catch (Exception e)
{
errorHandler.HandleCommandException(e, Context, "I couldn't find a message with that id :disappointed:");
errorHandler.HandleCommandException(e, Context,
"I couldn't find a message with that id :disappointed:");
}
}
private async Task<IMessage> getLastMessageByUser(IUser user)
{
Task<IEnumerable<IMessage>> list = Context.Channel.GetMessagesAsync().Flatten();
var list = Context.Channel.GetMessagesAsync().Flatten();
await list;
return list.Result
.First(msg => msg.Author.Id == user.Id
@ -159,10 +162,7 @@ namespace Geekbot.net.Commands
eb.Title = $"{user.Username} @ {quote.time.Day}.{quote.time.Month}.{quote.time.Year}";
eb.Description = quote.quote;
eb.ThumbnailUrl = user.GetAvatarUrl();
if (quote.image != null)
{
eb.ImageUrl = quote.image;
}
if (quote.image != null) eb.ImageUrl = quote.image;
return eb;
}
@ -177,7 +177,8 @@ namespace Geekbot.net.Commands
{
image = null;
}
return new QuoteObject()
return new QuoteObject
{
userId = message.Author.Id,
time = message.Timestamp.DateTime,
@ -187,7 +188,8 @@ namespace Geekbot.net.Commands
}
}
public class QuoteObject {
public class QuoteObject
{
public ulong userId { get; set; }
public string quote { get; set; }
public DateTime time { get; set; }

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Serilog;
@ -13,13 +12,14 @@ namespace Geekbot.net.Commands
{
public class Rank : ModuleBase
{
private readonly IDatabase _redis;
private readonly IEmojiConverter _emojiConverter;
private readonly IErrorHandler _errorHandler;
private readonly ILogger _logger;
private readonly IDatabase _redis;
private readonly IUserRepository _userRepository;
private readonly IEmojiConverter _emojiConverter;
public Rank(IDatabase redis, IErrorHandler errorHandler, ILogger logger, IUserRepository userRepository, IEmojiConverter emojiConverter)
public Rank(IDatabase redis, IErrorHandler errorHandler, ILogger logger, IUserRepository userRepository,
IEmojiConverter emojiConverter)
{
_redis = redis;
_errorHandler = errorHandler;
@ -31,7 +31,8 @@ namespace Geekbot.net.Commands
[Command("rank", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Statistics)]
[Summary("get user top 10 in messages or karma")]
public async Task RankCmd([Summary("type")] string typeUnformated = "messages", [Summary("amount")] int amount = 10)
public async Task RankCmd([Summary("type")] string typeUnformated = "messages",
[Summary("amount")] int amount = 10)
{
try
{
@ -64,10 +65,10 @@ namespace Geekbot.net.Commands
if (listLimiter > amount) break;
try
{
var guildUser = _userRepository.Get((ulong)user.Name);
var guildUser = _userRepository.Get((ulong) user.Name);
if (guildUser.Username != null)
{
highscoreUsers.Add(new RankUserPolyfill()
highscoreUsers.Add(new RankUserPolyfill
{
Username = guildUser.Username,
Discriminator = guildUser.Discriminator
@ -75,19 +76,19 @@ namespace Geekbot.net.Commands
}
else
{
highscoreUsers.Add(new RankUserPolyfill()
highscoreUsers.Add(new RankUserPolyfill
{
Id = user.Name
}, (int) user.Value);
failedToRetrieveUser = true;
}
listLimiter++;
}
catch (Exception e)
{
_logger.Warning(e, $"Could not retrieve user {user.Name}");
}
}
if (failedToRetrieveUser) replyBuilder.AppendLine(":warning: Couldn't get all userdata\n");
@ -121,6 +122,7 @@ namespace Geekbot.net.Commands
highscorePlace++;
}
await ReplyAsync(replyBuilder.ToString());
}
catch (Exception e)
@ -130,7 +132,7 @@ namespace Geekbot.net.Commands
}
}
class RankUserPolyfill
internal class RankUserPolyfill
{
public string Username { get; set; }
public string Discriminator { get; set; }

View file

@ -2,7 +2,6 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AngleSharp;
using Discord;
using Discord.Commands;
using Discord.Net;
@ -36,13 +35,11 @@ namespace Geekbot.net.Commands
await ReplyAsync("There are no roles configured for this server");
return;
}
var sb = new StringBuilder();
sb.AppendLine($"**Self Service Roles on {Context.Guild.Name}**");
sb.AppendLine("To get a role, use `!role name`");
foreach (var role in roles)
{
sb.AppendLine($"- {role.Name}");
}
foreach (var role in roles) sb.AppendLine($"- {role.Name}");
await ReplyAsync(sb.ToString());
}
catch (Exception e)
@ -69,16 +66,19 @@ namespace Geekbot.net.Commands
await ReplyAsync("That role doesn't seem to exist");
return;
}
if (guildUser.RoleIds.Contains(roleId))
{
await guildUser.RemoveRoleAsync(role);
await ReplyAsync($"Removed you from {role.Name}");
return;
}
await guildUser.AddRoleAsync(role);
await ReplyAsync($"Added you to {role.Name}");
return;
}
await ReplyAsync("That role doesn't seem to exist");
}
catch (HttpException e)
@ -104,16 +104,20 @@ namespace Geekbot.net.Commands
await ReplyAsync("You can't add a role that is managed by discord");
return;
}
if (role.Permissions.ManageRoles
|| role.Permissions.Administrator
|| role.Permissions.ManageGuild
|| role.Permissions.BanMembers
|| role.Permissions.KickMembers)
{
await ReplyAsync("Woah, i don't think you want to add that role to self service as it contains some dangerous permissions");
await ReplyAsync(
"Woah, i don't think you want to add that role to self service as it contains some dangerous permissions");
return;
}
_redis.HashSet($"{Context.Guild.Id}:RoleWhitelist", new HashEntry[] { new HashEntry(roleName.ToLower(), role.Id.ToString()) });
_redis.HashSet($"{Context.Guild.Id}:RoleWhitelist",
new[] {new HashEntry(roleName.ToLower(), role.Id.ToString())});
await ReplyAsync($"Added {role.Name} to the whitelist");
}
catch (Exception e)

View file

@ -8,10 +8,10 @@ namespace Geekbot.net.Commands
{
public class Roll : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly Random _rnd;
private readonly ITranslationHandler _translation;
private readonly IErrorHandler _errorHandler;
public Roll(IDatabase redis, Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
{
@ -40,7 +40,9 @@ namespace Geekbot.net.Commands
await ReplyAsync(string.Format(transDict["NoPrevGuess"], Context.Message.Author.Mention));
return;
}
_redis.HashSet($"{Context.Guild.Id}:RollsPrevious", new HashEntry[]{ new HashEntry(Context.Message.Author.Id, guess), });
_redis.HashSet($"{Context.Guild.Id}:RollsPrevious",
new[] {new HashEntry(Context.Message.Author.Id, guess)});
await ReplyAsync(string.Format(transDict["Rolled"], Context.Message.Author.Mention, number, guess));
if (guess == number)
{

View file

@ -9,9 +9,9 @@ namespace Geekbot.net.Commands
{
public class Ship : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
private readonly Random _rnd;
private readonly IErrorHandler _errorHandler;
public Ship(IDatabase redis, Random randomClient, IErrorHandler errorHandler)
{
@ -87,6 +87,7 @@ namespace Geekbot.net.Commands
{
blocks = blocks + ":black_medium_small_square:";
}
return blocks;
}
}

View file

@ -9,9 +9,9 @@ namespace Geekbot.net.Commands
{
public class Stats : ModuleBase
{
private readonly IDatabase _redis;
private readonly IErrorHandler _errorHandler;
private readonly ILevelCalc _levelCalc;
private readonly IDatabase _redis;
public Stats(IDatabase redis, IErrorHandler errorHandler, ILevelCalc levelCalc)
{
@ -49,8 +49,10 @@ namespace Geekbot.net.Commands
var karma = _redis.HashGet($"{Context.Guild.Id}:Karma", userInfo.Id.ToString());
var correctRolls = _redis.HashGet($"{Context.Guild.Id}:Rolls", userInfo.Id.ToString());
eb.AddInlineField("Discordian Since", $"{createdAt.Day}.{createdAt.Month}.{createdAt.Year} ({age} days)")
.AddInlineField("Joined Server", $"{joinedAt.Day}.{joinedAt.Month}.{joinedAt.Year} ({joinedDayAgo} days)")
eb.AddInlineField("Discordian Since",
$"{createdAt.Day}.{createdAt.Month}.{createdAt.Year} ({age} days)")
.AddInlineField("Joined Server",
$"{joinedAt.Day}.{joinedAt.Month}.{joinedAt.Year} ({joinedDayAgo} days)")
.AddInlineField("Karma", karma.ToString() ?? "0")
.AddInlineField("Level", level)
.AddInlineField("Messages Sent", messages)

View file

@ -22,7 +22,7 @@ namespace Geekbot.net.Commands
[Command("urban", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Lookup something on urban dictionary")]
public async Task urbanDefine([Remainder, Summary("word")] string word)
public async Task urbanDefine([Remainder] [Summary("word")] string word)
{
try
{
@ -39,23 +39,21 @@ namespace Geekbot.net.Commands
await ReplyAsync("That word hasn't been defined...");
return;
}
var definition = definitions.list.First(e => !string.IsNullOrWhiteSpace(e.example));
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
eb.WithAuthor(new EmbedAuthorBuilder
{
Name = definition.word,
Url = definition.permalink
});
eb.WithColor(new Color(239,255,0));
eb.WithColor(new Color(239, 255, 0));
eb.Description = definition.definition;
eb.AddField("Example", definition.example ?? "(no example given...)");
eb.AddInlineField("Upvotes", definition.thumbs_up);
eb.AddInlineField("Downvotes", definition.thumbs_down);
if (definitions.tags.Length > 0)
{
eb.AddField("Tags", string.Join(", ", definitions.tags));
}
if (definitions.tags.Length > 0) eb.AddField("Tags", string.Join(", ", definitions.tags));
await ReplyAsync("", false, eb.Build());
}

View file

@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Discord;
using Discord.Audio;
using Discord.Commands;
using Geekbot.net.Lib;
@ -9,8 +8,8 @@ namespace Geekbot.net.Commands
{
public class Voice : ModuleBase
{
private readonly IErrorHandler _errorHandler;
private readonly IAudioUtils _audioUtils;
private readonly IErrorHandler _errorHandler;
public Voice(IErrorHandler errorHandler, IAudioUtils audioUtils)
{
@ -54,6 +53,7 @@ namespace Geekbot.net.Commands
await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment");
return;
}
await audioClient.StopAsync();
await ReplyAsync("Disconnected from channel!");
}

View file

@ -10,8 +10,8 @@ namespace Geekbot.net.Commands
{
public class Youtube : ModuleBase
{
private readonly IDatabase _redis;
private readonly IErrorHandler _errorHandler;
private readonly IDatabase _redis;
public Youtube(IDatabase redis, IErrorHandler errorHandler)
{

View file

@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using System.Web;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
@ -8,8 +9,8 @@ namespace Geekbot.net.Commands
{
public class mal : ModuleBase
{
private readonly IMalClient _malClient;
private readonly IErrorHandler _errorHandler;
private readonly IMalClient _malClient;
public mal(IMalClient malClient, IErrorHandler errorHandler)
{
@ -20,7 +21,7 @@ namespace Geekbot.net.Commands
[Command("anime", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Show Info about an Anime.")]
public async Task searchAnime([Remainder, Summary("AnimeName")] string animeName)
public async Task searchAnime([Remainder] [Summary("AnimeName")] string animeName)
{
try
{
@ -31,7 +32,7 @@ namespace Geekbot.net.Commands
{
var eb = new EmbedBuilder();
var description = System.Web.HttpUtility.HtmlDecode(anime.Synopsis)
var description = HttpUtility.HtmlDecode(anime.Synopsis)
.Replace("<br />", "")
.Replace("[i]", "*")
.Replace("[/i]", "*");
@ -69,7 +70,7 @@ namespace Geekbot.net.Commands
[Command("manga", RunMode = RunMode.Async)]
[Remarks(CommandCategories.Helpers)]
[Summary("Show Info about a Manga.")]
public async Task searchManga([Remainder, Summary("MangaName")] string mangaName)
public async Task searchManga([Remainder] [Summary("MangaName")] string mangaName)
{
try
{
@ -80,7 +81,7 @@ namespace Geekbot.net.Commands
{
var eb = new EmbedBuilder();
var description = System.Web.HttpUtility.HtmlDecode(manga.Synopsis)
var description = HttpUtility.HtmlDecode(manga.Synopsis)
.Replace("<br />", "")
.Replace("[i]", "*")
.Replace("[/i]", "*");