Fixes to some commands which had IUserMesasge leftover

This commit is contained in:
Kwoth 2017-01-01 13:26:17 +01:00
parent 221e707963
commit 755a2c40b3
13 changed files with 85 additions and 84 deletions

View File

@ -207,9 +207,9 @@ namespace NadekoBot.Modules.Gambling
}
private void Client_MessageReceived(IMessage imsg)
private void Client_MessageReceived(SocketMessage imsg)
{
var msg = imsg as IUserMessage;
var msg = imsg as SocketUserMessage;
if (msg == null)
return;
if (msg.IsAuthor() || !(imsg.Channel is ITextChannel) || imsg.Channel != raceChannel)

View File

@ -26,9 +26,9 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Roll(IUserMessage umsg)
public async Task Roll()
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
if (channel == null)
return;
var rng = new NadekoRandom();
@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Gambling
catch { return new MemoryStream(); }
});
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
await channel.SendFileAsync(imageStream, "dice.png", $"{Context.User.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
}
public enum RollOrderType
@ -60,39 +60,39 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public async Task Roll(IUserMessage umsg, int num)
public async Task Roll(int num)
{
await InternalRoll(umsg, num, true).ConfigureAwait(false);
await InternalRoll(num, true).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(0)]
public async Task Rolluo(IUserMessage umsg, int num)
public async Task Rolluo(int num)
{
await InternalRoll(umsg, num, false).ConfigureAwait(false);
await InternalRoll(num, false).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task Roll(IUserMessage umsg, string arg)
public async Task Roll(string arg)
{
await InternallDndRoll(umsg, arg, true).ConfigureAwait(false);
await InternallDndRoll(arg, true).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
[Priority(1)]
public async Task Rolluo(IUserMessage umsg, string arg)
public async Task Rolluo(string arg)
{
await InternallDndRoll(umsg, arg, false).ConfigureAwait(false);
await InternallDndRoll(arg, false).ConfigureAwait(false);
}
private async Task InternalRoll(IUserMessage umsg, int num, bool ordered)
private async Task InternalRoll( int num, bool ordered)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
if (channel == null)
return;
@ -136,12 +136,12 @@ namespace NadekoBot.Modules.Gambling
var ms = new MemoryStream();
bitmap.SaveAsPng(ms);
ms.Position = 0;
await channel.SendFileAsync(ms, "dice.png", $"{umsg.Author.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
await channel.SendFileAsync(ms, "dice.png", $"{Context.User.Mention} rolled {values.Count} {(values.Count == 1 ? "die" : "dice")}. Total: **{values.Sum()}** Average: **{(values.Sum() / (1.0f * values.Count)).ToString("N2")}**").ConfigureAwait(false);
}
private async Task InternallDndRoll(IUserMessage umsg, string arg, bool ordered)
private async Task InternallDndRoll(string arg, bool ordered)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
if (channel == null)
return;
@ -160,7 +160,7 @@ namespace NadekoBot.Modules.Gambling
{
rolls.Add(fateRolls[rng.Next(0, fateRolls.Length)]);
}
var embed = new EmbedBuilder().WithOkColor().WithDescription($"{umsg.Author.Mention} rolled {n1} fate {(n1 == 1 ? "die" : "dice")}.")
var embed = new EmbedBuilder().WithOkColor().WithDescription($"{Context.User.Mention} rolled {n1} fate {(n1 == 1 ? "die" : "dice")}.")
.AddField(efb => efb.WithName(Format.Bold("Result"))
.WithValue(string.Join(" ", rolls.Select(c => Format.Code($"[{c}]")))));
await channel.EmbedAsync(embed).ConfigureAwait(false);
@ -183,7 +183,7 @@ namespace NadekoBot.Modules.Gambling
arr[i] = rng.Next(1, n2 + 1) + add - sub;
}
var embed = new EmbedBuilder().WithOkColor().WithDescription($"{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`")
var embed = new EmbedBuilder().WithOkColor().WithDescription($"{Context.User.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`")
.AddField(efb => efb.WithName(Format.Bold("Result"))
.WithValue(string.Join(" ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => Format.Code(x.ToString())))));
await channel.EmbedAsync(embed).ConfigureAwait(false);
@ -193,9 +193,9 @@ namespace NadekoBot.Modules.Gambling
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
public async Task NRoll([Remainder] string range)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
try
{
@ -215,7 +215,7 @@ namespace NadekoBot.Modules.Gambling
rolled = new NadekoRandom().Next(0, int.Parse(range) + 1);
}
await channel.SendConfirmAsync($"{umsg.Author.Mention} rolled **{rolled}**.").ConfigureAwait(false);
await channel.SendConfirmAsync($"{Context.User.Mention} rolled **{rolled}**.").ConfigureAwait(false);
}
catch (Exception ex)
{

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
@ -25,7 +26,7 @@ namespace NadekoBot.Modules.Games
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Acro(IUserMessage imsg, int time = 60)
public async Task Acro(int time = 60)
{
var channel = (ITextChannel)imsg.Channel;
@ -167,11 +168,11 @@ namespace NadekoBot.Modules.Games
await End().ConfigureAwait(false);
}
private async void PotentialAcro(IMessage arg)
private async void PotentialAcro(SocketMessage arg)
{
try
{
var msg = arg as IUserMessage;
var msg = arg as SocketUserMessage;
if (msg == null || msg.Author.IsBot || msg.Channel.Id != channel.Id)
return;

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Services;
@ -46,7 +47,7 @@ namespace NadekoBot.Modules.Games
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
}
public static async Task<bool> TryAsk(IUserMessage msg)
public static async Task<bool> TryAsk(SocketUserMessage msg)
{
var channel = msg.Channel as ITextChannel;

View File

@ -1,4 +1,5 @@
using Discord;
using Discord.WebSocket;
using NadekoBot.Extensions;
using NadekoBot.Services;
using Newtonsoft.Json;
@ -128,11 +129,11 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
await GameChannel.EmbedAsync(embed.WithOkColor()).ConfigureAwait(false);
}
private async void PotentialGuess(IMessage msg)
private async void PotentialGuess(SocketMessage msg)
{
try
{
if (!(msg is IUserMessage))
if (!(msg is SocketUserMessage))
return;
if (msg.Channel != GameChannel)

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.EntityFrameworkCore;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
@ -62,11 +63,11 @@ namespace NadekoBot.Modules.Games
_log.Debug($"Loaded in {sw.Elapsed.TotalSeconds:F2}s");
}
private static async void PotentialFlowerGeneration(IMessage imsg)
private static async void PotentialFlowerGeneration(SocketMessage imsg)
{
try
{
var msg = imsg as IUserMessage;
var msg = imsg as SocketUserMessage;
if (msg == null || msg.IsAuthor() || msg.Author.IsBot)
return;

View File

@ -128,12 +128,12 @@ namespace NadekoBot.Modules.Games
}
}
private async void Vote(IMessage imsg)
private async void Vote(SocketMessage imsg)
{
try
{
// has to be a user message
var msg = imsg as IUserMessage;
var msg = imsg as SocketUserMessage;
if (msg == null || msg.Author.IsBot)
return;

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules.Games.Commands.Models;
@ -105,13 +106,13 @@ namespace NadekoBot.Modules.Games
NadekoBot.Client.MessageReceived += AnswerReceived;
}
private async void AnswerReceived(IMessage imsg)
private async void AnswerReceived(SocketMessage imsg)
{
try
{
if (imsg.Author.IsBot)
return;
var msg = imsg as IUserMessage;
var msg = imsg as SocketUserMessage;
if (msg == null)
return;

View File

@ -1,5 +1,6 @@
using Discord;
using Discord.Net;
using Discord.WebSocket;
using NadekoBot.Extensions;
using NLog;
using System;
@ -141,14 +142,14 @@ namespace NadekoBot.Modules.Games.Trivia
try { await channel.SendConfirmAsync("Trivia Game", "Stopping after this question.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
}
private async void PotentialGuess(IMessage imsg)
private async void PotentialGuess(SocketMessage imsg)
{
try
{
if (imsg.Author.IsBot)
return;
var umsg = imsg as IUserMessage;
var umsg = imsg as SocketUserMessage;
if (umsg == null)
return;

View File

@ -21,13 +21,13 @@ namespace NadekoBot.Modules.Games
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Trivia([Remainder] string additionalArgs = "")
=> Trivia(Context.Message, 10, additionalArgs);
=> Trivia(10, additionalArgs);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Trivia(IUserMessage umsg, int winReq = 10, [Remainder] string additionalArgs = "")
public async Task Trivia(int winReq = 10, [Remainder] string additionalArgs = "")
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
var showHints = !additionalArgs.Contains("nohint");

View File

@ -580,7 +580,7 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ReptCurSong(IUserMessage umsg)
public async Task ReptCurSong()
{
MusicPlayer musicPlayer;
@ -782,7 +782,7 @@ $"{("tracks".SnPl(musicPlayer.Playlist.Count))} | {(int)total.TotalHours}h {tota
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Autoplay(IUserMessage umsg)
public async Task Autoplay()
{
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(Context.Guild.Id, out musicPlayer))

View File

@ -28,9 +28,9 @@ namespace NadekoBot.Modules.NSFW
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Hentai(IUserMessage umsg, [Remainder] string tag = null)
public async Task Hentai([Remainder] string tag = null)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
tag = tag?.Trim() ?? "";
@ -66,16 +66,16 @@ namespace NadekoBot.Modules.NSFW
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task AutoHentai(IUserMessage umsg, int interval = 0, string tags = null)
public async Task AutoHentai(int interval = 0, string tags = null)
{
Timer t;
if (interval == 0)
{
if (AutoHentaiTimers.TryRemove(umsg.Channel.Id, out t))
if (AutoHentaiTimers.TryRemove(Context.Channel.Id, out t))
{
t.Change(Timeout.Infinite, Timeout.Infinite); //proper way to disable the timer
await umsg.Channel.SendConfirmAsync("Autohentai stopped.").ConfigureAwait(false);
await Context.Channel.SendConfirmAsync("Autohentai stopped.").ConfigureAwait(false);
}
return;
}
@ -90,28 +90,28 @@ namespace NadekoBot.Modules.NSFW
try
{
if (tagsArr == null || tagsArr.Length == 0)
await Hentai(umsg, null).ConfigureAwait(false);
await Hentai(null).ConfigureAwait(false);
else
await Hentai(umsg, tagsArr[new NadekoRandom().Next(0, tagsArr.Length)]);
await Hentai(tagsArr[new NadekoRandom().Next(0, tagsArr.Length)]);
}
catch { }
}, null, interval * 1000, interval * 1000);
AutoHentaiTimers.AddOrUpdate(umsg.Channel.Id, t, (key, old) =>
AutoHentaiTimers.AddOrUpdate(Context.Channel.Id, t, (key, old) =>
{
old.Change(Timeout.Infinite, Timeout.Infinite);
return t;
});
await umsg.Channel.SendConfirmAsync($"Autohentai started. Reposting every {interval}s with one of the following tags:\n{string.Join(", ", tagsArr)}").ConfigureAwait(false);
await Context.Channel.SendConfirmAsync($"Autohentai started. Reposting every {interval}s with one of the following tags:\n{string.Join(", ", tagsArr)}").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task HentaiBomb(IUserMessage umsg, [Remainder] string tag = null)
public async Task HentaiBomb([Remainder] string tag = null)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
tag = tag?.Trim() ?? "";
tag = "rating%3Aexplicit+" + tag;
@ -133,76 +133,73 @@ namespace NadekoBot.Modules.NSFW
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Danbooru(IUserMessage umsg, [Remainder] string tag = null)
public async Task Danbooru([Remainder] string tag = null)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
tag = tag?.Trim() ?? "";
var url = await GetDanbooruImageLink(tag).ConfigureAwait(false);
if (url == null)
await channel.SendErrorAsync(umsg.Author.Mention + " No results.");
await channel.SendErrorAsync(Context.User.Mention + " No results.");
else
await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(umsg.Author.Mention + " " + tag)
.WithDescription(Context.User.Mention + " " + tag)
.WithImageUrl(url)
.WithFooter(efb => efb.WithText("Danbooru"))).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Yandere(IUserMessage umsg, [Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(umsg, tag, Searches.Searches.DapiSearchType.Yandere);
public Task Yandere([Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(Context.Message, tag, Searches.Searches.DapiSearchType.Yandere);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Konachan(IUserMessage umsg, [Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(umsg, tag, Searches.Searches.DapiSearchType.Konachan);
public Task Konachan([Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(Context.Message, tag, Searches.Searches.DapiSearchType.Konachan);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Gelbooru(IUserMessage umsg, [Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(umsg, tag, Searches.Searches.DapiSearchType.Gelbooru);
public Task Gelbooru([Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(Context.Message, tag, Searches.Searches.DapiSearchType.Gelbooru);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Rule34(IUserMessage umsg, [Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(umsg, tag, Searches.Searches.DapiSearchType.Rule34);
public Task Rule34([Remainder] string tag = null)
=> Searches.Searches.InternalDapiCommand(Context.Message, tag, Searches.Searches.DapiSearchType.Rule34);
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task E621(IUserMessage umsg, [Remainder] string tag = null)
public async Task E621([Remainder] string tag = null)
{
var channel = (ITextChannel)umsg.Channel;
var channel = (ITextChannel)Context.Channel;
tag = tag?.Trim() ?? "";
var url = await GetE621ImageLink(tag).ConfigureAwait(false);
if (url == null)
await channel.SendErrorAsync(umsg.Author.Mention + " No results.");
await channel.SendErrorAsync(Context.User.Mention + " No results.");
else
await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithDescription(umsg.Author.Mention + " " + tag)
.WithDescription(Context.User.Mention + " " + tag)
.WithImageUrl(url)
.WithFooter(efb => efb.WithText("e621"))).ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Cp(IUserMessage umsg)
public async Task Cp()
{
var channel = (ITextChannel)umsg.Channel;
await channel.SendMessageAsync("http://i.imgur.com/MZkY1md.jpg").ConfigureAwait(false);
await Context.Channel.SendMessageAsync("http://i.imgur.com/MZkY1md.jpg").ConfigureAwait(false);
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Boobs(IUserMessage umsg)
public async Task Boobs()
{
var channel = (ITextChannel)umsg.Channel;
try
{
JToken obj;
@ -210,20 +207,18 @@ namespace NadekoBot.Modules.NSFW
{
obj = JArray.Parse(await http.GetStringAsync($"http://api.oboobs.ru/boobs/{ new NadekoRandom().Next(0, 10229) }").ConfigureAwait(false))[0];
}
await channel.SendMessageAsync($"http://media.oboobs.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
await Context.Channel.SendMessageAsync($"http://media.oboobs.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
}
catch (Exception ex)
{
await channel.SendErrorAsync(ex.Message).ConfigureAwait(false);
await Context.Channel.SendErrorAsync(ex.Message).ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Butts(IUserMessage umsg)
public async Task Butts()
{
var channel = (ITextChannel)umsg.Channel;
try
{
JToken obj;
@ -231,11 +226,11 @@ namespace NadekoBot.Modules.NSFW
{
obj = JArray.Parse(await http.GetStringAsync($"http://api.obutts.ru/butts/{ new NadekoRandom().Next(0, 4222) }").ConfigureAwait(false))[0];
}
await channel.SendMessageAsync($"http://media.obutts.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
await Context.Channel.SendMessageAsync($"http://media.obutts.ru/{ obj["preview"].ToString() }").ConfigureAwait(false);
}
catch (Exception ex)
{
await channel.SendErrorAsync(ex.Message).ConfigureAwait(false);
await Context.Channel.SendErrorAsync(ex.Message).ConfigureAwait(false);
}
}

View File

@ -475,7 +475,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Hashtag(IUserMessage umsg, [Remainder] string query = null)
public async Task Hashtag([Remainder] string query = null)
{
var arg = query;
if (string.IsNullOrWhiteSpace(arg))
@ -551,7 +551,7 @@ namespace NadekoBot.Modules.Searches
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public Task Safebooru(IUserMessage umsg, [Remainder] string tag = null)
public Task Safebooru([Remainder] string tag = null)
=> InternalDapiCommand(umsg, tag, DapiSearchType.Safebooru);
[NadekoCommand, Usage, Description, Aliases]