Roll commands done. Draw commands done. Untested.
@ -432,7 +432,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
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);
|
||||
|
||||
}
|
||||
@ -467,7 +467,7 @@ namespace NadekoBot.Modules.Administration
|
||||
[RequirePermission(ChannelPermission.ManageMessages)]
|
||||
public async Task Prune(IUserMessage msg, int count)
|
||||
{
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
await (msg as IUserMessage).DeleteAsync();
|
||||
while (count > 0)
|
||||
{
|
||||
@ -485,7 +485,7 @@ namespace NadekoBot.Modules.Administration
|
||||
[RequireContext(ContextType.Guild)]
|
||||
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;
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit)).Where(m => m.Author == user);
|
||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||
|
@ -27,11 +27,8 @@ namespace NadekoBot.Modules.ClashOfClans
|
||||
uow.ClashOfClans
|
||||
.GetAll()
|
||||
.Select(cw => {
|
||||
cw.Channel = NadekoBot.Client.GetGuilds()
|
||||
.FirstOrDefault(s => s.Id == cw.GuildId)?
|
||||
.GetChannels()
|
||||
.FirstOrDefault(c => c.Id == cw.ChannelId)
|
||||
as ITextChannel;
|
||||
cw.Channel = NadekoBot.Client.GetGuild(cw.GuildId)
|
||||
?.GetTextChannel(cw.ChannelId);
|
||||
cw.Bases.Capacity = cw.Size;
|
||||
return cw;
|
||||
})
|
||||
@ -318,11 +315,8 @@ namespace NadekoBot.Modules.ClashOfClans
|
||||
Bases = new List<ClashCaller>(size),
|
||||
GuildId = serverId,
|
||||
ChannelId = channelId,
|
||||
Channel = NadekoBot.Client.GetGuilds()
|
||||
.FirstOrDefault(s => s.Id == serverId)?
|
||||
.GetChannels()
|
||||
.FirstOrDefault(c => c.Id == channelId)
|
||||
as ITextChannel
|
||||
Channel = NadekoBot.Client.GetGuild(serverId)
|
||||
?.GetTextChannel(channelId)
|
||||
};
|
||||
uow.ClashOfClans.Add(cw);
|
||||
await uow.CompleteAsync();
|
||||
|
@ -1,11 +1,14 @@
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using ImageProcessorCore;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Resources;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -17,94 +20,191 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Roll(IUserMessage umsg, [Remainder] string arg = null) =>
|
||||
publicRoll(umsg, arg, true);
|
||||
public async Task Roll(IUserMessage umsg)
|
||||
{
|
||||
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]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Rolluo(IUserMessage umsg, [Remainder] string arg = null) =>
|
||||
publicRoll(umsg, arg, false);
|
||||
//todo drawing
|
||||
private async Task publicRoll(IUserMessage umsg, string arg, bool ordered)
|
||||
public async Task Roll(IUserMessage umsg, int num)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
var r = new NadekoRandom();
|
||||
//if (string.IsNullOrWhiteSpace(arg))
|
||||
//{
|
||||
// var gen = r.Next(0, 101);
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
// var num1 = gen / 10;
|
||||
// var num2 = gen % 10;
|
||||
var ordered = true;
|
||||
|
||||
// var imageStream = await new Image[2] { GetDice(num1), GetDice(num2) }.Merge().ToStream(ImageFormat.Png);
|
||||
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;
|
||||
}
|
||||
|
||||
// await channel.SendFileAsync(imageStream, "dice.png").ConfigureAwait(false);
|
||||
// return;
|
||||
//}
|
||||
Match m;
|
||||
if ((m = dndRegex.Match(arg)).Length != 0)
|
||||
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);
|
||||
}
|
||||
//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 n2;
|
||||
if (int.TryParse(m.Groups["n1"].ToString(), out n1) &&
|
||||
int.TryParse(m.Groups["n2"].ToString(), out 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] = r.Next(1, n2 + 1);
|
||||
arr[i] = rng.Next(1, n2 + 1);
|
||||
}
|
||||
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();
|
||||
// await channel.SendMessageAsync(values.Count + " Dice rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**").ConfigureAwait(false);
|
||||
// await channel.SendFileAsync("dice.png", bitmap.ToStream(ImageFormat.Png)).ConfigureAwait(false);
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
// await channel.SendMessageAsync("Please enter a number of dice to roll.").ConfigureAwait(false);
|
||||
//}
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Rolluo(IUserMessage umsg, string arg = "")
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
if (channel == null)
|
||||
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]
|
||||
@ -113,7 +213,6 @@ namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
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
|
||||
//private Image GetDice(int num) => num != 10
|
||||
// ? Properties.Resources.ResourceManager.GetObject("_" + num) as Image
|
||||
// : new[]
|
||||
// {
|
||||
// (Properties.Resources.ResourceManager.GetObject("_" + 1) as Image),
|
||||
// (Properties.Resources.ResourceManager.GetObject("_" + 0) as Image),
|
||||
// }.Merge();
|
||||
using (var one = File.OpenRead(Path.Combine(pathToImage, "1.png")))
|
||||
using (var zero = File.OpenRead(Path.Combine(pathToImage, "0.png")))
|
||||
{
|
||||
Image imgOne = new Image(one);
|
||||
Image imgZero = new Image(zero);
|
||||
|
||||
return new[] { imgOne, imgZero }.Merge();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,92 +1,70 @@
|
||||
//using Discord.Commands;
|
||||
//using NadekoBot.Classes;
|
||||
//using NadekoBot.Extensions;
|
||||
//using NadekoBot.Modules.Gambling.Helpers;
|
||||
//using System;
|
||||
//using System.Collections.Concurrent;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Drawing;
|
||||
//using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using ImageProcessorCore;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Modules.Gambling.Models;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
////todo drawing
|
||||
//namespace NadekoBot.Modules.Gambling
|
||||
//{
|
||||
// public class DrawCommand : DiscordCommand
|
||||
// {
|
||||
// public DrawCommand(DiscordModule module) : base(module) { }
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
[Group]
|
||||
public class DrawCommands
|
||||
{
|
||||
private static readonly ConcurrentDictionary<IGuild, Cards> AllDecks = new ConcurrentDictionary<IGuild, Cards>();
|
||||
|
||||
// public override void Init(CommandGroupBuilder cgb)
|
||||
// {
|
||||
// cgb.CreateCommand(Module.Prefix + "draw")
|
||||
// .Description($"Draws a card from the deck.If you supply number [x], she draws up to 5 cards from the deck. | `{Prefix}draw [x]`")
|
||||
// .Parameter("count", ParameterType.Optional)
|
||||
// .Do(DrawCardFunc());
|
||||
private const string cardsPath = "data/images/cards";
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Draw(IUserMessage msg)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
var cards = AllDecks.GetOrAdd(channel.Guild, (s) => new Cards());
|
||||
|
||||
// cgb.CreateCommand(Module.Prefix + "shuffle")
|
||||
// .Alias(Module.Prefix + "sh")
|
||||
// .Description($"Reshuffles all cards back into the deck.|`{Prefix}shuffle`")
|
||||
// .Do(ReshuffleTask());
|
||||
// }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// private static readonly ConcurrentDictionary<Discord.Server, Cards> AllDecks = new ConcurrentDictionary<Discord.Server, Cards>();
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Shuffle(IUserMessage imsg)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
// private static Func<CommandEventArgs, Task> ReshuffleTask()
|
||||
// {
|
||||
// return async e =>
|
||||
// {
|
||||
// AllDecks.AddOrUpdate(e.Server,
|
||||
// (s) => new Cards(),
|
||||
// (s, c) =>
|
||||
// {
|
||||
// c.Restart();
|
||||
// return c;
|
||||
// });
|
||||
AllDecks.AddOrUpdate(channel.Guild,
|
||||
(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());
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
await channel.SendMessageAsync("`Deck reshuffled.`").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
//todo rewrite
|
||||
namespace NadekoBot.Modules.Games
|
||||
{
|
||||
public partial class Games
|
||||
@ -150,6 +149,7 @@ namespace NadekoBot.Modules.Games
|
||||
var file = GetRandomCurrencyImagePath();
|
||||
IUserMessage msg;
|
||||
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";
|
||||
if (file == null)
|
||||
{
|
||||
@ -157,7 +157,6 @@ namespace NadekoBot.Modules.Games
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo add prefix
|
||||
msg = await channel.SendFileAsync(file, msgToSend).ConfigureAwait(false);
|
||||
}
|
||||
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)]
|
||||
public async Task Gencurrency(IUserMessage imsg)
|
||||
{
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
if (channel == null)
|
||||
return;
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Games
|
||||
}).Where(t => t.Item1).Select(t => t.Item2).FirstOrDefault();
|
||||
if (number < 0)
|
||||
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))
|
||||
await channel.SendMessageAsync($"**Trivia game started! {triviaGame.WinRequirement} points needed to win.**").ConfigureAwait(false);
|
||||
else
|
||||
|
@ -52,7 +52,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
public async Task Youtube(IUserMessage umsg, [Remainder] string query = null)
|
||||
{
|
||||
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();
|
||||
if (string.IsNullOrWhiteSpace(result))
|
||||
{
|
||||
@ -68,7 +68,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
{
|
||||
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);
|
||||
string result;
|
||||
try
|
||||
|
@ -16,7 +16,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerInfo(IUserMessage msg, string guild = null)
|
||||
{
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
guild = guild?.ToUpperInvariant();
|
||||
IGuild server;
|
||||
if (guild == null)
|
||||
@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
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)
|
||||
return;
|
||||
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)]
|
||||
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;
|
||||
if (user == null)
|
||||
return;
|
||||
|
@ -18,7 +18,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ShowQuote(IUserMessage umsg, string keyword)
|
||||
{
|
||||
var channel = umsg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
return;
|
||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
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))
|
||||
return;
|
||||
@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task DeleteQuote(IUserMessage umsg, string keyword)
|
||||
{
|
||||
var channel = umsg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
return;
|
||||
@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task DelAllQuotes(IUserMessage umsg, string keyword)
|
||||
{
|
||||
var channel = umsg.Channel as ITextChannel;
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
return;
|
||||
|
@ -83,7 +83,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
StringBuilder builder = new StringBuilder("```\n");
|
||||
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()))
|
||||
{
|
||||
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null).ToString()}");
|
||||
@ -111,21 +111,22 @@ namespace NadekoBot.Modules.Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
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]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
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)
|
||||
{
|
||||
await msg.Reply($"`List of roles for **{target.Username}**:` \n• " + string.Join("\n• ", target.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => r.Position)));
|
||||
}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5622,7 +5622,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string rolluo_desc {
|
||||
get {
|
||||
|
@ -1408,7 +1408,7 @@
|
||||
<value>rolluo</value>
|
||||
</data>
|
||||
<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 name="rolluo_summary" xml:space="preserve">
|
||||
<value>`$rolluo` or `$rolluo 7` or `$rolluo 3d5`</value>
|
||||
|
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.6 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 6.0 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 6.4 KiB |
Before Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 9.6 KiB |
Before Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 9.4 KiB |
Before Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1006 B |
Before Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 340 B |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 18 KiB |
@ -1,5 +1,6 @@
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using ImageProcessorCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -266,5 +267,28 @@ namespace NadekoBot.Extensions
|
||||
public static ulong GB(this ulong value) => value.MB() * 1000;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,8 @@
|
||||
"Microsoft.EntityFrameworkCore": "1.0.0",
|
||||
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
|
||||
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0",
|
||||
"CoreCLR-NCalc": "2.1.0"
|
||||
"CoreCLR-NCalc": "2.1.0",
|
||||
"ImageProcessorCore": "1.0.0-alpha1039"
|
||||
},
|
||||
"tools": {
|
||||
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
|
||||
|
@ -146,6 +146,34 @@
|
||||
"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": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
@ -2380,6 +2408,18 @@
|
||||
"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": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
@ -3371,6 +3411,16 @@
|
||||
"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": {
|
||||
"sha512": "9Q7AaqtQhS8JDSIvRBt6ODSLWDBI4c8YxNxyCQemWebBFUtBbc6M5Vi5Gz1ZyIUlTW3rZK9bIr5gnVyv0z7a2Q==",
|
||||
"type": "package",
|
||||
@ -7249,6 +7299,19 @@
|
||||
"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": {
|
||||
"sha512": "CUOHjTT/vgP0qGW22U4/hDlOqXmcPq5YicBaXdUR2UiUoLwBT+olO6we4DVbq57jeX5uXH2uerVZhf0qGj+sVQ==",
|
||||
"type": "package",
|
||||
@ -9037,6 +9100,7 @@
|
||||
"Google.Apis.Customsearch.v1 >= 1.16.0.466",
|
||||
"Google.Apis.Urlshortener.v1 >= 1.15.0.138",
|
||||
"Google.Apis.YouTube.v3 >= 1.15.0.582",
|
||||
"ImageProcessorCore >= 1.0.0-alpha1039",
|
||||
"Microsoft.EntityFrameworkCore >= 1.0.0",
|
||||
"Microsoft.EntityFrameworkCore.Design >= 1.0.0-preview2-final",
|
||||
"Microsoft.EntityFrameworkCore.Sqlite >= 1.0.0",
|
||||
|