Woops, didn't push correctly. Also added owner only commands now.
This commit is contained in:
parent
94b5c411b9
commit
81753255b9
@ -1,11 +1,12 @@
|
||||
//using System.Threading.Tasks;
|
||||
//using Discord.Commands;
|
||||
//using Discord;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord;
|
||||
|
||||
//namespace NadekoBot.Attributes {
|
||||
// public class OwnerOnlyAttribute : PreconditionAttribute
|
||||
// {
|
||||
// public override Task<PreconditionResult> CheckPermissions(IUserMessage context, Command executingCommand, object moduleInstance) =>
|
||||
// Task.FromResult((NadekoBot.Credentials.IsOwner(context.Author) ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
|
||||
// }
|
||||
//}
|
||||
namespace NadekoBot.Attributes
|
||||
{
|
||||
public class OwnerOnlyAttribute : PreconditionAttribute
|
||||
{
|
||||
public override Task<PreconditionResult> CheckPermissions(IUserMessage context, Command executingCommand, object moduleInstance) =>
|
||||
Task.FromResult((NadekoBot.Credentials.IsOwner(context.Author) ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
|
||||
}
|
||||
}
|
@ -13,6 +13,9 @@ using System.Text.RegularExpressions;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Net.Http;
|
||||
using ImageProcessorCore;
|
||||
using System.IO;
|
||||
|
||||
namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
@ -46,19 +49,21 @@ namespace NadekoBot.Modules.Administration
|
||||
_log.Warn(ex, "Delmsgoncmd errored...");
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Restart(IUserMessage umsg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Restart(IUserMessage umsg)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
// await channel.SendMessageAsync("`Restarting in 2 seconds...`");
|
||||
// await Task.Delay(2000);
|
||||
// System.Diagnostics.Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location);
|
||||
// Environment.Exit(0);
|
||||
//}
|
||||
await channel.SendMessageAsync("`Restarting in 2 seconds...`");
|
||||
await Task.Delay(2000);
|
||||
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo {
|
||||
Arguments = "dotnet " + System.Reflection.Assembly.GetEntryAssembly().Location
|
||||
});
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@ -205,7 +210,7 @@ namespace NadekoBot.Modules.Administration
|
||||
var green = Convert.ToByte(rgb ? int.Parse(args[2]) : Convert.ToInt32(arg1.Substring(2, 2), 16));
|
||||
var blue = Convert.ToByte(rgb ? int.Parse(args[3]) : Convert.ToInt32(arg1.Substring(4, 2), 16));
|
||||
|
||||
await role.ModifyAsync(r => r.Color = new Color(red, green, blue).RawValue).ConfigureAwait(false);
|
||||
await role.ModifyAsync(r => r.Color = new Discord.Color(red, green, blue).RawValue).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Role {role.Name}'s color has been changed.").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
@ -455,7 +460,7 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
var user = await channel.Guild.GetCurrentUserAsync();
|
||||
var user = channel.Guild.GetCurrentUser();
|
||||
|
||||
var enumerable = (await umsg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
|
||||
await umsg.Channel.DeleteMessagesAsync(enumerable);
|
||||
@ -483,6 +488,7 @@ namespace NadekoBot.Modules.Administration
|
||||
//prune @user [x]
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequirePermission(ChannelPermission.ManageMessages)]
|
||||
public async Task Prune(IUserMessage msg, IGuildUser user, int count = 100)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
@ -490,149 +496,163 @@ namespace NadekoBot.Modules.Administration
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit)).Where(m => m.Author == user);
|
||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||
}
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Die(IUserMessage umsg)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
// await channel.SendMessageAsync("`Shutting down.`").ConfigureAwait(false);
|
||||
// await Task.Delay(2000).ConfigureAwait(false);
|
||||
// Environment.Exit(0);
|
||||
//}
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Die(IUserMessage umsg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Setname(IUserMessage umsg, [Remainder] string newName = null)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
await channel.SendMessageAsync("`Shutting down.`").ConfigureAwait(false);
|
||||
await Task.Delay(2000).ConfigureAwait(false);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
//}
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Setname(IUserMessage umsg, [Remainder] string newName)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
return;
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task NewAvatar(IUserMessage umsg, [Remainder] string img = null)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
await NadekoBot.Client.GetCurrentUser().ModifyAsync(u => u.Username = newName).ConfigureAwait(false);
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(img))
|
||||
// return;
|
||||
// // Gather user provided URL.
|
||||
// var avatarAddress = img;
|
||||
// var imageStream = await SearchHelper.GetResponseStreamAsync(avatarAddress).ConfigureAwait(false);
|
||||
// var image = System.Drawing.Image.FromStream(imageStream);
|
||||
// await client.CurrentUser.Edit("", avatar: image.ToStream()).ConfigureAwait(false);
|
||||
await channel.SendMessageAsync($"Successfully changed name to {newName}").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// // Send confirm.
|
||||
// await channel.SendMessageAsync("New avatar set.").ConfigureAwait(false);
|
||||
//}
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task NewAvatar(IUserMessage umsg, [Remainder] string img = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task SetGame(IUserMessage umsg, [Remainder] string game = null)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
if (string.IsNullOrWhiteSpace(img))
|
||||
return;
|
||||
|
||||
// game = game ?? "";
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
using (var sr = await http.GetStreamAsync(img))
|
||||
{
|
||||
var imgStream = new MemoryStream();
|
||||
await sr.CopyToAsync(imgStream);
|
||||
imgStream.Position = 0;
|
||||
|
||||
// client.SetGame(set_game);
|
||||
//}
|
||||
await NadekoBot.Client.GetCurrentUser().ModifyAsync(u => u.Avatar = imgStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
await channel.SendMessageAsync("New avatar set.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(msg))
|
||||
// return;
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task SetGame(IUserMessage umsg, [Remainder] string game = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
// var ids = where.Split('|');
|
||||
// if (ids.Length != 2)
|
||||
// return;
|
||||
// var sid = ulong.Parse(ids[0]);
|
||||
// var server = NadekoBot.Client.Servers.Where(s => s.Id == sid).FirstOrDefault();
|
||||
game = game ?? "";
|
||||
|
||||
// if (server == null)
|
||||
// return;
|
||||
await NadekoBot.Client.GetCurrentUser().ModifyStatusAsync(u => u.Game = new Game(game)).ConfigureAwait(false);
|
||||
|
||||
// if (ids[1].ToUpperInvariant().StartsWith("C:"))
|
||||
// {
|
||||
// var cid = ulong.Parse(ids[1].Substring(2));
|
||||
// var channel = server.TextChannels.Where(c => c.Id == cid).FirstOrDefault();
|
||||
// if (channel == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// await channel.SendMessageAsync(msg);
|
||||
// }
|
||||
// else if (ids[1].ToUpperInvariant().StartsWith("U:"))
|
||||
// {
|
||||
// var uid = ulong.Parse(ids[1].Substring(2));
|
||||
// var user = server.Users.Where(u => u.Id == uid).FirstOrDefault();
|
||||
// if (user == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// await user.SendMessageAsync(msg);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// await channel.SendMessageAsync("`Invalid format.`");
|
||||
// }
|
||||
//}
|
||||
await channel.SendMessageAsync("New game set.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Announce(IUserMessage umsg, [Remainder] string message)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Send(IUserMessage umsg, string where, [Remainder] string msg = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
// foreach (var ch in (await _client.GetGuildsAsync().ConfigureAwait(false)).Select(async g => await g.GetDefaultChannelAsync().ConfigureAwait(false)))
|
||||
// {
|
||||
// await channel.SendMessageAsync(message).ConfigureAwait(false);
|
||||
// }
|
||||
if (string.IsNullOrWhiteSpace(msg))
|
||||
return;
|
||||
|
||||
// await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
||||
//}
|
||||
var ids = where.Split('|');
|
||||
if (ids.Length != 2)
|
||||
return;
|
||||
var sid = ulong.Parse(ids[0]);
|
||||
var server = NadekoBot.Client.GetGuilds().Where(s => s.Id == sid).FirstOrDefault();
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task SaveChat(IUserMessage umsg, int cnt)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
if (server == null)
|
||||
return;
|
||||
|
||||
// ulong? lastmsgId = null;
|
||||
// var sb = new StringBuilder();
|
||||
// var msgs = new List<IUserMessage>(cnt);
|
||||
// while (cnt > 0)
|
||||
// {
|
||||
// var dlcnt = cnt < 100 ? cnt : 100;
|
||||
// IReadOnlyCollection<IUserMessage> dledMsgs;
|
||||
// if (lastmsgId == null)
|
||||
// dledMsgs = await umsg.Channel.GetMessagesAsync(cnt).ConfigureAwait(false);
|
||||
// else
|
||||
// dledMsgs = await umsg.Channel.GetMessagesAsync(lastmsgId.Value, Direction.Before, dlcnt);
|
||||
if (ids[1].ToUpperInvariant().StartsWith("C:"))
|
||||
{
|
||||
var cid = ulong.Parse(ids[1].Substring(2));
|
||||
var ch = server.GetTextChannels().Where(c => c.Id == cid).FirstOrDefault();
|
||||
if (ch == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await ch.SendMessageAsync(msg);
|
||||
}
|
||||
else if (ids[1].ToUpperInvariant().StartsWith("U:"))
|
||||
{
|
||||
var uid = ulong.Parse(ids[1].Substring(2));
|
||||
var user = server.GetUsers().Where(u => u.Id == uid).FirstOrDefault();
|
||||
if (user == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await user.SendMessageAsync(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
await channel.SendMessageAsync("`Invalid format.`");
|
||||
}
|
||||
}
|
||||
|
||||
// if (!dledMsgs.Any())
|
||||
// break;
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Announce(IUserMessage umsg, [Remainder] string message)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
// msgs.AddRange(dledMsgs);
|
||||
// lastmsgId = msgs[msgs.Count - 1].Id;
|
||||
// cnt -= 100;
|
||||
// }
|
||||
// var title = $"Chatlog-{channel.Guild.Name}/#{channel.Name}-{DateTime.Now}.txt";
|
||||
// await (umsg.Author as IGuildUser).SendFileAsync(
|
||||
// await JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream().ConfigureAwait(false),
|
||||
// title, title).ConfigureAwait(false);
|
||||
//}
|
||||
foreach (var ch in (await _client.GetGuildsAsync().ConfigureAwait(false)).Select(async g => await g.GetDefaultChannelAsync().ConfigureAwait(false)))
|
||||
{
|
||||
await channel.SendMessageAsync(message).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync(":ok:").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task SaveChat(IUserMessage umsg, int cnt)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
ulong? lastmsgId = null;
|
||||
var sb = new StringBuilder();
|
||||
var msgs = new List<IMessage>(cnt);
|
||||
while (cnt > 0)
|
||||
{
|
||||
var dlcnt = cnt < 100 ? cnt : 100;
|
||||
IReadOnlyCollection<IMessage> dledMsgs;
|
||||
if (lastmsgId == null)
|
||||
dledMsgs = await umsg.Channel.GetMessagesAsync(cnt).ConfigureAwait(false);
|
||||
else
|
||||
dledMsgs = await umsg.Channel.GetMessagesAsync(lastmsgId.Value, Direction.Before, dlcnt);
|
||||
|
||||
if (!dledMsgs.Any())
|
||||
break;
|
||||
|
||||
msgs.AddRange(dledMsgs);
|
||||
lastmsgId = msgs[msgs.Count - 1].Id;
|
||||
cnt -= 100;
|
||||
}
|
||||
var title = $"Chatlog-{channel.Guild.Name}/#{channel.Name}-{DateTime.Now}.txt";
|
||||
await (umsg.Author as IGuildUser).SendFileAsync(
|
||||
await JsonConvert.SerializeObject(new { Messages = msgs.Select(s => s.ToString()) }, Formatting.Indented).ToStream().ConfigureAwait(false),
|
||||
title, title).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
@ -691,5 +711,17 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
await channel.SendMessageAsync($"Successfuly added a new donator. Total donated amount from this user: {don.Amount} 👑").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Leave(IUserMessage imsg, [Remainder] IGuild guild)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
await guild.LeaveAsync();
|
||||
|
||||
await channel.SendMessageAsync($"Left guild **{guild.Name}**\nId: `{guild.Id}`.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Attributes;
|
||||
using NadekoBot.Extensions;
|
||||
using NadekoBot.Services;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@ -52,23 +53,23 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
private string GetText(IGuild server, ITextChannel channel, IGuildUser user, IUserMessage message) =>
|
||||
$"**{server.Name} | {channel.Name}** `{user.Username}`: " + message.Content;
|
||||
|
||||
|
||||
public static readonly ConcurrentDictionary<int, HashSet<ITextChannel>> Subscribers = new ConcurrentDictionary<int, HashSet<ITextChannel>>();
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Scsc(IUserMessage msg)
|
||||
//{
|
||||
// var channel = (ITextChannel)msg.Channel;
|
||||
// var token = new NadekoRandom().Next();
|
||||
// var set = new HashSet<ITextChannel>();
|
||||
// if (Subscribers.TryAdd(token, set))
|
||||
// {
|
||||
// set.Add(channel);
|
||||
// await ((IGuildUser)msg.Author).SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false);
|
||||
// }
|
||||
//}
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Scsc(IUserMessage msg)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
var token = new NadekoRandom().Next();
|
||||
var set = new HashSet<ITextChannel>();
|
||||
if (Subscribers.TryAdd(token, set))
|
||||
{
|
||||
set.Add(channel);
|
||||
await ((IGuildUser)msg.Author).SendMessageAsync("This is your CSC token:" + token.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
@ -484,6 +484,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task LogServer(IUserMessage msg)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
@ -506,6 +507,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task LogIgnore(IUserMessage imsg)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
@ -529,6 +531,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task LogAdd(IUserMessage msg, [Remainder] string eventName)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
|
@ -88,6 +88,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task RotatePlaying(IUserMessage umsg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@ -108,6 +109,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task AddPlaying(IUserMessage umsg, [Remainder] string status)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@ -124,6 +126,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task ListPlaying(IUserMessage umsg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@ -146,6 +149,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task RemovePlaying(IUserMessage umsg, int index)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
@ -82,14 +82,15 @@ namespace NadekoBot.Modules.Gambling
|
||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully sent {amount} {Gambling.CurrencyPluralName}s to {receiver.Mention}!").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//todo owner only
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public Task Award(IUserMessage umsg, long amount, [Remainder] IGuildUser usr) =>
|
||||
Award(umsg, amount, usr.Id);
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Award(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@ -101,26 +102,35 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully awarded {amount} {Gambling.CurrencyName}s to <@{usrId}>!").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
if (amount <= 0)
|
||||
return;
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public Task Take(IUserMessage umsg, long amount, [Remainder] IGuildUser user) =>
|
||||
// Take(umsg, amount, user.Id);
|
||||
await CurrencyHandler.RemoveCurrencyAsync(user, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount, true).ConfigureAwait(false);
|
||||
|
||||
//todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
// if (amount <= 0)
|
||||
// return;
|
||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from {user}!").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// await CurrencyHandler.RemoveFlowers(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", (int)amount).ConfigureAwait(false);
|
||||
|
||||
// await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
||||
//}
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Take(IUserMessage umsg, long amount, [Remainder] ulong usrId)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
if (amount <= 0)
|
||||
return;
|
||||
|
||||
await CurrencyHandler.RemoveCurrencyAsync(usrId, $"Taken by bot owner.({umsg.Author.Username}/{umsg.Author.Id})", amount).ConfigureAwait(false);
|
||||
|
||||
await channel.SendMessageAsync($"{umsg.Author.Mention} successfully took {amount} {Gambling.CurrencyName}s from <@{usrId}>!").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
@ -174,24 +174,25 @@ namespace NadekoBot.Modules.Games
|
||||
await channel.SendMessageAsync("No contest to stop on this channel.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task Typeadd(IUserMessage imsg, [Remainder] string text)
|
||||
//{
|
||||
// var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Typeadd(IUserMessage imsg, [Remainder] string text)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
// using (var uow = DbHandler.UnitOfWork())
|
||||
// {
|
||||
// uow.TypingArticles.Add(new Services.Database.Models.TypingArticle
|
||||
// {
|
||||
// Author = imsg.Author.Username,
|
||||
// Text = text
|
||||
// });
|
||||
// }
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
uow.TypingArticles.Add(new Services.Database.Models.TypingArticle
|
||||
{
|
||||
Author = imsg.Author.Username,
|
||||
Text = text
|
||||
});
|
||||
}
|
||||
|
||||
// await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
|
||||
//}
|
||||
await channel.SendMessageAsync("Added new article for typing game.").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -98,6 +98,7 @@ namespace NadekoBot.Modules.Help
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Hgit(IUserMessage umsg)
|
||||
{
|
||||
var helpstr = new StringBuilder();
|
||||
|
@ -334,6 +334,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task LocalPl(IUserMessage umsg, [Remainder] string directory)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
@ -381,6 +382,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task Local(IUserMessage umsg, [Remainder] string path)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
@ -37,6 +37,28 @@ namespace NadekoBot.Modules.Permissions
|
||||
await channel.SendMessageAsync("I will " + (action.Value ? "now" : "no longer") + " show permission warnings.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task PermRole(IUserMessage msg, [Remainder] IRole role = null)
|
||||
{
|
||||
var channel = (ITextChannel)msg.Channel;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.For(channel.Guild.Id);
|
||||
if (role == null)
|
||||
{
|
||||
await channel.SendMessageAsync($"Current permission role is **{config.PermissionRole}**.").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
config.PermissionRole = role.Name.Trim();
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await channel.SendMessageAsync($"Users now require **{role.Name}** role in order to edit permissions.").ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ListPerms(IUserMessage msg)
|
||||
@ -186,7 +208,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task UsrCmd(IUserMessage imsg, Command command, PermissionAction action, IGuildUser user)
|
||||
public async Task UsrCmd(IUserMessage imsg, Command command, PermissionAction action, [Remainder] IGuildUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -209,7 +231,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task UsrMdl(IUserMessage imsg, Module module, PermissionAction action, IGuildUser user)
|
||||
public async Task UsrMdl(IUserMessage imsg, Module module, PermissionAction action, [Remainder] IGuildUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -232,7 +254,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RoleCmd(IUserMessage imsg, Command command, PermissionAction action, IRole role)
|
||||
public async Task RoleCmd(IUserMessage imsg, Command command, PermissionAction action, [Remainder] IRole role)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -255,7 +277,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RoleMdl(IUserMessage imsg, Module module, PermissionAction action, IRole role)
|
||||
public async Task RoleMdl(IUserMessage imsg, Module module, PermissionAction action, [Remainder] IRole role)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -278,7 +300,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ChnlCmd(IUserMessage imsg, Command command, PermissionAction action, ITextChannel chnl)
|
||||
public async Task ChnlCmd(IUserMessage imsg, Command command, PermissionAction action, [Remainder] ITextChannel chnl)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
try
|
||||
@ -306,7 +328,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ChnlMdl(IUserMessage imsg, Module module, PermissionAction action, ITextChannel chnl)
|
||||
public async Task ChnlMdl(IUserMessage imsg, Module module, PermissionAction action, [Remainder] ITextChannel chnl)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -329,7 +351,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllChnlMdls(IUserMessage imsg, PermissionAction action, ITextChannel chnl)
|
||||
public async Task AllChnlMdls(IUserMessage imsg, PermissionAction action, [Remainder] ITextChannel chnl)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -352,7 +374,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllRoleMdls(IUserMessage imsg, PermissionAction action, IRole role)
|
||||
public async Task AllRoleMdls(IUserMessage imsg, PermissionAction action, [Remainder] IRole role)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -375,7 +397,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllUsrMdls(IUserMessage imsg, PermissionAction action, IUser user)
|
||||
public async Task AllUsrMdls(IUserMessage imsg, PermissionAction action, [Remainder] IUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
@ -398,7 +420,7 @@ namespace NadekoBot.Modules.Permissions
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task AllSrvrMdls(IUserMessage imsg, PermissionAction action, IUser user)
|
||||
public async Task AllSrvrMdls(IUserMessage imsg, PermissionAction action, [Remainder] IUser user)
|
||||
{
|
||||
var channel = (ITextChannel)imsg.Channel;
|
||||
|
||||
|
@ -184,21 +184,23 @@ namespace NadekoBot.Modules.Utility
|
||||
await StartReminder(rem);
|
||||
}
|
||||
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary, LocalizedAlias]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
//public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg)
|
||||
//{
|
||||
// var channel = (ITextChannel)umsg.Channel;
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[OwnerOnly]
|
||||
public async Task RemindTemplate(IUserMessage umsg, [Remainder] string arg)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(arg))
|
||||
return;
|
||||
|
||||
// arg = arg?.Trim();
|
||||
// if (string.IsNullOrWhiteSpace(arg))
|
||||
// return;
|
||||
|
||||
// NadekoBot.Config.RemindMessageFormat = arg;
|
||||
// await channel.SendMessageAsync("`New remind message set.`");
|
||||
//}
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
uow.BotConfig.GetOrCreate().RemindMessageFormat = arg.Trim();
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
await channel.SendMessageAsync("`New remind message set.`");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -70,6 +70,7 @@ namespace NadekoBot
|
||||
CommandService.AddTypeReader<PermissionAction>(new PermissionActionTypeReader());
|
||||
CommandService.AddTypeReader<Command>(new CommandTypeReader());
|
||||
CommandService.AddTypeReader<Module>(new ModuleTypeReader());
|
||||
CommandService.AddTypeReader<IGuild>(new GuildTypeReader());
|
||||
|
||||
//connect
|
||||
await Client.LoginAsync(TokenType.Bot, Credentials.Token).ConfigureAwait(false);
|
||||
|
@ -48,7 +48,18 @@ namespace NadekoBot.Services
|
||||
|
||||
try
|
||||
{
|
||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, MultiMatchHandling.Best);
|
||||
bool verbose;
|
||||
Permission rootPerm;
|
||||
string permRole;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var config = uow.GuildConfigs.PermissionsFor(guild.Id);
|
||||
verbose = config.VerbosePermissions;
|
||||
rootPerm = config.RootPermission;
|
||||
permRole = config.PermissionRole.Trim().ToLowerInvariant();
|
||||
}
|
||||
|
||||
var t = await ExecuteCommand(usrMsg, usrMsg.Content, guild, usrMsg.Author, rootPerm, permRole, MultiMatchHandling.Best);
|
||||
var command = t.Item1;
|
||||
var result = t.Item2;
|
||||
sw.Stop();
|
||||
@ -85,11 +96,6 @@ namespace NadekoBot.Services
|
||||
);
|
||||
if (guild != null && command != null && result.Error == CommandError.Exception)
|
||||
{
|
||||
bool verbose;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
verbose = uow.GuildConfigs.For(guild.Id).VerbosePermissions;
|
||||
}
|
||||
if (verbose)
|
||||
await msg.Channel.SendMessageAsync(":warning: " + result.ErrorReason).ConfigureAwait(false);
|
||||
}
|
||||
@ -112,7 +118,7 @@ namespace NadekoBot.Services
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<Tuple<Command,IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
||||
public async Task<Tuple<Command,IResult>> ExecuteCommand(IUserMessage message, string input, IGuild guild, IUser user, Permission rootPerm, string permRole, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Best) {
|
||||
var searchResult = _commandService.Search(message, input);
|
||||
if (!searchResult.IsSuccess)
|
||||
return new Tuple<Command, IResult>(null, searchResult);
|
||||
@ -154,20 +160,24 @@ namespace NadekoBot.Services
|
||||
}
|
||||
}
|
||||
var cmd = commands[i];
|
||||
Permission rootPerm;
|
||||
//check permissions
|
||||
if (guild != null)
|
||||
{
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
rootPerm = uow.GuildConfigs.PermissionsFor(guild.Id).RootPermission;
|
||||
}
|
||||
int index;
|
||||
if (!rootPerm.AsEnumerable().CheckPermissions(message, cmd, out index))
|
||||
{
|
||||
var returnMsg = $"Permission number #{index} **{rootPerm.GetAt(index).GetCommand()}** is preventing this action.";
|
||||
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, returnMsg));
|
||||
}
|
||||
|
||||
|
||||
if (cmd.Module.Source.Name == typeof(Permissions).Name) //permissions, you must have special role
|
||||
{
|
||||
if (!((IGuildUser)user).Roles.Any(r => r.Name.Trim().ToLowerInvariant() == permRole))
|
||||
{
|
||||
return new Tuple<Command, IResult>(cmd, SearchResult.FromError(CommandError.Exception, $"You need a **{permRole}** role in order to use permission commands."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Tuple<Command, IResult>(commands[i], await commands[i].Execute(message, parseResult));
|
||||
|
@ -13,6 +13,16 @@ namespace NadekoBot.Services
|
||||
public static class CurrencyHandler
|
||||
{
|
||||
public static async Task<bool> RemoveCurrencyAsync(IGuildUser author, string reason, long amount, bool sendMessage)
|
||||
{
|
||||
var success = await RemoveCurrencyAsync(author.Id, reason, amount);
|
||||
|
||||
if (success && sendMessage)
|
||||
try { await author.SendMessageAsync($"`You lost:` {amount} {Gambling.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static async Task<bool> RemoveCurrencyAsync(ulong authorId, string reason, long amount)
|
||||
{
|
||||
if (amount < 0)
|
||||
throw new ArgumentNullException(nameof(amount));
|
||||
@ -20,15 +30,12 @@ namespace NadekoBot.Services
|
||||
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
var success = uow.Currency.TryUpdateState(author.Id, -amount);
|
||||
var success = uow.Currency.TryUpdateState(authorId, -amount);
|
||||
if (!success)
|
||||
return false;
|
||||
await uow.CompleteAsync();
|
||||
}
|
||||
|
||||
if (sendMessage)
|
||||
try { await author.SendMessageAsync($"`You lost:` {amount} {Gambling.CurrencySign}\n`Reason:` {reason}").ConfigureAwait(false); } catch { }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
26
src/NadekoBot/TypeReaders/GuildTypeReader.cs
Normal file
26
src/NadekoBot/TypeReaders/GuildTypeReader.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Discord.Commands;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace NadekoBot.TypeReaders
|
||||
{
|
||||
public class GuildTypeReader : TypeReader
|
||||
{
|
||||
public override Task<TypeReaderResult> Read(IUserMessage context, string input)
|
||||
{
|
||||
input = input.Trim().ToLowerInvariant();
|
||||
var guild = NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Id.ToString().Trim().ToLowerInvariant() == input) ?? //by id
|
||||
NadekoBot.Client.GetGuilds().FirstOrDefault(g => g.Name.Trim().ToLowerInvariant() == input);//by name
|
||||
|
||||
if (guild != null)
|
||||
return Task.FromResult(TypeReaderResult.FromSuccess(guild));
|
||||
|
||||
return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No guild by that name or Id found"));
|
||||
}
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ namespace Tests
|
||||
{
|
||||
var root = GetRoot();
|
||||
|
||||
root.Add(new Permission() { SecondaryTargetName = "Added" });
|
||||
root.Prepend(new Permission() { SecondaryTargetName = "Added" });
|
||||
|
||||
Assert.Equal(11, root.Count());
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,26 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Discord.Net.Commands</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:Discord.Commands.AliasAttribute">
|
||||
<summary> Provides aliases for a command. </summary>
|
||||
</member>
|
||||
<member name="P:Discord.Commands.AliasAttribute.Aliases">
|
||||
<summary> The aliases which have been defined for the command. </summary>
|
||||
</member>
|
||||
<member name="M:Discord.Commands.AliasAttribute.#ctor(System.String[])">
|
||||
<summary> Creates a new <see cref="T:Discord.Commands.AliasAttribute"/> with the given aliases. </summary>
|
||||
</member>
|
||||
<member name="T:Discord.Commands.PriorityAttribute">
|
||||
<summary> Sets priority of commands </summary>
|
||||
</member>
|
||||
<member name="P:Discord.Commands.PriorityAttribute.Priority">
|
||||
<summary> The priority which has been set for the command </summary>
|
||||
</member>
|
||||
<member name="M:Discord.Commands.PriorityAttribute.#ctor(System.Int32)">
|
||||
<summary> Creates a new <see cref="T:Discord.Commands.PriorityAttribute"/> with the given priority. </summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"additionalProbingPaths": [
|
||||
"C:\\Users\\Kwoth\\.nuget\\packages"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
@ -3614,7 +3614,8 @@
|
||||
"framework": ".NETCoreApp,Version=v1.0",
|
||||
"dependencies": {
|
||||
"CoreCLR-NCalc": "2.1.0",
|
||||
"Discord.Net.Commands": "1.0.0-dev",
|
||||
"Discord.Net": "1.0.0-beta",
|
||||
"Discord.Net.Commands": "1.0.0-beta",
|
||||
"Google.Apis.Customsearch.v1": "1.16.0.466",
|
||||
"Google.Apis.Urlshortener.v1": "1.15.0.138",
|
||||
"Google.Apis.YouTube.v3": "1.15.0.582",
|
||||
|
Loading…
Reference in New Issue
Block a user