Refaction all files into component based folders

This commit is contained in:
runebaas 2018-05-03 00:56:06 +02:00
parent 55e152f4aa
commit e3adf55742
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
102 changed files with 816 additions and 709 deletions

View file

@ -5,9 +5,11 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Admin
{
[Group("admin")]
[RequireUserPermission(GuildPermission.Administrator)]

View file

@ -5,9 +5,11 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.UserRepository;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Admin
{
[Group("mod")]
[RequireUserPermission(GuildPermission.KickMembers)]

View file

@ -4,9 +4,12 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Logger;
using Geekbot.net.Lib.UserRepository;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Admin
{
[Group("owner")]
[RequireUserPermission(GuildPermission.Administrator)]

View file

@ -6,9 +6,11 @@ using Discord;
using Discord.Commands;
using Discord.Net;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.ReactionListener;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Admin
{
[Group("role")]
public class Role : ModuleBase

View file

@ -3,8 +3,9 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Admin
{
public class Say : ModuleBase
{

View file

@ -2,8 +2,10 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.UserRepository;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Games
{
[Group("battletag")]
public class BattleTag : ModuleBase

View file

@ -3,11 +3,12 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.UserRepository;
using OverwatchAPI;
using OverwatchAPI.Config;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Games
{
[Group("ow")]
public class Overwatch : ModuleBase

View file

@ -4,9 +4,10 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using PokeAPI;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Games
{
public class Pokedex : ModuleBase
{

View file

@ -2,9 +2,11 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Games
{
public class Roll : ModuleBase
{

View file

@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using StackExchange.Redis;
using Utf8Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations.Google
{
public class Google : ModuleBase
{
@ -40,7 +40,7 @@ namespace Geekbot.net.Commands
var url = new Uri($"https://kgsearch.googleapis.com/v1/entities:search?languages=en&limit=1&query={searchText}&key={apiKey}");
var responseString = client.DownloadString(url);
var response = JsonSerializer.Deserialize<GoogleKgApiResponse>(responseString);
var response = JsonSerializer.Deserialize<GoogleKgApiResponseDto>(responseString);
if (!response.ItemListElement.Any())
{
@ -48,13 +48,13 @@ namespace Geekbot.net.Commands
return;
}
var data = response.ItemListElement.First().Result;
var data = response.ItemListElement.First().ResultDto;
var eb = new EmbedBuilder();
eb.Title = data.Name;
if(!string.IsNullOrEmpty(data.Description)) eb.WithDescription(data.Description);
if(!string.IsNullOrEmpty(data.DetailedDescription?.Url)) eb.WithUrl(data.DetailedDescription.Url);
if(!string.IsNullOrEmpty(data.DetailedDescription?.ArticleBody)) eb.AddField("Details", data.DetailedDescription.ArticleBody);
if(!string.IsNullOrEmpty(data.Image?.ContentUrl)) eb.WithThumbnailUrl(data.Image.ContentUrl);
if(!string.IsNullOrEmpty(data.DetailedDtoDescription?.Url)) eb.WithUrl(data.DetailedDtoDescription.Url);
if(!string.IsNullOrEmpty(data.DetailedDtoDescription?.ArticleBody)) eb.AddField("Details", data.DetailedDtoDescription.ArticleBody);
if(!string.IsNullOrEmpty(data.ImageDto?.ContentUrl)) eb.WithThumbnailUrl(data.ImageDto.ContentUrl);
await ReplyAsync("", false, eb.Build());
}
@ -64,37 +64,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
public class GoogleKgApiResponse
{
public List<GoogleKgApiElement> ItemListElement { get; set; }
public class GoogleKgApiElement
{
public GoogleKgApiResult Result { get; set; }
public double ResultScore { get; set; }
}
public class GoogleKgApiResult
{
public string Name { get; set; }
public string Description { get; set; }
public GoogleKgApiImage Image { get; set; }
public GoogleKgApiDetailed DetailedDescription { get; set; }
}
public class GoogleKgApiImage
{
public string ContentUrl { get; set; }
public string Url { get; set; }
}
public class GoogleKgApiDetailed
{
public string ArticleBody { get; set; }
public string Url { get; set; }
public string License { get; set; }
}
}
}
}

View file

@ -0,0 +1,9 @@
namespace Geekbot.net.Commands.Integrations.Google
{
public class GoogleKgApiDetailedDto
{
public string ArticleBody { get; set; }
public string Url { get; set; }
public string License { get; set; }
}
}

View file

@ -0,0 +1,8 @@
namespace Geekbot.net.Commands.Integrations.Google
{
public class GoogleKgApiElementDto
{
public GoogleKgApiResultDto ResultDto { get; set; }
public double ResultScore { get; set; }
}
}

View file

@ -0,0 +1,8 @@
namespace Geekbot.net.Commands.Integrations.Google
{
public class GoogleKgApiImageDto
{
public string ContentUrl { get; set; }
public string Url { get; set; }
}
}

View file

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace Geekbot.net.Commands.Integrations.Google
{
public class GoogleKgApiResponseDto
{
public List<GoogleKgApiElementDto> ItemListElement { get; set; }
}
}

View file

@ -0,0 +1,10 @@
namespace Geekbot.net.Commands.Integrations.Google
{
public class GoogleKgApiResultDto
{
public string Name { get; set; }
public string Description { get; set; }
public GoogleKgApiImageDto ImageDto { get; set; }
public GoogleKgApiDetailedDto DetailedDtoDescription { get; set; }
}
}

View file

@ -5,9 +5,11 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling;
using MtgApiManager.Lib.Service;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations
{
public class Magicthegathering : ModuleBase
{

View file

@ -4,8 +4,10 @@ using System.Web;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Clients;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations
{
public class Mal : ModuleBase
{

View file

@ -0,0 +1,12 @@
namespace Geekbot.net.Commands.Integrations.UbranDictionary
{
internal class UrbanListItemDto
{
public string Definition { get; set; }
public string Permalink { get; set; }
public string ThumbsUp { get; set; }
public string Word { get; set; }
public string Example { get; set; }
public string ThumbsDown { get; set; }
}
}

View file

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Geekbot.net.Commands.Integrations.UbranDictionary
{
internal class UrbanResponseDto
{
public string[] Tags { get; set; }
public List<UrbanListItemDto> List { get; set; }
}
}

View file

@ -1,14 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations.UbranDictionary
{
public class UrbanDictionary : ModuleBase
{
@ -33,7 +33,7 @@ namespace Geekbot.net.Commands
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var definitions = JsonConvert.DeserializeObject<UrbanResponse>(stringResponse);
var definitions = JsonConvert.DeserializeObject<UrbanResponseDto>(stringResponse);
if (definitions.List.Count == 0)
{
await ReplyAsync("That word hasn't been defined...");
@ -63,21 +63,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
private class UrbanResponse
{
public string[] Tags { get; set; }
public List<UrbanListItem> List { get; set; }
}
private class UrbanListItem
{
public string Definition { get; set; }
public string Permalink { get; set; }
public string ThumbsUp { get; set; }
public string Word { get; set; }
public string Example { get; set; }
public string ThumbsDown { get; set; }
}
}
}

View file

@ -6,12 +6,13 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using HtmlAgilityPack;
using StackExchange.Redis;
using WikipediaApi;
using WikipediaApi.Page;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations
{
public class Wikipedia : ModuleBase
{

View file

@ -2,11 +2,12 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Google.Apis.Services;
using Google.Apis.YouTube.v3;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Integrations
{
public class Youtube : ModuleBase
{

View file

@ -1,58 +1,54 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Newtonsoft.Json;
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()
{
try
{
using (var client = new HttpClient())
{
try
{
client.BaseAddress = new Uri("https://aws.random.cat");
var response = await client.GetAsync("/meow");
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var catFile = JsonConvert.DeserializeObject<CatResponse>(stringResponse);
var eb = new EmbedBuilder();
eb.ImageUrl = catFile.File;
await ReplyAsync("", false, eb.Build());
}
catch
{
await ReplyAsync("Seems like the dog cought the cat (error occured)");
}
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
}
}
private class CatResponse
{
public string File { get; set; }
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands.Randomness.Cat
{
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()
{
try
{
using (var client = new HttpClient())
{
try
{
client.BaseAddress = new Uri("https://aws.random.cat");
var response = await client.GetAsync("/meow");
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var catFile = JsonConvert.DeserializeObject<CatResponseDto>(stringResponse);
var eb = new EmbedBuilder();
eb.ImageUrl = catFile.File;
await ReplyAsync("", false, eb.Build());
}
catch
{
await ReplyAsync("Seems like the dog cought the cat (error occured)");
}
}
}
catch (Exception e)
{
_errorHandler.HandleCommandException(e, Context);
}
}
}
}

View file

@ -0,0 +1,7 @@
namespace Geekbot.net.Commands.Randomness.Cat
{
internal class CatResponseDto
{
public string File { get; set; }
}
}

View file

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

View file

@ -0,0 +1,7 @@
namespace Geekbot.net.Commands.Randomness.Chuck
{
internal class ChuckNorrisJokeResponseDto
{
public string Value { get; set; }
}
}

View file

@ -4,9 +4,10 @@ using System.Net.Http.Headers;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness.Chuck
{
public class ChuckNorrisJokes : ModuleBase
{
@ -34,7 +35,7 @@ namespace Geekbot.net.Commands
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<ChuckNorrisJokeResponse>(stringResponse);
var data = JsonConvert.DeserializeObject<ChuckNorrisJokeResponseDto>(stringResponse);
await ReplyAsync(data.Value);
}
catch (HttpRequestException)
@ -48,10 +49,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
private class ChuckNorrisJokeResponse
{
public string Value { get; set; }
}
}
}

View file

@ -0,0 +1,7 @@
namespace Geekbot.net.Commands.Randomness.Dad
{
internal class DadJokeResponseDto
{
public string Joke { get; set; }
}
}

View file

@ -4,9 +4,10 @@ using System.Net.Http.Headers;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness.Dad
{
public class DadJokes : ModuleBase
{
@ -34,7 +35,7 @@ namespace Geekbot.net.Commands
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<DadJokeResponse>(stringResponse);
var data = JsonConvert.DeserializeObject<DadJokeResponseDto>(stringResponse);
await ReplyAsync(data.Joke);
}
catch (HttpRequestException)
@ -48,10 +49,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
private class DadJokeResponse
{
public string Joke { get; set; }
}
}
}

View file

@ -4,9 +4,10 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness.Dog
{
public class Dog : ModuleBase
{
@ -33,7 +34,7 @@ namespace Geekbot.net.Commands
response.EnsureSuccessStatusCode();
var stringResponse = await response.Content.ReadAsStringAsync();
var dogFile = JsonConvert.DeserializeObject<DogResponse>(stringResponse);
var dogFile = JsonConvert.DeserializeObject<DogResponseDto>(stringResponse);
var eb = new EmbedBuilder();
eb.ImageUrl = dogFile.Url;
await ReplyAsync("", false, eb.Build());
@ -49,10 +50,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
private class DogResponse
{
public string Url { get; set; }
}
}
}

View file

@ -0,0 +1,7 @@
namespace Geekbot.net.Commands.Randomness.Dog
{
internal class DogResponseDto
{
public string Url { get; set; }
}
}

View file

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class EightBall : ModuleBase
{

View file

@ -3,7 +3,7 @@ using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Media;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class Fortune : ModuleBase
{

View file

@ -3,8 +3,9 @@ using System.Net;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class Gdq : ModuleBase
{

View file

@ -4,7 +4,7 @@ using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Media;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class RandomAnimals : ModuleBase
{

View file

@ -3,9 +3,10 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class Ship : ModuleBase
{

View file

@ -4,9 +4,10 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Randomness
{
public class Slap : ModuleBase
{

View file

@ -4,9 +4,11 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Levels;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.User
{
public class GuildInfo : ModuleBase
{
@ -51,12 +53,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
public static string FirstCharToUpper(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentException("ARGH!");
return input.First().ToString().ToUpper() + input.Substring(1);
}
}
}

View file

@ -3,9 +3,11 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.User
{
public class Karma : ModuleBase
{

View file

@ -6,9 +6,13 @@ using System.Threading.Tasks;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Logger;
using Geekbot.net.Lib.UserRepository;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.User.Rank
{
public class Rank : ModuleBase
{
@ -69,7 +73,7 @@ namespace Geekbot.net.Commands
}
if (type == "Messages") sortedList.RemoveAt(0);
var highscoreUsers = new Dictionary<RankUserPolyfill, int>();
var highscoreUsers = new Dictionary<RankUserPolyfillDto, int>();
var listLimiter = 1;
var failedToRetrieveUser = false;
foreach (var user in sortedList)
@ -80,7 +84,7 @@ namespace Geekbot.net.Commands
var guildUser = _userRepository.Get((ulong) user.Name);
if (guildUser.Username != null)
{
highscoreUsers.Add(new RankUserPolyfill
highscoreUsers.Add(new RankUserPolyfillDto
{
Username = guildUser.Username,
Discriminator = guildUser.Discriminator
@ -88,7 +92,7 @@ namespace Geekbot.net.Commands
}
else
{
highscoreUsers.Add(new RankUserPolyfill
highscoreUsers.Add(new RankUserPolyfillDto
{
Id = user.Name
}, (int) user.Value);
@ -143,11 +147,4 @@ namespace Geekbot.net.Commands
}
}
}
internal class RankUserPolyfill
{
public string Username { get; set; }
public string Discriminator { get; set; }
public string Id { get; set; }
}
}

View file

@ -0,0 +1,9 @@
namespace Geekbot.net.Commands.User.Rank
{
internal class RankUserPolyfillDto
{
public string Username { get; set; }
public string Discriminator { get; set; }
public string Id { get; set; }
}
}

View file

@ -3,9 +3,11 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Levels;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.User
{
public class Stats : ModuleBase
{

View file

@ -3,8 +3,9 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class AvatarGetter : ModuleBase
{

View file

@ -8,9 +8,10 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils.Changelog
{
public class Changelog : ModuleBase
{
@ -51,7 +52,7 @@ 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})");
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.AuthorDto.Date:yyyy-MM-dd})");
eb.Description = sb.ToString();
eb.WithFooter(new EmbedFooterBuilder
{
@ -65,21 +66,5 @@ namespace Geekbot.net.Commands
_errorHandler.HandleCommandException(e, Context);
}
}
private class CommitDto
{
public CommitInfo Commit { get; set; }
}
private class CommitInfo
{
public CommitAuthor Author { get; set; }
public string Message { get; set; }
}
private class CommitAuthor
{
public DateTimeOffset Date { get; set; }
}
}
}

View file

@ -0,0 +1,9 @@
using System;
namespace Geekbot.net.Commands.Utils.Changelog
{
internal class CommitAuthorDto
{
public DateTimeOffset Date { get; set; }
}
}

View file

@ -0,0 +1,7 @@
namespace Geekbot.net.Commands.Utils.Changelog
{
internal class CommitDto
{
public CommitInfoDto Commit { get; set; }
}
}

View file

@ -0,0 +1,8 @@
namespace Geekbot.net.Commands.Utils.Changelog
{
internal class CommitInfoDto
{
public CommitAuthorDto AuthorDto { get; set; }
public string Message { get; set; }
}
}

View file

@ -2,8 +2,10 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.Localization;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class Choose : ModuleBase
{

View file

@ -6,7 +6,7 @@ using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils.Dice
{
public class Dice : ModuleBase
{
@ -112,12 +112,4 @@ namespace Geekbot.net.Commands
return new DiceTypeDto();
}
}
internal class DiceTypeDto
{
public string DiceType { get; set; }
public int Times { get; set; }
public int Sides { get; set; }
public int Mod { get; set; }
}
}

View file

@ -0,0 +1,10 @@
namespace Geekbot.net.Commands.Utils.Dice
{
internal class DiceTypeDto
{
public string DiceType { get; set; }
public int Times { get; set; }
public int Sides { get; set; }
public int Mod { get; set; }
}
}

View file

@ -2,8 +2,10 @@
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class Emojify : ModuleBase
{

View file

@ -4,8 +4,9 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class Help : ModuleBase
{

View file

@ -6,9 +6,10 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class Info : ModuleBase
{

View file

@ -2,7 +2,7 @@
using Discord.Commands;
using Geekbot.net.Lib;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils
{
public class Ping : ModuleBase
{

View file

@ -6,10 +6,13 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.Converters;
using Geekbot.net.Lib.ErrorHandling;
using Geekbot.net.Lib.UserRepository;
using Newtonsoft.Json;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils.Poll
{
[Group("poll")]
public class Poll : ModuleBase
@ -92,7 +95,7 @@ namespace Geekbot.net.Commands
pollMessage.AddReactionAsync(new Emoji(_emojiConverter.NumberToEmoji(i)));
i++;
});
var poll = new PollData
var poll = new PollDataDto
{
Creator = Context.User.Id,
MessageId = pollMessage.Id,
@ -139,28 +142,28 @@ namespace Geekbot.net.Commands
}
}
private PollData GetCurrentPoll()
private PollDataDto GetCurrentPoll()
{
try
{
var currentPoll = _redis.HashGet($"{Context.Guild.Id}:Polls", Context.Channel.Id);
return JsonConvert.DeserializeObject<PollData>(currentPoll.ToString());
return JsonConvert.DeserializeObject<PollDataDto>(currentPoll.ToString());
}
catch
{
return new PollData();
return new PollDataDto();
}
}
private async Task<List<PollResult>> GetPollResults(PollData poll)
private async Task<List<PollResultDto>> GetPollResults(PollDataDto poll)
{
var message = (IUserMessage) await Context.Channel.GetMessageAsync(poll.MessageId);
var results = new List<PollResult>();
var results = new List<PollResultDto>();
foreach (var r in message.Reactions)
try
{
var option = int.Parse(r.Key.Name.ToCharArray()[0].ToString());
var result = new PollResult
var result = new PollResultDto
{
Option = poll.Options[option - 1],
VoteCount = r.Value.ReactionCount
@ -172,20 +175,5 @@ namespace Geekbot.net.Commands
results.Sort((x, y) => y.VoteCount.CompareTo(x.VoteCount));
return results;
}
private class PollData
{
public ulong Creator { get; set; }
public ulong MessageId { get; set; }
public bool IsFinshed { get; set; }
public string Question { get; set; }
public List<string> Options { get; set; }
}
private class PollResult
{
public string Option { get; set; }
public int VoteCount { get; set; }
}
}
}

View file

@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace Geekbot.net.Commands.Utils.Poll
{
internal class PollDataDto
{
public ulong Creator { get; set; }
public ulong MessageId { get; set; }
public bool IsFinshed { get; set; }
public string Question { get; set; }
public List<string> Options { get; set; }
}
}

View file

@ -0,0 +1,8 @@
namespace Geekbot.net.Commands.Utils.Poll
{
internal class PollResultDto
{
public string Option { get; set; }
public int VoteCount { get; set; }
}
}

View file

@ -4,10 +4,11 @@ using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
using Newtonsoft.Json;
using StackExchange.Redis;
namespace Geekbot.net.Commands
namespace Geekbot.net.Commands.Utils.Quote
{
[Group("quote")]
public class Quote : ModuleBase
@ -31,7 +32,7 @@ namespace Geekbot.net.Commands
var randomQuotes = _redis.SetMembers($"{Context.Guild.Id}:Quotes");
var randomNumber = new Random().Next(randomQuotes.Length - 1);
var randomQuote = randomQuotes[randomNumber];
var quote = JsonConvert.DeserializeObject<QuoteObject>(randomQuote);
var quote = JsonConvert.DeserializeObject<QuoteObjectDto>(randomQuote);
var embed = QuoteBuilder(quote, randomNumber + 1);
await ReplyAsync("", false, embed.Build());
}
@ -159,7 +160,7 @@ namespace Geekbot.net.Commands
var success = _redis.SetRemove($"{Context.Guild.Id}:Quotes", quotes[id - 1]);
if (success)
{
var quote = JsonConvert.DeserializeObject<QuoteObject>(quotes[id - 1]);
var quote = JsonConvert.DeserializeObject<QuoteObjectDto>(quotes[id - 1]);
var embed = QuoteBuilder(quote);
await ReplyAsync($"**Removed #{id}**", false, embed.Build());
}
@ -186,7 +187,7 @@ namespace Geekbot.net.Commands
&& !msg.Content.ToLower().StartsWith("!"));
}
private EmbedBuilder QuoteBuilder(QuoteObject quote, int id = 0)
private EmbedBuilder QuoteBuilder(QuoteObjectDto quote, int id = 0)
{
var user = Context.Client.GetUserAsync(quote.UserId).Result;
var eb = new EmbedBuilder();
@ -199,7 +200,7 @@ namespace Geekbot.net.Commands
return eb;
}
private QuoteObject CreateQuoteObject(IMessage message)
private QuoteObjectDto CreateQuoteObject(IMessage message)
{
string image;
try
@ -211,7 +212,7 @@ namespace Geekbot.net.Commands
image = null;
}
return new QuoteObject
return new QuoteObjectDto
{
UserId = message.Author.Id,
Time = message.Timestamp.DateTime,
@ -220,12 +221,4 @@ namespace Geekbot.net.Commands
};
}
}
public class QuoteObject
{
public ulong UserId { get; set; }
public string Quote { get; set; }
public DateTime Time { get; set; }
public string Image { get; set; }
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace Geekbot.net.Commands.Utils.Quote
{
internal class QuoteObjectDto
{
public ulong UserId { get; set; }
public string Quote { get; set; }
public DateTime Time { get; set; }
public string Image { get; set; }
}
}

View file

@ -1,102 +0,0 @@
//using System;
//using System.IO;
//using System.Threading.Tasks;
//using Discord;
//using Discord.Commands;
//using Geekbot.net.Lib;
//
//namespace Geekbot.net.Commands
//{
// public class Voice : ModuleBase
// {
// private readonly IAudioUtils _audioUtils;
// private readonly IErrorHandler _errorHandler;
//
// public Voice(IErrorHandler errorHandler, IAudioUtils audioUtils)
// {
// _errorHandler = errorHandler;
// _audioUtils = audioUtils;
// }
//
// [Command("join")]
// public async Task JoinChannel()
// {
// try
// {
// // Get the audio channel
// var channel = (Context.User as IGuildUser)?.VoiceChannel;
// if (channel == null)
// {
// await Context.Channel.SendMessageAsync(
// "User must be in a voice channel, or a voice channel must be passed as an argument.");
// return;
// }
//
// // For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
// var audioClient = await channel.ConnectAsync();
// _audioUtils.StoreAudioClient(Context.Guild.Id, audioClient);
// await ReplyAsync($"Connected to {channel.Name}");
// }
// catch (Exception e)
// {
// _errorHandler.HandleCommandException(e, Context);
// }
// }
//
// [Command("disconnect")]
// public async Task DisconnectChannel()
// {
// try
// {
// var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
// if (audioClient == null)
// {
// await Context.Channel.SendMessageAsync("I'm not in a voice channel at the moment");
// return;
// }
//
// await audioClient.StopAsync();
// await ReplyAsync("Disconnected from channel!");
// _audioUtils.Cleanup(Context.Guild.Id);
// }
// catch (Exception e)
// {
// _errorHandler.HandleCommandException(e, Context);
// _audioUtils.Cleanup(Context.Guild.Id);
// }
// }
//
// [Command("ytplay")]
// public async Task ytplay(string url)
// {
// try
// {
// if (!url.Contains("youtube"))
// {
// await ReplyAsync("I can only play youtube videos");
// return;
// }
// var audioClient = _audioUtils.GetAudioClient(Context.Guild.Id);
// if (audioClient == null)
// {
// await ReplyAsync("I'm not in a voice channel at the moment");
// return;
// }
//
// var message = await Context.Channel.SendMessageAsync("Just a second, i'm still a bit slow at this");
// var ffmpeg = _audioUtils.CreateStreamFromYoutube(url, Context.Guild.Id);
// var output = ffmpeg.StandardOutput.BaseStream;
// await message.ModifyAsync(msg => msg.Content = "**Playing!** Please note that this feature is experimental");
// var discord = audioClient.CreatePCMStream(Discord.Audio.AudioApplication.Mixed);
// await output.CopyToAsync(discord);
// await discord.FlushAsync();
// _audioUtils.Cleanup(Context.Guild.Id);
// }
// catch (Exception e)
// {
// _errorHandler.HandleCommandException(e, Context);
// _audioUtils.Cleanup(Context.Guild.Id);
// }
// }
// }
//}