2016-11-18 21:28:53 +00:00
|
|
|
using Discord;
|
2016-08-15 14:57:40 +00:00
|
|
|
using Discord.Commands;
|
2017-05-22 23:59:31 +00:00
|
|
|
using Discord.WebSocket;
|
2016-08-15 14:57:40 +00:00
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 04:14:54 +00:00
|
|
|
using NadekoBot.Core.Services;
|
2016-08-15 14:57:40 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
using NadekoBot.Common.Attributes;
|
2016-08-13 18:45:08 +00:00
|
|
|
|
2016-08-15 14:57:40 +00:00
|
|
|
namespace NadekoBot.Modules.Utility
|
|
|
|
{
|
2016-12-08 15:40:59 +00:00
|
|
|
public partial class Utility
|
2016-08-15 14:57:40 +00:00
|
|
|
{
|
2016-12-17 00:21:05 +00:00
|
|
|
[Group]
|
2017-02-23 02:06:37 +00:00
|
|
|
public class InfoCommands : NadekoSubmodule
|
2016-08-15 14:57:40 +00:00
|
|
|
{
|
2017-06-19 13:42:10 +00:00
|
|
|
private readonly DiscordSocketClient _client;
|
2017-05-22 23:59:31 +00:00
|
|
|
private readonly IStatsService _stats;
|
|
|
|
|
2017-06-19 13:42:10 +00:00
|
|
|
public InfoCommands(DiscordSocketClient client, IStatsService stats, CommandHandler ch)
|
2017-05-22 23:59:31 +00:00
|
|
|
{
|
|
|
|
_client = client;
|
|
|
|
_stats = stats;
|
|
|
|
}
|
|
|
|
|
2016-12-17 00:21:05 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
public async Task ServerInfo(string guildName = null)
|
2016-12-10 17:13:51 +00:00
|
|
|
{
|
2016-12-17 00:21:05 +00:00
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
guildName = guildName?.ToUpperInvariant();
|
2017-09-10 21:01:26 +00:00
|
|
|
SocketGuild guild;
|
2016-12-17 00:21:05 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(guildName))
|
2017-09-10 21:01:26 +00:00
|
|
|
guild = (SocketGuild)channel.Guild;
|
2016-12-17 00:21:05 +00:00
|
|
|
else
|
2017-05-22 23:59:31 +00:00
|
|
|
guild = _client.Guilds.FirstOrDefault(g => g.Name.ToUpperInvariant() == guildName.ToUpperInvariant());
|
2016-12-17 00:21:05 +00:00
|
|
|
if (guild == null)
|
|
|
|
return;
|
2017-09-10 21:01:26 +00:00
|
|
|
var ownername = guild.GetUser(guild.OwnerId);
|
|
|
|
var textchn = guild.TextChannels.Count();
|
|
|
|
var voicechn = guild.VoiceChannels.Count();
|
2016-12-17 00:21:05 +00:00
|
|
|
|
|
|
|
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(guild.Id >> 22);
|
2017-01-18 01:44:48 +00:00
|
|
|
var features = string.Join("\n", guild.Features);
|
|
|
|
if (string.IsNullOrWhiteSpace(features))
|
|
|
|
features = "-";
|
2016-12-17 00:21:05 +00:00
|
|
|
var embed = new EmbedBuilder()
|
2017-02-23 02:06:37 +00:00
|
|
|
.WithAuthor(eab => eab.WithName(GetText("server_info")))
|
2016-12-17 00:21:05 +00:00
|
|
|
.WithTitle(guild.Name)
|
2017-02-23 02:06:37 +00:00
|
|
|
.AddField(fb => fb.WithName(GetText("id")).WithValue(guild.Id.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("owner")).WithValue(ownername.ToString()).WithIsInline(true))
|
2017-09-10 21:01:26 +00:00
|
|
|
.AddField(fb => fb.WithName(GetText("members")).WithValue(guild.MemberCount.ToString()).WithIsInline(true))
|
2017-02-23 02:06:37 +00:00
|
|
|
.AddField(fb => fb.WithName(GetText("text_channels")).WithValue(textchn.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("voice_channels")).WithValue(voicechn.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("created_at")).WithValue($"{createdAt:dd.MM.yyyy HH:mm}").WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("region")).WithValue(guild.VoiceRegionId.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("roles")).WithValue((guild.Roles.Count - 1).ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("features")).WithValue(features).WithIsInline(true))
|
2016-12-17 00:21:05 +00:00
|
|
|
.WithColor(NadekoBot.OkColor);
|
2017-07-07 21:22:34 +00:00
|
|
|
if (Uri.IsWellFormedUriString(guild.IconUrl, UriKind.Absolute))
|
|
|
|
embed.WithImageUrl(guild.IconUrl);
|
2017-05-22 23:59:31 +00:00
|
|
|
if (guild.Emotes.Any())
|
2016-12-17 00:21:05 +00:00
|
|
|
{
|
2017-05-22 23:59:31 +00:00
|
|
|
embed.AddField(fb => fb.WithName(GetText("custom_emojis") + $"({guild.Emotes.Count})").WithValue(string.Join(" ", guild.Emotes.Shuffle().Take(20).Select(e => $"{e.Name} <:{e.Name}:{e.Id}>"))));
|
2016-12-17 00:21:05 +00:00
|
|
|
}
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-10 17:13:51 +00:00
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
2016-12-17 00:21:05 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
public async Task ChannelInfo(ITextChannel channel = null)
|
|
|
|
{
|
|
|
|
var ch = channel ?? (ITextChannel)Context.Channel;
|
|
|
|
if (ch == null)
|
|
|
|
return;
|
|
|
|
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
|
|
|
|
var usercount = (await ch.GetUsersAsync().Flatten()).Count();
|
|
|
|
var embed = new EmbedBuilder()
|
|
|
|
.WithTitle(ch.Name)
|
|
|
|
.WithDescription(ch.Topic?.SanitizeMentions())
|
2017-02-23 02:06:37 +00:00
|
|
|
.AddField(fb => fb.WithName(GetText("id")).WithValue(ch.Id.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("created_at")).WithValue($"{createdAt:dd.MM.yyyy HH:mm}").WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("users")).WithValue(usercount.ToString()).WithIsInline(true))
|
2016-12-17 00:21:05 +00:00
|
|
|
.WithColor(NadekoBot.OkColor);
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
2016-12-17 00:21:05 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
public async Task UserInfo(IGuildUser usr = null)
|
|
|
|
{
|
|
|
|
var user = usr ?? Context.User as IGuildUser;
|
2016-12-10 19:17:41 +00:00
|
|
|
|
2016-12-17 00:21:05 +00:00
|
|
|
if (user == null)
|
|
|
|
return;
|
2016-12-10 19:17:41 +00:00
|
|
|
|
2016-12-17 00:21:05 +00:00
|
|
|
var embed = new EmbedBuilder()
|
2017-02-23 02:06:37 +00:00
|
|
|
.AddField(fb => fb.WithName(GetText("name")).WithValue($"**{user.Username}**#{user.Discriminator}").WithIsInline(true));
|
2016-12-17 00:21:05 +00:00
|
|
|
if (!string.IsNullOrWhiteSpace(user.Nickname))
|
|
|
|
{
|
2017-02-23 02:06:37 +00:00
|
|
|
embed.AddField(fb => fb.WithName(GetText("nickname")).WithValue(user.Nickname).WithIsInline(true));
|
2016-12-17 00:21:05 +00:00
|
|
|
}
|
2017-02-23 02:06:37 +00:00
|
|
|
embed.AddField(fb => fb.WithName(GetText("id")).WithValue(user.Id.ToString()).WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("joined_server")).WithValue($"{user.JoinedAt?.ToString("dd.MM.yyyy HH:mm") ?? "?"}").WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("joined_discord")).WithValue($"{user.CreatedAt:dd.MM.yyyy HH:mm}").WithIsInline(true))
|
|
|
|
.AddField(fb => fb.WithName(GetText("roles")).WithValue($"**({user.RoleIds.Count - 1})** - {string.Join("\n", user.GetRoles().Take(10).Where(r => r.Id != r.Guild.EveryoneRole.Id).Select(r => r.Name)).SanitizeMentions()}").WithIsInline(true))
|
2016-12-17 00:21:05 +00:00
|
|
|
.WithColor(NadekoBot.OkColor);
|
2017-01-30 01:58:36 +00:00
|
|
|
|
|
|
|
if (user.AvatarId != null)
|
|
|
|
embed.WithThumbnailUrl(user.RealAvatarUrl());
|
2016-12-17 00:21:05 +00:00
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-12-10 17:13:51 +00:00
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
2017-05-22 23:59:31 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
[OwnerOnly]
|
|
|
|
public async Task Activity(int page = 1)
|
|
|
|
{
|
|
|
|
const int activityPerPage = 15;
|
|
|
|
page -= 1;
|
2016-12-28 05:31:39 +00:00
|
|
|
|
2017-05-22 23:59:31 +00:00
|
|
|
if (page < 0)
|
|
|
|
return;
|
2016-12-28 05:31:39 +00:00
|
|
|
|
2017-05-22 23:59:31 +00:00
|
|
|
int startCount = page * activityPerPage;
|
2016-12-28 05:31:39 +00:00
|
|
|
|
2017-05-22 23:59:31 +00:00
|
|
|
StringBuilder str = new StringBuilder();
|
2017-05-29 04:13:22 +00:00
|
|
|
foreach (var kvp in _cmdHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page * activityPerPage).Take(activityPerPage))
|
2017-05-22 23:59:31 +00:00
|
|
|
{
|
|
|
|
str.AppendLine(GetText("activity_line",
|
|
|
|
++startCount,
|
|
|
|
Format.Bold(kvp.Key.ToString()),
|
|
|
|
kvp.Value / _stats.GetUptime().TotalSeconds, kvp.Value));
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
|
2017-05-22 23:59:31 +00:00
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder()
|
|
|
|
.WithTitle(GetText("activity_page", page + 1))
|
|
|
|
.WithOkColor()
|
|
|
|
.WithFooter(efb => efb.WithText(GetText("activity_users_total",
|
2017-05-29 04:13:22 +00:00
|
|
|
_cmdHandler.UserMessagesSent.Count)))
|
2017-05-22 23:59:31 +00:00
|
|
|
.WithDescription(str.ToString()));
|
|
|
|
}
|
2016-12-28 05:31:39 +00:00
|
|
|
}
|
2016-08-15 14:57:40 +00:00
|
|
|
}
|
2016-12-17 00:21:05 +00:00
|
|
|
}
|