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
|
||||
private class CatResponse
|
||||
{
|
||||
public string file { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,10 +46,10 @@ namespace Geekbot.net.Commands
|
|||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DogResponse
|
||||
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;
|
||||
|
||||
|
@ -31,8 +32,15 @@ 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; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
|
@ -37,8 +38,7 @@ namespace Geekbot.net
|
|||
{
|
||||
try
|
||||
{
|
||||
var message = messageParam as SocketUserMessage;
|
||||
if (message == null) return Task.CompletedTask;
|
||||
if (!(messageParam is SocketUserMessage message)) return Task.CompletedTask;
|
||||
if (message.Author.IsBot) return Task.CompletedTask;
|
||||
var argPos = 0;
|
||||
var lowCaseMsg = message.ToString().ToLower();
|
||||
|
@ -65,18 +65,30 @@ namespace Geekbot.net
|
|||
}
|
||||
}
|
||||
|
||||
public Task UpdateStats(SocketMessage messsageParam)
|
||||
public Task UpdateStats(SocketMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var message = messsageParam;
|
||||
if (message == null) return Task.CompletedTask;
|
||||
|
||||
if (message.Channel.Name.StartsWith('@'))
|
||||
{
|
||||
_logger.Information(
|
||||
$"[Message] DM-Channel - {message.Channel.Name} - {message.Content}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
var channel = (SocketGuildChannel) message.Channel;
|
||||
|
||||
_redis.HashIncrementAsync($"{channel.Guild.Id}:Messages", message.Author.Id.ToString());
|
||||
_redis.HashIncrementAsync($"{channel.Guild.Id}:Messages", 0.ToString());
|
||||
|
||||
if (message.Author.IsBot) return Task.CompletedTask;
|
||||
_logger.Information($"[Message] {channel.Guild.Name} - {message.Channel} - {message.Author.Username} - {message.Content}");
|
||||
_logger.Information(
|
||||
$"[Message] {channel.Guild.Name} ({channel.Guild.Id}) - {message.Channel} ({message.Channel.Id}) - {message.Author.Username}#{message.Author.Discriminator} ({message.Author.Id}) - {message.Content}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Could not process message stats");
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace Geekbot.net
|
|||
{
|
||||
LogLevel = LogSeverity.Verbose,
|
||||
MessageCacheSize = 1000
|
||||
// AlwaysDownloadUsers = true
|
||||
});
|
||||
client.Log += DiscordLogger;
|
||||
commands = new CommandService();
|
||||
|
@ -149,7 +148,7 @@ namespace Geekbot.net
|
|||
if (isConneted)
|
||||
{
|
||||
await client.SetGameAsync(redis.StringGet("Game"));
|
||||
logger.Information($"[Geekbot] Now Connected to {client.Guilds.Count} Servers");
|
||||
logger.Information($"[Geekbot] Now Connected as {client.CurrentUser.Username} to {client.Guilds.Count} Servers");
|
||||
|
||||
logger.Information("[Geekbot] Registering Stuff");
|
||||
|
||||
|
|
Loading…
Reference in a new issue