More work

This commit is contained in:
Kwoth
2016-08-20 13:05:57 +02:00
parent ac7147f5c1
commit e8ffcbf7f6
8 changed files with 89 additions and 104 deletions

View File

@@ -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 imsg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
await imsg.Channel.DeleteMessagesAsync(enumerable);
}
var enumerable = (await msg.Channel.GetMessagesAsync()).Where(x => x.Author.Id == user.Id);
// 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)]

View File

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