Urban Dictionary command, small improvents in message handler, emojis are in embeds now, avatar command
This commit is contained in:
parent
667d928ca4
commit
45f289d071
7 changed files with 168 additions and 27 deletions
37
Geekbot.net/Commands/AvatarGetter.cs
Normal file
37
Geekbot.net/Commands/AvatarGetter.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.Commands
|
||||
{
|
||||
public class AvatarGetter : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public AvatarGetter(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("avatar", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Get someones avatar")]
|
||||
public async Task getAvatar([Remainder, Summary("user")] IUser user = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
user = Context.User;
|
||||
}
|
||||
await ReplyAsync(user.GetAvatarUrl());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,10 +46,10 @@ namespace Geekbot.net.Commands
|
|||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CatResponse
|
||||
{
|
||||
public string file { get; set; }
|
||||
|
||||
private class CatResponse
|
||||
{
|
||||
public string file { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,10 +46,10 @@ namespace Geekbot.net.Commands
|
|||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DogResponse
|
||||
{
|
||||
public string url { get; set; }
|
||||
|
||||
private class DogResponse
|
||||
{
|
||||
public string url { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
|
@ -30,9 +31,16 @@ namespace Geekbot.net.Commands
|
|||
{
|
||||
await ReplyAsync("I can't take that much at once!");
|
||||
return;
|
||||
}
|
||||
await ReplyAsync($"*{Context.User.Username}#{Context.User.Discriminator} said:*");
|
||||
await ReplyAsync(emojis);
|
||||
}
|
||||
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());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
85
Geekbot.net/Commands/UrbanDictionary.cs
Normal file
85
Geekbot.net/Commands/UrbanDictionary.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
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 Newtonsoft.Json;
|
||||
|
||||
namespace Geekbot.net.Commands
|
||||
{
|
||||
public class UrbanDictionary : ModuleBase
|
||||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public UrbanDictionary(IErrorHandler errorHandler)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
[Command("urban", RunMode = RunMode.Async)]
|
||||
[Remarks(CommandCategories.Randomness)]
|
||||
[Summary("Lookup something on urban dictionary")]
|
||||
public async Task urbanDefine([Remainder, Summary("word")] string word)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.urbandictionary.com");
|
||||
var response = await client.GetAsync($"/v0/define?term={word}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var definitions = JsonConvert.DeserializeObject<UrbanResponse>(stringResponse);
|
||||
if (definitions.list.Count == 0)
|
||||
{
|
||||
await ReplyAsync("That word is not defined...");
|
||||
return;
|
||||
}
|
||||
var definition = definitions.list.OrderBy(e => e.thumbs_up).First();
|
||||
|
||||
var eb = new EmbedBuilder();
|
||||
eb.Title = definition.word;
|
||||
eb.WithColor(new Color(239,255,0));
|
||||
eb.Description = definition.definition;
|
||||
eb.AddField("Example", definition.example);
|
||||
eb.AddInlineField("Upvotes", definition.thumbs_up);
|
||||
eb.AddInlineField("Downvotes", definition.thumbs_down);
|
||||
eb.WithFooter(new EmbedFooterBuilder()
|
||||
{
|
||||
Text = definition.permalink
|
||||
});
|
||||
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
|
||||
private class UrbanResponse
|
||||
{
|
||||
public string[] tags { get; set; }
|
||||
public string result_type { get; set; }
|
||||
public List<UrbanListItem> list { get; set; }
|
||||
}
|
||||
|
||||
private class UrbanListItem
|
||||
{
|
||||
public string definition { get; set; }
|
||||
public string permalink { get; set; }
|
||||
public string thumbs_up { get; set; }
|
||||
public string author { get; set; }
|
||||
public string word { get; set; }
|
||||
public string defid { get; set; }
|
||||
public string current_vote { get; set; }
|
||||
public string example { get; set; }
|
||||
public string thumbs_down { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue