Roll commands done. Draw commands done. Untested.

This commit is contained in:
Kwoth 2016-09-13 18:12:27 +02:00
parent ec2ca03272
commit d969dcbbbd
85 changed files with 366 additions and 197 deletions

View File

@ -432,7 +432,7 @@ namespace NadekoBot.Modules.Administration
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
topic = topic ?? ""; topic = topic ?? "";
await (channel as ITextChannel).ModifyAsync(c => c.Topic = topic); await channel.ModifyAsync(c => c.Topic = topic);
await channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false); await channel.SendMessageAsync(":ok: **New channel topic set.**").ConfigureAwait(false);
} }
@ -467,7 +467,7 @@ namespace NadekoBot.Modules.Administration
[RequirePermission(ChannelPermission.ManageMessages)] [RequirePermission(ChannelPermission.ManageMessages)]
public async Task Prune(IUserMessage msg, int count) public async Task Prune(IUserMessage msg, int count)
{ {
var channel = msg.Channel as ITextChannel; var channel = (ITextChannel)msg.Channel;
await (msg as IUserMessage).DeleteAsync(); await (msg as IUserMessage).DeleteAsync();
while (count > 0) while (count > 0)
{ {
@ -485,7 +485,7 @@ namespace NadekoBot.Modules.Administration
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Prune(IUserMessage msg, IGuildUser user, int count = 100) public async Task Prune(IUserMessage msg, IGuildUser user, int count = 100)
{ {
var channel = msg.Channel as ITextChannel; var channel = (ITextChannel)msg.Channel;
int limit = (count < 100) ? count : 100; int limit = (count < 100) ? count : 100;
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit)).Where(m => m.Author == user); var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit)).Where(m => m.Author == user);
await msg.Channel.DeleteMessagesAsync(enumerable); await msg.Channel.DeleteMessagesAsync(enumerable);

View File

@ -27,11 +27,8 @@ namespace NadekoBot.Modules.ClashOfClans
uow.ClashOfClans uow.ClashOfClans
.GetAll() .GetAll()
.Select(cw => { .Select(cw => {
cw.Channel = NadekoBot.Client.GetGuilds() cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId)
.FirstOrDefault(s => s.Id == cw.GuildId)? ?.GetTextChannel(cw.ChannelId);
.GetChannels()
.FirstOrDefault(c => c.Id == cw.ChannelId)
as ITextChannel;
cw.Bases.Capacity = cw.Size; cw.Bases.Capacity = cw.Size;
return cw; return cw;
}) })
@ -318,11 +315,8 @@ namespace NadekoBot.Modules.ClashOfClans
Bases = new List<ClashCaller>(size), Bases = new List<ClashCaller>(size),
GuildId = serverId, GuildId = serverId,
ChannelId = channelId, ChannelId = channelId,
Channel = NadekoBot.Client.GetGuilds() Channel = NadekoBot.Client.GetGuild(serverId)
.FirstOrDefault(s => s.Id == serverId)? ?.GetTextChannel(channelId)
.GetChannels()
.FirstOrDefault(c => c.Id == channelId)
as ITextChannel
}; };
uow.ClashOfClans.Add(cw); uow.ClashOfClans.Add(cw);
await uow.CompleteAsync(); await uow.CompleteAsync();

View File

@ -1,11 +1,14 @@
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using ImageProcessorCore;
using NadekoBot.Attributes; using NadekoBot.Attributes;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Services; using NadekoBot.Services;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Resources;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -17,94 +20,191 @@ namespace NadekoBot.Modules.Gambling
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public Task Roll(IUserMessage umsg, [Remainder] string arg = null) => public async Task Roll(IUserMessage umsg)
publicRoll(umsg, arg, true); {
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var rng = new NadekoRandom();
var gen = rng.Next(1, 101);
var num1 = gen / 10;
var num2 = gen % 10;
var imageStream = await Task.Run(() =>
{
var ms = new MemoryStream();
new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
ms.Position = 0;
return ms;
});
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public Task Rolluo(IUserMessage umsg, [Remainder] string arg = null) => public async Task Roll(IUserMessage umsg, int num)
publicRoll(umsg, arg, false);
//todo drawing
private async Task publicRoll(IUserMessage umsg, string arg, bool ordered)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
var r = new NadekoRandom(); if (channel == null)
//if (string.IsNullOrWhiteSpace(arg)) return;
//{
// var gen = r.Next(0, 101);
// var num1 = gen / 10; var ordered = true;
// var num2 = gen % 10;
if (num < 1 || num > 30)
{
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
num = 30;
}
// var imageStream = await new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png); var rng = new NadekoRandom();
// await channel.SendFileAsync(imageStream, "dice.png").ConfigureAwait(false); var dice = new List<Image>(num);
// return; var values = new List<int>(num);
//} for (var i = 0; i < num; i++)
Match m; {
if ((m = dndRegex.Match(arg)).Length != 0) var randomNumber = rng.Next(1, 7);
var toInsert = dice.Count;
if (ordered)
{
if (randomNumber == 6 || dice.Count == 0)
toInsert = 0;
else if (randomNumber != 1)
for (var j = 0; j < dice.Count; j++)
{
if (values[j] < randomNumber)
{
toInsert = j;
break;
}
}
}
else
{
toInsert = dice.Count;
}
dice.Insert(toInsert, GetDice(randomNumber));
values.Insert(toInsert, randomNumber);
}
var bitmap = dice.Merge();
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);
}
//todo merge into internallDndRoll and internalRoll
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task Roll(IUserMessage umsg, string arg = "")
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = true;
var rng = new NadekoRandom();
Match match;
if ((match = dndRegex.Match(arg)).Length != 0)
{ {
int n1; int n1;
int n2; int n2;
if (int.TryParse(m.Groups["n1"].ToString(), out n1) && if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
int.TryParse(m.Groups["n2"].ToString(), out n2) && int.TryParse(match.Groups["n2"].ToString(), out n2) &&
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
{ {
var arr = new int[n1]; var arr = new int[n1];
for (int i = 0; i < n1; i++) for (int i = 0; i < n1; i++)
{ {
arr[i] = r.Next(1, n2 + 1); arr[i] = rng.Next(1, n2 + 1);
} }
var elemCnt = 0; var elemCnt = 0;
await channel.SendMessageAsync($"`Rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false); await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
} }
return;
} }
//try }
//{
// var num = int.Parse(e.Args[0]);
// if (num < 1) num = 1;
// if (num > 30)
// {
// await channel.SendMessageAsync("You can roll up to 30 dice at a time.").ConfigureAwait(false);
// num = 30;
// }
// var dices = new List<Image>(num);
// var values = new List<int>(num);
// for (var i = 0; i < num; i++)
// {
// var randomNumber = r.Next(1, 7);
// var toInsert = dices.Count;
// if (ordered)
// {
// if (randomNumber == 6 || dices.Count == 0)
// toInsert = 0;
// else if (randomNumber != 1)
// for (var j = 0; j < dices.Count; j++)
// {
// if (values[j] < randomNumber)
// {
// toInsert = j;
// break;
// }
// }
// }
// else
// {
// toInsert = dices.Count;
// }
// dices.Insert(toInsert, GetDice(randomNumber));
// values.Insert(toInsert, randomNumber);
// }
// var bitmap = dices.Merge(); [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// await channel.SendMessageAsync(values.Count + " Dice rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**").ConfigureAwait(false); [RequireContext(ContextType.Guild)]
// await channel.SendFileAsync("dice.png", bitmap.ToStream(ImageFormat.Png)).ConfigureAwait(false); public async Task Rolluo(IUserMessage umsg, string arg = "")
//} {
//catch var channel = (ITextChannel)umsg.Channel;
//{ if (channel == null)
// await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false); return;
//}
var ordered = false;
var rng = new NadekoRandom();
Match match;
if ((match = dndRegex.Match(arg)).Length != 0)
{
int n1;
int n2;
if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
int.TryParse(match.Groups["n2"].ToString(), out n2) &&
n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
{
var arr = new int[n1];
for (int i = 0; i < n1; i++)
{
arr[i] = rng.Next(1, n2 + 1);
}
var elemCnt = 0;
await channel.SendMessageAsync($"`{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} 1-{n2}.`\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
}
}
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task Rolluo(IUserMessage umsg, int num)
{
var channel = (ITextChannel)umsg.Channel;
if (channel == null)
return;
var ordered = true;
if (num < 1 || num > 30)
{
await channel.SendMessageAsync("Invalid number specified. You can roll up to 1-30 dice at a time.").ConfigureAwait(false);
num = 30;
}
var rng = new NadekoRandom();
var dice = new List<Image>(num);
var values = new List<int>(num);
for (var i = 0; i < num; i++)
{
var randomNumber = rng.Next(1, 7);
var toInsert = dice.Count;
if (ordered)
{
if (randomNumber == 6 || dice.Count == 0)
toInsert = 0;
else if (randomNumber != 1)
for (var j = 0; j < dice.Count; j++)
{
if (values[j] < randomNumber)
{
toInsert = j;
break;
}
}
}
else
{
toInsert = dice.Count;
}
dice.Insert(toInsert, GetDice(randomNumber));
values.Insert(toInsert, randomNumber);
}
var bitmap = dice.Merge();
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);
} }
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
@ -112,8 +212,7 @@ namespace NadekoBot.Modules.Gambling
public async Task NRoll(IUserMessage umsg, [Remainder] string range) public async Task NRoll(IUserMessage umsg, [Remainder] string range)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
try try
{ {
int rolled; int rolled;
@ -140,14 +239,23 @@ namespace NadekoBot.Modules.Gambling
} }
} }
private Image GetDice(int num)
{
const string pathToImage = "data/images/dice";
if(num != 10)
{
using (var stream = File.OpenRead(Path.Combine(pathToImage, $"{num}.png")))
return new Image(stream);
}
////todo drawing using (var one = File.OpenRead(Path.Combine(pathToImage, "1.png")))
//private Image GetDice(int num) => num != 10 using (var zero = File.OpenRead(Path.Combine(pathToImage, "0.png")))
// ? Properties.Resources.ResourceManager.GetObject("_" + num) as Image {
// : new[] Image imgOne = new Image(one);
// { Image imgZero = new Image(zero);
// (Properties.Resources.ResourceManager.GetObject("_" + 1) as Image),
// (Properties.Resources.ResourceManager.GetObject("_" + 0) as Image), return new[] { imgOne, imgZero }.Merge();
// }.Merge(); }
}
} }
} }

View File

@ -1,92 +1,70 @@
//using Discord.Commands; using Discord;
//using NadekoBot.Classes; using Discord.Commands;
//using NadekoBot.Extensions; using ImageProcessorCore;
//using NadekoBot.Modules.Gambling.Helpers; using NadekoBot.Attributes;
//using System; using NadekoBot.Extensions;
//using System.Collections.Concurrent; using NadekoBot.Modules.Gambling.Models;
//using System.Collections.Generic; using System;
//using System.Drawing; using System.Collections.Concurrent;
//using System.Threading.Tasks; using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
////todo drawing namespace NadekoBot.Modules.Gambling
//namespace NadekoBot.Modules.Gambling {
//{ [Group]
// public class DrawCommand : DiscordCommand public class DrawCommands
// { {
// public DrawCommand(DiscordModule module) : base(module) { } private static readonly ConcurrentDictionary<IGuild, Cards> AllDecks = new ConcurrentDictionary<IGuild, Cards>();
// public override void Init(CommandGroupBuilder cgb) private const string cardsPath = "data/images/cards";
// { [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// cgb.CreateCommand(Module.Prefix + "draw") [RequireContext(ContextType.Guild)]
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`") public async Task Draw(IUserMessage msg)
// .Parameter("count", ParameterType.Optional) {
// .Do(DrawCardFunc()); var channel = (ITextChannel)msg.Channel;
var cards = AllDecks.GetOrAdd(channel.Guild, (s) => new Cards());
var num = 1;
var images = new List<Image>();
var cardObjects = new List<Cards.Card>();
for (var i = 0; i < num; i++)
{
if (cards.CardPool.Count == 0 && i != 0)
{
await channel.SendMessageAsync("No more cards in a deck.").ConfigureAwait(false);
break;
}
var currentCard = cards.DrawACard();
cardObjects.Add(currentCard);
using (var stream = File.OpenRead(Path.Combine(cardsPath, currentCard.GetName())))
images.Add(new Image(stream));
}
MemoryStream bitmapStream = new MemoryStream();
images.Merge().SaveAsPng(bitmapStream);
bitmapStream.Position = 0;
await channel.SendFileAsync(bitmapStream, images.Count + " cards.jpg", $"{msg.Author.Mention} drew (TODO: CARD NAMES HERE)").ConfigureAwait(false);
if (cardObjects.Count == 5)
{
await channel.SendMessageAsync($"{msg.Author.Mention} `{Cards.GetHandValue(cardObjects)}`").ConfigureAwait(false);
}
}
// cgb.CreateCommand(Module.Prefix + "shuffle") [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
// .Alias(Module.Prefix + "sh") [RequireContext(ContextType.Guild)]
// .Description($"Reshuffles all cards back into the deck.|`{Prefix}shuffle`") public async Task Shuffle(IUserMessage imsg)
// .Do(ReshuffleTask()); {
// } var channel = (ITextChannel)imsg.Channel;
// private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>(); AllDecks.AddOrUpdate(channel.Guild,
(s) => new Cards(),
(s, c) =>
{
c.Restart();
return c;
});
// private static Func<CommandEventArgs, Task> ReshuffleTask() await channel.SendMessageAsync("`Deck reshuffled.`").ConfigureAwait(false);
// { }
// return async e => }
// { }
// AllDecks.AddOrUpdate(e.Server,
// (s) => new Cards(),
// (s, c) =>
// {
// c.Restart();
// return c;
// });
// await channel.SendMessageAsync("Deck reshuffled.").ConfigureAwait(false);
// };
// }
// private Func<CommandEventArgs, Task> DrawCardFunc() => async (e) =>
// {
// var cards = AllDecks.GetOrAdd(e.Server, (s) => new Cards());
// try
// {
// var num = 1;
// var isParsed = int.TryParse(count, out num);
// if (!isParsed || num < 2)
// {
// var c = cards.DrawACard();
// await e.Channel.SendFile(c.Name + ".jpg", (Properties.Resources.ResourceManager.GetObject(c.Name) as Image).ToStream()).ConfigureAwait(false);
// return;
// }
// if (num > 5)
// num = 5;
// var images = new List<Image>();
// var cardObjects = new List<Cards.Card>();
// for (var i = 0; i < num; i++)
// {
// if (cards.CardPool.Count == 0 && i != 0)
// {
// await channel.SendMessageAsync("No more cards in a deck.").ConfigureAwait(false);
// break;
// }
// var currentCard = cards.DrawACard();
// cardObjects.Add(currentCard);
// images.Add(Properties.Resources.ResourceManager.GetObject(currentCard.Name) as Image);
// }
// var bitmap = images.Merge();
// await e.Channel.SendFile(images.Count + " cards.jpg", bitmap.ToStream()).ConfigureAwait(false);
// if (cardObjects.Count == 5)
// {
// await channel.SendMessageAsync($"{umsg.Author.Mention} `{Cards.GetHandValue(cardObjects)}`").ConfigureAwait(false);
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine("Error drawing (a) card(s) " + ex.ToString());
// }
// };
// }
//}

View File

@ -14,7 +14,6 @@ using System.Security.Cryptography;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
//todo rewrite
namespace NadekoBot.Modules.Games namespace NadekoBot.Modules.Games
{ {
public partial class Games public partial class Games
@ -150,6 +149,7 @@ namespace NadekoBot.Modules.Games
var file = GetRandomCurrencyImagePath(); var file = GetRandomCurrencyImagePath();
IUserMessage msg; IUserMessage msg;
var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(Gambling.Gambling.CurrencyName[0]); var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(Gambling.Gambling.CurrencyName[0]);
//todo add prefix
var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using >pick"; var msgToSend = $"Oh how Nice! **{imsg.Author.Username}** planted {(vowelFirst ? "an" : "a")} {Gambling.Gambling.CurrencyName}. Pick it using >pick";
if (file == null) if (file == null)
{ {
@ -157,7 +157,6 @@ namespace NadekoBot.Modules.Games
} }
else else
{ {
//todo add prefix
msg = await channel.SendFileAsync(file, msgToSend).ConfigureAwait(false); msg = await channel.SendFileAsync(file, msgToSend).ConfigureAwait(false);
} }
plantedFlowers.AddOrUpdate(channel.Id, new List<IUserMessage>() { msg }, (id, old) => { old.Add(msg); return old; }); plantedFlowers.AddOrUpdate(channel.Id, new List<IUserMessage>() { msg }, (id, old) => { old.Add(msg); return old; });
@ -168,7 +167,7 @@ namespace NadekoBot.Modules.Games
[RequirePermission(GuildPermission.ManageMessages)] [RequirePermission(GuildPermission.ManageMessages)]
public async Task Gencurrency(IUserMessage imsg) public async Task Gencurrency(IUserMessage imsg)
{ {
var channel = imsg.Channel as ITextChannel; var channel = (ITextChannel)imsg.Channel;
if (channel == null) if (channel == null)
return; return;

View File

@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games
}).Where(t => t.Item1).Select(t => t.Item2).FirstOrDefault(); }).Where(t => t.Item1).Select(t => t.Item2).FirstOrDefault();
if (number < 0) if (number < 0)
return; return;
var triviaGame = new TriviaGame(channel.Guild, umsg.Channel as ITextChannel, showHints, number == 0 ? 10 : number); var triviaGame = new TriviaGame(channel.Guild, (ITextChannel)umsg.Channel, showHints, number == 0 ? 10 : number);
if (RunningTrivias.TryAdd(channel.Guild.Id, triviaGame)) if (RunningTrivias.TryAdd(channel.Guild.Id, triviaGame))
await channel.SendMessageAsync($"**Trivia game started! {triviaGame.WinRequirement} points needed to win.**").ConfigureAwait(false); await channel.SendMessageAsync($"**Trivia game started! {triviaGame.WinRequirement} points needed to win.**").ConfigureAwait(false);
else else

View File

@ -52,7 +52,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
public async Task Youtube(IUserMessage umsg, [Remainder] string query = null) public async Task Youtube(IUserMessage umsg, [Remainder] string query = null)
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
if (!(await ValidateQuery(umsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; if (!(await ValidateQuery(channel, query).ConfigureAwait(false))) return;
var result = (await _google.GetVideosByKeywordsAsync(query, 1)).FirstOrDefault(); var result = (await _google.GetVideosByKeywordsAsync(query, 1)).FirstOrDefault();
if (string.IsNullOrWhiteSpace(result)) if (string.IsNullOrWhiteSpace(result))
{ {
@ -68,7 +68,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
{ {
var channel = (ITextChannel)umsg.Channel; var channel = (ITextChannel)umsg.Channel;
if (!(await ValidateQuery(umsg.Channel as ITextChannel, query).ConfigureAwait(false))) return; if (!(await ValidateQuery(channel, query).ConfigureAwait(false))) return;
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false); await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
string result; string result;
try try

View File

@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ServerInfo(IUserMessage msg, string guild = null) public async Task ServerInfo(IUserMessage msg, string guild = null)
{ {
var channel = msg.Channel as ITextChannel; var channel = (ITextChannel)msg.Channel;
guild = guild?.ToUpperInvariant(); guild = guild?.ToUpperInvariant();
IGuild server; IGuild server;
if (guild == null) if (guild == null)
@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ChannelInfo(IUserMessage msg, ITextChannel channel = null) public async Task ChannelInfo(IUserMessage msg, ITextChannel channel = null)
{ {
var ch = channel ?? msg.Channel as ITextChannel; var ch = channel ?? (ITextChannel)msg.Channel;
if (ch == null) if (ch == null)
return; return;
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22); var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task UserInfo(IUserMessage msg, IGuildUser usr = null) public async Task UserInfo(IUserMessage msg, IGuildUser usr = null)
{ {
var channel = msg.Channel as ITextChannel; var channel = (ITextChannel)msg.Channel;
var user = usr ?? msg.Author as IGuildUser; var user = usr ?? msg.Author as IGuildUser;
if (user == null) if (user == null)
return; return;

View File

@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ShowQuote(IUserMessage umsg, string keyword) public async Task ShowQuote(IUserMessage umsg, string keyword)
{ {
var channel = umsg.Channel as ITextChannel; var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(keyword)) if (string.IsNullOrWhiteSpace(keyword))
return; return;
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task AddQuote(IUserMessage umsg, string keyword, [Remainder] string text) public async Task AddQuote(IUserMessage umsg, string keyword, [Remainder] string text)
{ {
var channel = umsg.Channel as ITextChannel; var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text)) if (string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(text))
return; return;
@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task DeleteQuote(IUserMessage umsg, string keyword) public async Task DeleteQuote(IUserMessage umsg, string keyword)
{ {
var channel = umsg.Channel as ITextChannel; var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(keyword)) if (string.IsNullOrWhiteSpace(keyword))
return; return;
@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task DelAllQuotes(IUserMessage umsg, string keyword) public async Task DelAllQuotes(IUserMessage umsg, string keyword)
{ {
var channel = umsg.Channel as ITextChannel; var channel = (ITextChannel)umsg.Channel;
if (string.IsNullOrWhiteSpace(keyword)) if (string.IsNullOrWhiteSpace(keyword))
return; return;

View File

@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Utility
StringBuilder builder = new StringBuilder("```\n"); StringBuilder builder = new StringBuilder("```\n");
var user = msg.Author as IGuildUser; var user = msg.Author as IGuildUser;
var perms = user.GetPermissions(msg.Channel as ITextChannel); var perms = user.GetPermissions((ITextChannel)msg.Channel);
foreach (var p in perms.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any())) foreach (var p in perms.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
{ {
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null).ToString()}"); builder.AppendLine($"{p.Name} : {p.GetValue(perms, null).ToString()}");
@ -111,21 +111,22 @@ namespace NadekoBot.Modules.Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task ServerId(IUserMessage msg) public async Task ServerId(IUserMessage msg)
{ {
await msg.Reply($"This server's ID is {(msg.Channel as ITextChannel).Guild.Id}").ConfigureAwait(false); await msg.Reply($"This server's ID is {((ITextChannel)msg.Channel).Guild.Id}").ConfigureAwait(false);
} }
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias] [LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Roles(IUserMessage msg, IGuildUser target = null) public async Task Roles(IUserMessage msg, IGuildUser target = null)
{ {
var guild = (msg.Channel as ITextChannel).Guild; var channel = (ITextChannel)msg.Channel;
var guild = channel.Guild;
if (target != null) if (target != null)
{ {
await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position))); await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)));
} }
else else
{ {
await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", (msg.Channel as ITextChannel).Guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r=>r.Position))); await msg.Reply("`List of roles:` \n• " + string.Join("\n• ", guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r=>r.Position)));
} }
} }

View File

@ -5622,7 +5622,7 @@ namespace NadekoBot.Resources {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice (unordered). If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y.. /// Looks up a localized string similar to Rolls X normal dice (up to 30) unordered. If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y..
/// </summary> /// </summary>
public static string rolluo_desc { public static string rolluo_desc {
get { get {

View File

@ -1408,7 +1408,7 @@
<value>rolluo</value> <value>rolluo</value>
</data> </data>
<data name="rolluo_desc" xml:space="preserve"> <data name="rolluo_desc" xml:space="preserve">
<value>Rolls 0-100. If you supply a number [x] it rolls up to 30 normal dice (unordered). If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y.</value> <value>Rolls X normal dice (up to 30) unordered. If you split 2 numbers with letter d (xdy) it will roll x dice from 1 to y.</value>
</data> </data>
<data name="rolluo_summary" xml:space="preserve"> <data name="rolluo_summary" xml:space="preserve">
<value>`$rolluo` or `$rolluo 7` or `$rolluo 3d5`</value> <value>`$rolluo` or `$rolluo 7` or `$rolluo 3d5`</value>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1006 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1,5 +1,6 @@
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using ImageProcessorCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -266,5 +267,28 @@ namespace NadekoBot.Extensions
public static ulong GB(this ulong value) => value.MB() * 1000; public static ulong GB(this ulong value) => value.MB() * 1000;
public static string Unmention(this string str) => str.Replace("@", "ම"); public static string Unmention(this string str) => str.Replace("@", "ම");
public static Image Merge(this IEnumerable<Image> images)
{
var imgList = images.ToList();
var canvas = new Image(imgList.Sum(img => img.Width), imgList.Max(img => img.Height));
var canvasPixels = canvas.Lock();
int offsetX = 0;
foreach (var img in imgList.Select(img=>img.Lock()))
{
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
canvasPixels[i + offsetX, j] = img[i, j];
}
}
offsetX += img.Width;
}
return canvas;
}
} }
} }

View File

@ -31,7 +31,8 @@
"Microsoft.EntityFrameworkCore": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0", "Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
"CoreCLR-NCalc": "2.1.0" "CoreCLR-NCalc": "2.1.0",
"ImageProcessorCore": "1.0.0-alpha1039"
}, },
"tools": { "tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"

View File

@ -146,6 +146,34 @@
"lib/netstandard1.3/Google.Apis.YouTube.v3.dll": {} "lib/netstandard1.3/Google.Apis.YouTube.v3.dll": {}
} }
}, },
"ImageProcessorCore/1.0.0-alpha1039": {
"type": "package",
"dependencies": {
"System.Collections": "4.0.11",
"System.Diagnostics.Debug": "4.0.11",
"System.Diagnostics.Tools": "4.0.1",
"System.IO": "4.1.0",
"System.IO.Compression": "4.1.0",
"System.Linq": "4.1.0",
"System.Numerics.Vectors": "4.1.1",
"System.ObjectModel": "4.0.12",
"System.Resources.ResourceManager": "4.0.1",
"System.Runtime.CompilerServices.Unsafe": "4.0.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.InteropServices": "4.1.0",
"System.Runtime.Numerics": "4.0.1",
"System.Text.Encoding.Extensions": "4.0.11",
"System.Threading": "4.0.11",
"System.Threading.Tasks": "4.0.11",
"System.Threading.Tasks.Parallel": "4.0.1"
},
"compile": {
"lib/netstandard1.1/ImageProcessorCore.dll": {}
},
"runtime": {
"lib/netstandard1.1/ImageProcessorCore.dll": {}
}
},
"Libuv/1.9.0": { "Libuv/1.9.0": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -2380,6 +2408,18 @@
"lib/portable-net45+win8+wp80+wpa81/_._": {} "lib/portable-net45+win8+wp80+wpa81/_._": {}
} }
}, },
"System.Runtime.CompilerServices.Unsafe/4.0.0": {
"type": "package",
"dependencies": {
"System.Runtime": "4.1.0"
},
"compile": {
"lib/netstandard1.0/System.Runtime.CompilerServices.Unsafe.dll": {}
},
"runtime": {
"lib/netstandard1.0/System.Runtime.CompilerServices.Unsafe.dll": {}
}
},
"System.Runtime.Extensions/4.1.0": { "System.Runtime.Extensions/4.1.0": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -3371,6 +3411,16 @@
"lib/portable-net45+netcore45+wpa81+wp8/Google.Apis.YouTube.v3.xml" "lib/portable-net45+netcore45+wpa81+wp8/Google.Apis.YouTube.v3.xml"
] ]
}, },
"ImageProcessorCore/1.0.0-alpha1039": {
"sha512": "nNLCXniPRY+m59tIQRA71uQQGmbtL0GASzex7zIz0PH6M1/yHxgYtlXZQmeyfkJIrGhJmqJDlYwEu3aZxlTfHw==",
"type": "package",
"path": "ImageProcessorCore/1.0.0-alpha1039",
"files": [
"ImageProcessorCore.1.0.0-alpha1039.nupkg.sha512",
"ImageProcessorCore.nuspec",
"lib/netstandard1.1/ImageProcessorCore.dll"
]
},
"Libuv/1.9.0": { "Libuv/1.9.0": {
"sha512": "9Q7AaqtQhS8JDSIvRBt6ODSLWDBI4c8YxNxyCQemWebBFUtBbc6M5Vi5Gz1ZyIUlTW3rZK9bIr5gnVyv0z7a2Q==", "sha512": "9Q7AaqtQhS8JDSIvRBt6ODSLWDBI4c8YxNxyCQemWebBFUtBbc6M5Vi5Gz1ZyIUlTW3rZK9bIr5gnVyv0z7a2Q==",
"type": "package", "type": "package",
@ -7249,6 +7299,19 @@
"ref/xamarinwatchos10/_._" "ref/xamarinwatchos10/_._"
] ]
}, },
"System.Runtime.CompilerServices.Unsafe/4.0.0": {
"sha512": "LDvjxLx2fkThOFo/SC+901fJrh5artALmgzeSqnVxzvFp4q3HO8BkeLyshPdcbs5zpN7Xh9G23M6sDhgIPbG9A==",
"type": "package",
"path": "System.Runtime.CompilerServices.Unsafe/4.0.0",
"files": [
"System.Runtime.CompilerServices.Unsafe.4.0.0.nupkg.sha512",
"System.Runtime.CompilerServices.Unsafe.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/netstandard1.0/System.Runtime.CompilerServices.Unsafe.dll",
"lib/netstandard1.0/System.Runtime.CompilerServices.Unsafe.xml"
]
},
"System.Runtime.Extensions/4.1.0": { "System.Runtime.Extensions/4.1.0": {
"sha512": "CUOHjTT/vgP0qGW22U4/hDlOqXmcPq5YicBaXdUR2UiUoLwBT+olO6we4DVbq57jeX5uXH2uerVZhf0qGj+sVQ==", "sha512": "CUOHjTT/vgP0qGW22U4/hDlOqXmcPq5YicBaXdUR2UiUoLwBT+olO6we4DVbq57jeX5uXH2uerVZhf0qGj+sVQ==",
"type": "package", "type": "package",
@ -9037,6 +9100,7 @@
"Google.Apis.Customsearch.v1 >= 1.16.0.466", "Google.Apis.Customsearch.v1 >= 1.16.0.466",
"Google.Apis.Urlshortener.v1 >= 1.15.0.138", "Google.Apis.Urlshortener.v1 >= 1.15.0.138",
"Google.Apis.YouTube.v3 >= 1.15.0.582", "Google.Apis.YouTube.v3 >= 1.15.0.582",
"ImageProcessorCore >= 1.0.0-alpha1039",
"Microsoft.EntityFrameworkCore >= 1.0.0", "Microsoft.EntityFrameworkCore >= 1.0.0",
"Microsoft.EntityFrameworkCore.Design >= 1.0.0-preview2-final", "Microsoft.EntityFrameworkCore.Design >= 1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Sqlite >= 1.0.0", "Microsoft.EntityFrameworkCore.Sqlite >= 1.0.0",