Module, Command, PermissionAction typereaders, fixed HS (thanks to fearnlj01)

This commit is contained in:
Kwoth
2016-09-16 19:20:37 +02:00
parent 8fa90348a3
commit 48513daa64
7 changed files with 182 additions and 7 deletions

View File

@@ -0,0 +1,35 @@
using Discord.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
namespace NadekoBot.Modules.Permissions
{
public class PermissionAction
{
public static PermissionAction Enable => new PermissionAction(true);
public static PermissionAction Disable => new PermissionAction(false);
public bool Value { get; }
public PermissionAction(bool value)
{
this.Value = value;
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}
return this.Value == ((PermissionAction)obj).Value;
}
public override int GetHashCode() => Value.GetHashCode();
}
}

View File

@@ -0,0 +1,39 @@
using NadekoBot.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.WebSocket;
using NadekoBot.Services;
using Discord;
namespace NadekoBot.Modules.Permissions
{
[NadekoModule("Permissions", ";")]
public class Permissions : DiscordModule
{
public Permissions(ILocalization loc, CommandService cmds, DiscordSocketClient client) : base(loc, cmds, client)
{
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task UsrCmd(IUserMessage imsg, Command command, PermissionAction action, IGuildUser user)
{
var channel = (ITextChannel)imsg.Channel;
await channel.SendMessageAsync($"{command.Text} {action.Value} {user}");
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
[RequireContext(ContextType.Guild)]
public async Task UsrMdl(IUserMessage imsg, Module module, PermissionAction action, IGuildUser user)
{
var channel = (ITextChannel)imsg.Channel;
await channel.SendMessageAsync($"{module.Name} {action.Value} {user}");
}
}
}

View File

@@ -229,8 +229,7 @@ $@"🌍 **Weather for** 【{obj["target"]}】
var images = new List<Image>();
if (items == null)
throw new KeyNotFoundException("Cannot find a card by that name");
var cnt = 0;
foreach (var item in items.TakeWhile(item => cnt++ < 4).Where(item => item.HasValues && item["img"] != null))
foreach (var item in items.Where(item => item.HasValues && item["img"] != null).Take(4))
{
using (var sr =await http.GetStreamAsync(item["img"].ToString()))
{