More work
This commit is contained in:
parent
ac7147f5c1
commit
e8ffcbf7f6
@ -1 +1 @@
|
||||
Subproject commit f531c634996960c64ddfe602a7b6eef63677d30c
|
||||
Subproject commit 06184c1a655232beedd608a8b0190ca2c70b9b23
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"projects": [ "src", "Discord.Net", "discord.net/src" ],
|
||||
"projects": [ "discord.net/src/Discord.Net", "discord.net/src/Discord.Net.Commands", "src" ],
|
||||
"sdk": {
|
||||
"version": "1.0.0-preview2-003121"
|
||||
}
|
||||
|
12
src/NadekoBot/Attributes/OwnerOnlyAttribute.cs
Normal file
12
src/NadekoBot/Attributes/OwnerOnlyAttribute.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord;
|
||||
|
||||
namespace NadekoBot.Attributes {
|
||||
public class OwnerOnlyAttribute : PreconditionAttribute
|
||||
{
|
||||
|
||||
public override Task<PreconditionResult> CheckPermissions(IMessage context, Command executingCommand, object moduleInstance) =>
|
||||
Task.FromResult((NadekoBot.Credentials.IsOwner(context.Author) ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")));
|
||||
}
|
||||
}
|
@ -423,73 +423,47 @@ namespace NadekoBot.Modules.Administration
|
||||
}
|
||||
|
||||
|
||||
//todo maybe split into 3/4 different commands with the same name
|
||||
//delets her own messages, no perm required
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Prune(IMessage msg, [Remainder] string target = null)
|
||||
public async Task Prune(IMessage imsg)
|
||||
{
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
var channel = imsg.Channel as ITextChannel;
|
||||
|
||||
var user = await channel.Guild.GetCurrentUserAsync();
|
||||
if (string.IsNullOrWhiteSpace(target))
|
||||
{
|
||||
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
|
||||
var enumerable = (await imsg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
|
||||
await imsg.Channel.DeleteMessagesAsync(enumerable);
|
||||
}
|
||||
|
||||
// prune x
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[RequirePermission(ChannelPermission.ManageMessages)]
|
||||
public async Task Prune(IMessage msg, int count)
|
||||
{
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
while (count > 0)
|
||||
{
|
||||
int limit = (count < 100) ? count : 100;
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit));
|
||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||
return;
|
||||
}
|
||||
target = target.Trim();
|
||||
if (!user.GetPermissions(channel).ManageMessages)
|
||||
{
|
||||
await msg.Reply("Don't have permissions to manage messages in channel");
|
||||
return;
|
||||
}
|
||||
int count;
|
||||
if (int.TryParse(target, out count))
|
||||
{
|
||||
while (count > 0)
|
||||
{
|
||||
int limit = (count < 100) ? count : 100;
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit));
|
||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||
await Task.Delay(1000); // there is a 1 per second per guild ratelimit for deletemessages
|
||||
if (enumerable.Count < limit) break;
|
||||
count -= limit;
|
||||
}
|
||||
}
|
||||
else if (msg.MentionedUsers.Count > 0)
|
||||
{
|
||||
var toDel = new List<IMessage>();
|
||||
|
||||
var match = Regex.Match(target, @"\s(\d+)\s");
|
||||
if (match.Success)
|
||||
{
|
||||
int.TryParse(match.Groups[1].Value, out count);
|
||||
var messages = new List<IMessage>(count);
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
var toAdd = await msg.Channel.GetMessagesAsync(limit: count < 100 ? count : 100);
|
||||
messages.AddRange(toAdd);
|
||||
count -= toAdd.Count;
|
||||
}
|
||||
|
||||
foreach (var mention in msg.MentionedUsers)
|
||||
{
|
||||
toDel.AddRange(messages.Where(m => m.Author.Id == mention.Id));
|
||||
}
|
||||
|
||||
var messagesEnum = messages.AsEnumerable();
|
||||
while (messagesEnum.Count() > 0)
|
||||
{
|
||||
await msg.Channel.DeleteMessagesAsync(messagesEnum.Take(100));
|
||||
await Task.Delay(1000); // 1 second ratelimit
|
||||
messagesEnum = messagesEnum.Skip(100);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1000); // there is a 1 per second per guild ratelimit for deletemessages
|
||||
if (enumerable.Count < limit) break;
|
||||
count -= limit;
|
||||
}
|
||||
}
|
||||
|
||||
//prune @user [x]
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Prune(IMessage msg, IGuildUser user, int count = 100)
|
||||
{
|
||||
var channel = msg.Channel as ITextChannel;
|
||||
int limit = (count < 100) ? count : 100;
|
||||
var enumerable = (await msg.Channel.GetMessagesAsync(limit: limit));
|
||||
await msg.Channel.DeleteMessagesAsync(enumerable);
|
||||
}
|
||||
////todo owner only
|
||||
//[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
//[RequireContext(ContextType.Guild)]
|
||||
|
@ -35,7 +35,8 @@ namespace NadekoBot.Modules.Utility
|
||||
`TextChannels:` **{(await server.GetTextChannelsAsync()).Count()}** `VoiceChannels:` **{(await server.GetVoiceChannelsAsync()).Count()}**
|
||||
`Members:` **{users.Count}** `Online:` **{users.Count(u => u.Status == UserStatus.Online)}**
|
||||
`Roles:` **{server.Roles.Count()}**
|
||||
`Created At:` **{createdAt}**");
|
||||
`Created At:` **{createdAt}**
|
||||
");
|
||||
if (server.Emojis.Count() > 0)
|
||||
sb.AppendLine($"`Custom Emojis:` **{string.Join(", ", server.Emojis)}**");
|
||||
if (server.Features.Count() > 0)
|
||||
@ -53,13 +54,12 @@ namespace NadekoBot.Modules.Utility
|
||||
if (ch == null)
|
||||
return;
|
||||
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"`Name:` **#{ch.Name}**");
|
||||
sb.AppendLine($"`Id:` **{ch.Id}**");
|
||||
sb.AppendLine($"`Created At:` **{createdAt}**");
|
||||
sb.AppendLine($"`Topic:` **{ch.Topic}**");
|
||||
sb.AppendLine($"`Users:` **{(await ch.GetUsersAsync()).Count()}**");
|
||||
await msg.Reply(sb.ToString()).ConfigureAwait(false);
|
||||
var toReturn = $@"`Name:` **#{ch.Name}**
|
||||
`Id:` **{ch.Id}**
|
||||
`Created At:` **{createdAt}**
|
||||
`Topic:` **{ch.Topic}**
|
||||
`Users:` **{(await ch.GetUsersAsync()).Count()}**";
|
||||
await msg.Reply(toReturn).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
|
||||
@ -70,17 +70,15 @@ namespace NadekoBot.Modules.Utility
|
||||
var user = usr ?? msg.Author as IGuildUser;
|
||||
if (user == null)
|
||||
return;
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"`Name#Discrim:` **#{user.Username}#{user.Discriminator}**");
|
||||
var toReturn = $"`Name#Discrim:` **#{user.Username}#{user.Discriminator}**\n";
|
||||
if (!string.IsNullOrWhiteSpace(user.Nickname))
|
||||
sb.AppendLine($"`Nickname:` **{user.Nickname}**");
|
||||
sb.AppendLine($"`Id:` **{user.Id}**");
|
||||
sb.AppendLine($"`Current Game:` **{(user.Game?.Name == null ? "-" : user.Game.Name)}**");
|
||||
sb.AppendLine($"`Joined At:` **{user.JoinedAt}**");
|
||||
sb.AppendLine($"`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name))}**");
|
||||
sb.AppendLine($"`AvatarUrl:` **{user.AvatarUrl}**");
|
||||
await msg.Reply(sb.ToString()).ConfigureAwait(false);
|
||||
toReturn += $"`Nickname:` **{user.Nickname}**";
|
||||
toReturn += $@"`Id:` **{user.Id}**
|
||||
`Current Game:` **{(user.Game?.Name == null ? "-" : user.Game.Name)}**
|
||||
`Joined At:` **{user.JoinedAt}**
|
||||
`Roles:` **({user.Roles.Count()}) - {string.Join(", ", user.Roles.Select(r => r.Name))}**
|
||||
`AvatarUrl:` **{user.AvatarUrl}**";
|
||||
await msg.Reply(toReturn).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
namespace NadekoBot.Services
|
||||
using Discord;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Services
|
||||
{
|
||||
public interface IBotCredentials
|
||||
{
|
||||
string ClientId { get; }
|
||||
string Token { get; }
|
||||
string GoogleApiKey { get; }
|
||||
ulong[] OwnerIds { get; }
|
||||
|
||||
|
||||
bool IsOwner(IUser u);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Discord;
|
||||
using System.Linq;
|
||||
|
||||
namespace NadekoBot.Services.Impl
|
||||
{
|
||||
@ -16,15 +18,20 @@ namespace NadekoBot.Services.Impl
|
||||
|
||||
public string Token { get; }
|
||||
|
||||
public ulong[] OwnerIds { get; }
|
||||
|
||||
public BotCredentials()
|
||||
{
|
||||
var cm = JsonConvert.DeserializeObject<CredentialsModel>(File.ReadAllText("./credentials.json"));
|
||||
Token = cm.Token;
|
||||
OwnerIds = cm.OwnerIds;
|
||||
}
|
||||
|
||||
private class CredentialsModel {
|
||||
public string Token { get; set; }
|
||||
public ulong[] OwnerIds { get; set; }
|
||||
}
|
||||
|
||||
public bool IsOwner(IUser u) => OwnerIds.Contains(u.Id);
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +339,7 @@
|
||||
"Microsoft.NETCore.Jit/1.0.2": {
|
||||
"type": "package"
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.0.2-beta-24410-01": {
|
||||
"Microsoft.NETCore.Platforms/1.0.1": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
"lib/netstandard1.0/_._": {}
|
||||
@ -1509,11 +1509,7 @@
|
||||
"ref/netstandard1.3/System.Net.Security.dll": {}
|
||||
},
|
||||
"runtimeTargets": {
|
||||
"runtimes/unix/lib/netstandard1.6/System.Net.Security.dll": {
|
||||
"assetType": "runtime",
|
||||
"rid": "unix"
|
||||
},
|
||||
"runtimes/win/lib/netstandard1.3/System.Net.Security.dll": {
|
||||
"runtimes/win/lib/netstandard1.3/_._": {
|
||||
"assetType": "runtime",
|
||||
"rid": "win"
|
||||
}
|
||||
@ -1563,20 +1559,16 @@
|
||||
"lib/netstandard1.3/System.Net.WebSockets.dll": {}
|
||||
}
|
||||
},
|
||||
"System.Net.WebSockets.Client/4.0.1-beta-24410-01": {
|
||||
"System.Net.WebSockets.Client/4.0.0": {
|
||||
"type": "package",
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Platforms": "1.0.2-beta-24410-01",
|
||||
"Microsoft.NETCore.Platforms": "1.0.1",
|
||||
"Microsoft.Win32.Primitives": "4.0.1",
|
||||
"System.Collections": "4.0.11",
|
||||
"System.Diagnostics.Debug": "4.0.11",
|
||||
"System.Diagnostics.Tracing": "4.1.0",
|
||||
"System.Globalization": "4.0.11",
|
||||
"System.IO": "4.1.0",
|
||||
"System.Net.NameResolution": "4.0.0",
|
||||
"System.Net.Primitives": "4.0.11",
|
||||
"System.Net.Security": "4.0.0",
|
||||
"System.Net.Sockets": "4.1.0",
|
||||
"System.Net.WebHeaderCollection": "4.0.1",
|
||||
"System.Net.WebSockets": "4.0.0",
|
||||
"System.Resources.ResourceManager": "4.0.1",
|
||||
@ -1584,14 +1576,10 @@
|
||||
"System.Runtime.Extensions": "4.1.0",
|
||||
"System.Runtime.Handles": "4.0.1",
|
||||
"System.Runtime.InteropServices": "4.1.0",
|
||||
"System.Security.Cryptography.Algorithms": "4.2.0",
|
||||
"System.Security.Cryptography.Primitives": "4.0.0",
|
||||
"System.Security.Cryptography.X509Certificates": "4.1.0",
|
||||
"System.Text.Encoding": "4.0.11",
|
||||
"System.Text.Encoding.Extensions": "4.0.11",
|
||||
"System.Threading": "4.0.11",
|
||||
"System.Threading.Tasks": "4.0.11",
|
||||
"System.Threading.Timer": "4.0.1"
|
||||
"System.Threading.Tasks": "4.0.11"
|
||||
},
|
||||
"compile": {
|
||||
"ref/netstandard1.3/System.Net.WebSockets.Client.dll": {}
|
||||
@ -2534,7 +2522,7 @@
|
||||
"System.Net.Http": "4.1.0",
|
||||
"System.Net.NameResolution": "4.0.0",
|
||||
"System.Net.Sockets": "4.1.0",
|
||||
"System.Net.WebSockets.Client": "4.0.1-beta-24410-01",
|
||||
"System.Net.WebSockets.Client": "4.0.0",
|
||||
"System.Reflection.Extensions": "4.0.1",
|
||||
"System.Runtime.InteropServices": "4.1.0",
|
||||
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
|
||||
@ -2918,12 +2906,12 @@
|
||||
"runtime.json"
|
||||
]
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.0.2-beta-24410-01": {
|
||||
"sha512": "uc/pGYdE4sVy3OovFF8hg79MvCxptzICxn0jdA6WusGWZa7VieqFoZYc+a6bHUVhMI0s/7SfBriux0RUq+PpbA==",
|
||||
"Microsoft.NETCore.Platforms/1.0.1": {
|
||||
"sha512": "2G6OjjJzwBfNOO8myRV/nFrbTw5iA+DEm0N+qUqhrOmaVtn4pC77h38I1jsXGw5VH55+dPfQsqHD0We9sCl9FQ==",
|
||||
"type": "package",
|
||||
"path": "Microsoft.NETCore.Platforms/1.0.2-beta-24410-01",
|
||||
"path": "Microsoft.NETCore.Platforms/1.0.1",
|
||||
"files": [
|
||||
"Microsoft.NETCore.Platforms.1.0.2-beta-24410-01.nupkg.sha512",
|
||||
"Microsoft.NETCore.Platforms.1.0.1.nupkg.sha512",
|
||||
"Microsoft.NETCore.Platforms.nuspec",
|
||||
"ThirdPartyNotices.txt",
|
||||
"dotnet_library_license.txt",
|
||||
@ -5548,12 +5536,12 @@
|
||||
"ref/xamarinwatchos10/_._"
|
||||
]
|
||||
},
|
||||
"System.Net.WebSockets.Client/4.0.1-beta-24410-01": {
|
||||
"sha512": "IOqAcR7k+3LwNI6aL7qN61HcCOA9X4MM9LbrZhDeNbeB/IeWTk7zpeb7kh3d7H678s7ndIqN6a7okO8dAAfcYQ==",
|
||||
"System.Net.WebSockets.Client/4.0.0": {
|
||||
"sha512": "GY5h9cn0ZVsG4ORQqMytTldrqxet2RC2CSEsgWGf4XNW5jhL5SxzcUZph03xbZsgn7K3qMr+Rq+gkbJNI+FEXg==",
|
||||
"type": "package",
|
||||
"path": "System.Net.WebSockets.Client/4.0.1-beta-24410-01",
|
||||
"path": "System.Net.WebSockets.Client/4.0.0",
|
||||
"files": [
|
||||
"System.Net.WebSockets.Client.4.0.1-beta-24410-01.nupkg.sha512",
|
||||
"System.Net.WebSockets.Client.4.0.0.nupkg.sha512",
|
||||
"System.Net.WebSockets.Client.nuspec",
|
||||
"ThirdPartyNotices.txt",
|
||||
"dotnet_library_license.txt",
|
||||
|
Loading…
Reference in New Issue
Block a user