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;
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);

View File

@@ -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();

View File

@@ -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;
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);
// return;
//}
Match m;
if ((m = dndRegex.Match(arg)).Length != 0)
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]
@@ -112,8 +212,7 @@ namespace NadekoBot.Modules.Gambling
public async Task NRoll(IUserMessage umsg, [Remainder] string range)
{
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();
}
}
}
}

View File

@@ -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());
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")
// .Alias(Module.Prefix + "sh")
// .Description($"Reshuffles all cards back into the deck.|`{Prefix}shuffle`")
// .Do(ReshuffleTask());
// }
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task Shuffle(IUserMessage imsg)
{
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()
// {
// 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());
// }
// };
// }
//}
await channel.SendMessageAsync("`Deck reshuffled.`").ConfigureAwait(false);
}
}
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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)));
}
}