2016-08-13 18:45:08 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using NadekoBot.Attributes;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-08-15 14:57:40 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using NadekoBot.Extensions;
|
|
|
|
|
using System.Reflection;
|
2016-11-30 19:15:22 +00:00
|
|
|
|
using NadekoBot.Services.Impl;
|
2016-12-24 07:05:43 +00:00
|
|
|
|
using System.Net.Http;
|
2017-01-05 12:49:50 +00:00
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using ImageSharp;
|
2017-01-11 13:05:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Newtonsoft.Json;
|
2017-01-29 21:54:27 +00:00
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using NadekoBot.Services;
|
2016-08-13 18:45:08 +00:00
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Utility
|
|
|
|
|
{
|
2016-09-10 19:45:12 +00:00
|
|
|
|
[NadekoModule("Utility", ".")]
|
2017-02-20 22:46:34 +00:00
|
|
|
|
public partial class Utility : NadekoTopLevelModule
|
2016-08-13 18:45:08 +00:00
|
|
|
|
{
|
2017-01-05 12:49:50 +00:00
|
|
|
|
private static ConcurrentDictionary<ulong, Timer> rotatingRoleColors = new ConcurrentDictionary<ulong, Timer>();
|
|
|
|
|
|
2017-02-06 06:53:27 +00:00
|
|
|
|
//[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
//[RequireContext(ContextType.Guild)]
|
|
|
|
|
//public async Task Midorina([Remainder] string arg)
|
|
|
|
|
//{
|
|
|
|
|
// var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
|
|
|
|
// var roleNames = arg?.Split(';');
|
|
|
|
|
|
|
|
|
|
// if (roleNames == null || roleNames.Length == 0)
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// var j = 0;
|
2017-02-06 08:35:49 +00:00
|
|
|
|
// var roles = roleNames.Select(x => Context.Guild.Roles.FirstOrDefault(r => String.Compare(r.Name, x, StringComparison.OrdinalIgnoreCase) == 0))
|
2017-02-06 06:53:27 +00:00
|
|
|
|
// .Where(x => x != null)
|
|
|
|
|
// .Take(10)
|
|
|
|
|
// .ToArray();
|
|
|
|
|
|
2017-02-06 08:35:49 +00:00
|
|
|
|
// var rnd = new NadekoRandom();
|
|
|
|
|
// var reactions = new[] { "🎬", "🐧", "🌍", "🌺", "🚀", "☀", "🌲", "🍒", "🐾", "🏀" }
|
|
|
|
|
// .OrderBy(x => rnd.Next())
|
|
|
|
|
// .ToArray();
|
2017-02-06 06:53:27 +00:00
|
|
|
|
|
2017-02-06 08:35:49 +00:00
|
|
|
|
// var roleStrings = roles
|
|
|
|
|
// .Select(x => $"{reactions[j++]} -> {x.Name}");
|
|
|
|
|
|
2017-02-06 06:53:27 +00:00
|
|
|
|
// var msg = await Context.Channel.SendConfirmAsync("Pick a Role",
|
2017-02-06 08:35:49 +00:00
|
|
|
|
// string.Join("\n", roleStrings)).ConfigureAwait(false);
|
2017-02-06 06:53:27 +00:00
|
|
|
|
|
|
|
|
|
// for (int i = 0; i < roles.Length; i++)
|
|
|
|
|
// {
|
2017-02-06 08:35:49 +00:00
|
|
|
|
// try { await msg.AddReactionAsync(reactions[i]).ConfigureAwait(false); }
|
|
|
|
|
// catch (Exception ex) { _log.Warn(ex); }
|
2017-02-06 06:53:27 +00:00
|
|
|
|
// await Task.Delay(1000).ConfigureAwait(false);
|
|
|
|
|
// }
|
2017-02-06 08:35:49 +00:00
|
|
|
|
|
|
|
|
|
// msg.OnReaction((r) => Task.Run(async () =>
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// var usr = r.User.GetValueOrDefault() as IGuildUser;
|
|
|
|
|
|
|
|
|
|
// if (usr == null)
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// var index = Array.IndexOf<string>(reactions, r.Emoji.Name);
|
|
|
|
|
// if (index == -1)
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// await usr.RemoveRolesAsync(roles[index]);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// _log.Warn(ex);
|
|
|
|
|
// }
|
|
|
|
|
// }), (r) => Task.Run(async () =>
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// var usr = r.User.GetValueOrDefault() as IGuildUser;
|
|
|
|
|
|
|
|
|
|
// if (usr == null)
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// var index = Array.IndexOf<string>(reactions, r.Emoji.Name);
|
|
|
|
|
// if (index == -1)
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
// await usr.RemoveRolesAsync(roles[index]);
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// _log.Warn(ex);
|
|
|
|
|
// }
|
|
|
|
|
// }));
|
2017-02-06 06:53:27 +00:00
|
|
|
|
//}
|
|
|
|
|
|
2017-01-05 12:49:50 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-23 00:27:45 +00:00
|
|
|
|
[RequireUserPermission(GuildPermission.ManageRoles)]
|
2017-01-05 12:49:50 +00:00
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task RotateRoleColor(int timeout, IRole role, params string[] hexes)
|
|
|
|
|
{
|
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
|
|
|
|
|
2017-01-05 18:13:53 +00:00
|
|
|
|
if ((timeout < 60 && timeout != 0) || timeout > 3600)
|
2017-01-05 12:49:50 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Timer t;
|
|
|
|
|
if (timeout == 0 || hexes.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
if (rotatingRoleColors.TryRemove(role.Id, out t))
|
|
|
|
|
{
|
|
|
|
|
t.Change(Timeout.Infinite, Timeout.Infinite);
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyConfirmLocalized("rrc_stop", Format.Bold(role.Name)).ConfigureAwait(false);
|
2017-01-05 12:49:50 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-02-20 22:46:34 +00:00
|
|
|
|
|
2017-01-05 12:49:50 +00:00
|
|
|
|
var hexColors = hexes.Select(hex =>
|
|
|
|
|
{
|
2017-02-20 22:46:34 +00:00
|
|
|
|
try { return (ImageSharp.Color?)ImageSharp.Color.FromHex(hex.Replace("#", "")); } catch { return null; }
|
2017-01-05 12:49:50 +00:00
|
|
|
|
})
|
|
|
|
|
.Where(c => c != null)
|
|
|
|
|
.Select(c => c.Value)
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
if (!hexColors.Any())
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("rrc_no_colors").ConfigureAwait(false);
|
2017-01-05 12:49:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var images = hexColors.Select(color =>
|
|
|
|
|
{
|
|
|
|
|
var img = new ImageSharp.Image(50, 50);
|
|
|
|
|
img.BackgroundColor(color);
|
|
|
|
|
return img;
|
|
|
|
|
}).Merge().ToStream();
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
t = new Timer(async (_) =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var color = hexColors[i];
|
|
|
|
|
await role.ModifyAsync(r => r.Color = new Discord.Color(color.R, color.G, color.B)).ConfigureAwait(false);
|
|
|
|
|
++i;
|
|
|
|
|
if (i >= hexColors.Length)
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}, null, 0, timeout * 1000);
|
|
|
|
|
|
|
|
|
|
rotatingRoleColors.AddOrUpdate(role.Id, t, (key, old) =>
|
|
|
|
|
{
|
|
|
|
|
old.Change(Timeout.Infinite, Timeout.Infinite);
|
|
|
|
|
return t;
|
|
|
|
|
});
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await channel.SendFileAsync(images, "magicalgirl.jpg", GetText("rrc_start", Format.Bold(role.Name))).ConfigureAwait(false);
|
2017-01-05 12:49:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2017-01-01 11:52:52 +00:00
|
|
|
|
public async Task TogetherTube()
|
2016-12-24 07:05:43 +00:00
|
|
|
|
{
|
|
|
|
|
Uri target;
|
|
|
|
|
using (var http = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
var res = await http.GetAsync("https://togethertube.com/room/create").ConfigureAwait(false);
|
|
|
|
|
target = res.RequestMessage.RequestUri;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-31 10:55:12 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
2016-12-24 07:05:43 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithIconUrl("https://togethertube.com/assets/img/favicons/favicon-32x32.png")
|
|
|
|
|
.WithName("Together Tube")
|
|
|
|
|
.WithUrl("https://togethertube.com/"))
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.WithDescription(Context.User.Mention + " " + GetText("togtub_room_link") + "\n" + target));
|
2016-12-24 07:05:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-13 18:45:08 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-02-22 17:16:05 +00:00
|
|
|
|
public async Task WhosPlaying([Remainder] string game)
|
2016-08-13 18:45:08 +00:00
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
game = game?.Trim().ToUpperInvariant();
|
2016-08-13 18:45:08 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(game))
|
|
|
|
|
return;
|
2017-01-29 21:54:27 +00:00
|
|
|
|
|
|
|
|
|
var socketGuild = Context.Guild as SocketGuild;
|
2017-02-06 08:35:49 +00:00
|
|
|
|
if (socketGuild == null)
|
|
|
|
|
{
|
2017-01-29 21:54:27 +00:00
|
|
|
|
_log.Warn("Can't cast guild to socket guild.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var rng = new NadekoRandom();
|
|
|
|
|
var arr = await Task.Run(() => socketGuild.Users
|
2016-08-15 14:57:40 +00:00
|
|
|
|
.Where(u => u.Game?.Name?.ToUpperInvariant() == game)
|
2016-08-13 18:45:08 +00:00
|
|
|
|
.Select(u => u.Username)
|
2017-01-29 21:54:27 +00:00
|
|
|
|
.OrderBy(x => rng.Next())
|
2017-01-26 07:02:57 +00:00
|
|
|
|
.Take(60)
|
2017-01-29 21:54:27 +00:00
|
|
|
|
.ToArray()).ConfigureAwait(false);
|
2016-08-13 18:45:08 +00:00
|
|
|
|
|
|
|
|
|
int i = 0;
|
2017-01-29 21:54:27 +00:00
|
|
|
|
if (arr.Length == 0)
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("nobody_playing_game").ConfigureAwait(false);
|
2017-01-29 21:54:27 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync("```css\n" + string.Join("\n", arr.GroupBy(item => (i++) / 2)
|
2016-12-08 15:40:59 +00:00
|
|
|
|
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) + "\n```")
|
|
|
|
|
.ConfigureAwait(false);
|
2017-01-29 21:54:27 +00:00
|
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-13 18:45:08 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-03-06 18:19:23 +00:00
|
|
|
|
public async Task InRole([Remainder] IRole role)
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2017-03-06 18:19:23 +00:00
|
|
|
|
|
2017-02-22 17:16:05 +00:00
|
|
|
|
var usrs = (await Context.Guild.GetUsersAsync()).ToArray();
|
2017-03-06 18:19:23 +00:00
|
|
|
|
var roleUsers = usrs.Where(u => u.RoleIds.Contains(role.Id)).Select(u => u.ToString()).ToArray();
|
|
|
|
|
var embed = new EmbedBuilder().WithOkColor()
|
|
|
|
|
.WithTitle("ℹ️ " + Format.Bold(GetText("inrole_list")) + $" - {roleUsers.Length}")
|
|
|
|
|
.WithDescription(string.Join(", ", roleUsers));
|
|
|
|
|
await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-15 14:57:40 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task CheckMyPerms()
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
|
|
|
|
|
2017-02-22 17:16:05 +00:00
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
var user = (IGuildUser) Context.User;
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var perms = user.GetPermissions((ITextChannel)Context.Channel);
|
2016-08-15 14:57:40 +00:00
|
|
|
|
foreach (var p in perms.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null)}");
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
2016-12-16 18:43:57 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(builder.ToString());
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-15 14:57:40 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task UserId(IGuildUser target = null)
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var usr = target ?? Context.User;
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyConfirmLocalized("userid", "🆔", Format.Bold(usr.ToString()),
|
|
|
|
|
Format.Code(usr.Id.ToString())).ConfigureAwait(false);
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task ChannelId()
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2017-03-01 16:12:38 +00:00
|
|
|
|
await ReplyConfirmLocalized("channelid", "🆔", Format.Code(Context.Channel.Id.ToString()))
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.ConfigureAwait(false);
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-15 14:57:40 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task ServerId()
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyConfirmLocalized("serverid", "🆔", Format.Code(Context.Guild.Id.ToString()))
|
|
|
|
|
.ConfigureAwait(false);
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-15 14:57:40 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Roles(IGuildUser target, int page = 1)
|
2016-08-15 14:57:40 +00:00
|
|
|
|
{
|
2016-12-16 18:43:57 +00:00
|
|
|
|
var channel = (ITextChannel)Context.Channel;
|
2016-09-13 16:12:27 +00:00
|
|
|
|
var guild = channel.Guild;
|
2016-10-10 00:27:33 +00:00
|
|
|
|
|
2017-02-22 17:16:05 +00:00
|
|
|
|
const int rolesPerPage = 20;
|
2016-10-10 00:27:33 +00:00
|
|
|
|
|
|
|
|
|
if (page < 1 || page > 100)
|
|
|
|
|
return;
|
2016-12-22 05:12:04 +00:00
|
|
|
|
|
2016-08-15 14:57:40 +00:00
|
|
|
|
if (target != null)
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
var roles = target.GetRoles().Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * rolesPerPage).Take(rolesPerPage).ToArray();
|
2016-12-21 11:52:01 +00:00
|
|
|
|
if (!roles.Any())
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("no_roles_on_page").ConfigureAwait(false);
|
2016-12-21 11:52:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
|
|
|
|
|
await channel.SendConfirmAsync(GetText("roles_page", page, Format.Bold(target.ToString())),
|
|
|
|
|
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions()).ConfigureAwait(false);
|
2016-12-21 11:52:01 +00:00
|
|
|
|
}
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
var roles = guild.Roles.Except(new[] { guild.EveryoneRole }).OrderBy(r => -r.Position).Skip((page - 1) * rolesPerPage).Take(rolesPerPage).ToArray();
|
2016-12-21 11:52:01 +00:00
|
|
|
|
if (!roles.Any())
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("no_roles_on_page").ConfigureAwait(false);
|
2016-12-21 11:52:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await channel.SendConfirmAsync(GetText("roles_all_page", page),
|
|
|
|
|
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions()).ConfigureAwait(false);
|
2016-12-21 11:52:01 +00:00
|
|
|
|
}
|
2016-08-15 14:57:40 +00:00
|
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
}
|
2016-08-18 21:00:54 +00:00
|
|
|
|
|
2016-10-10 00:27:33 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public Task Roles(int page = 1) =>
|
|
|
|
|
Roles(null, page);
|
2016-10-10 00:27:33 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-08-28 00:46:36 +00:00
|
|
|
|
[RequireContext(ContextType.Guild)]
|
2017-01-08 17:14:10 +00:00
|
|
|
|
public async Task ChannelTopic([Remainder]ITextChannel channel = null)
|
2016-08-28 00:46:36 +00:00
|
|
|
|
{
|
2017-01-08 17:14:10 +00:00
|
|
|
|
if (channel == null)
|
|
|
|
|
channel = (ITextChannel)Context.Channel;
|
2016-08-28 00:46:36 +00:00
|
|
|
|
|
|
|
|
|
var topic = channel.Topic;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(topic))
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("no_topic_set").ConfigureAwait(false);
|
2016-08-28 00:46:36 +00:00
|
|
|
|
else
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(GetText("channel_topic"), topic).ConfigureAwait(false);
|
2016-08-28 00:46:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-07 15:33:37 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[RequireBotPermission(ChannelPermission.CreateInstantInvite)]
|
|
|
|
|
[RequireUserPermission(ChannelPermission.CreateInstantInvite)]
|
|
|
|
|
public async Task CreateInvite()
|
|
|
|
|
{
|
|
|
|
|
var invite = await ((ITextChannel)Context.Channel).CreateInviteAsync(0, null, isUnique: true);
|
|
|
|
|
|
|
|
|
|
await Context.Channel.SendConfirmAsync($"{Context.User.Mention} https://discord.gg/{invite.Code}");
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 17:19:03 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
public async Task ShardStats(int page = 1)
|
|
|
|
|
{
|
2017-02-06 07:35:45 +00:00
|
|
|
|
if (page < 1)
|
2017-02-04 17:19:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2017-02-06 07:35:45 +00:00
|
|
|
|
var status = string.Join(", ", NadekoBot.Client.Shards.GroupBy(x => x.ConnectionState)
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.Select(x => $"{x.Count()} {x.Key}")
|
2017-02-06 07:35:45 +00:00
|
|
|
|
.ToArray());
|
2017-02-04 17:19:03 +00:00
|
|
|
|
|
2017-02-06 07:35:45 +00:00
|
|
|
|
var allShardStrings = NadekoBot.Client.Shards
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.Select(x =>
|
|
|
|
|
GetText("shard_stats_txt", x.ShardId.ToString(),
|
|
|
|
|
Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.Count.ToString())))
|
2017-02-06 07:35:45 +00:00
|
|
|
|
.ToArray();
|
2017-02-04 17:19:03 +00:00
|
|
|
|
|
|
|
|
|
|
2017-02-06 07:35:45 +00:00
|
|
|
|
|
2017-02-06 08:35:49 +00:00
|
|
|
|
await Context.Channel.SendPaginatedConfirmAsync(page, (curPage) =>
|
|
|
|
|
{
|
2017-02-06 07:35:45 +00:00
|
|
|
|
|
|
|
|
|
var str = string.Join("\n", allShardStrings.Skip(25 * (curPage - 1)).Take(25));
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(str))
|
2017-02-22 17:16:05 +00:00
|
|
|
|
str = GetText("no_shards_on_page");
|
2017-02-06 07:35:45 +00:00
|
|
|
|
|
|
|
|
|
return new EmbedBuilder()
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.WithAuthor(a => a.WithName(GetText("shard_stats")))
|
2017-02-06 07:35:45 +00:00
|
|
|
|
.WithTitle(status)
|
|
|
|
|
.WithOkColor()
|
|
|
|
|
.WithDescription(str);
|
|
|
|
|
}, allShardStrings.Length / 25);
|
2017-02-04 17:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 05:36:07 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
public async Task ShardId(ulong guildid)
|
|
|
|
|
{
|
|
|
|
|
var shardId = NadekoBot.Client.GetShardIdFor(guildid);
|
|
|
|
|
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync(shardId.ToString()).ConfigureAwait(false);
|
2017-02-05 05:36:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Stats()
|
2016-08-18 21:00:54 +00:00
|
|
|
|
{
|
2016-11-30 19:15:22 +00:00
|
|
|
|
var stats = NadekoBot.Stats;
|
|
|
|
|
|
2017-02-04 17:19:03 +00:00
|
|
|
|
var shardId = Context.Guild != null
|
|
|
|
|
? NadekoBot.Client.GetShardIdFor(Context.Guild.Id)
|
|
|
|
|
: 0;
|
|
|
|
|
|
2016-12-31 12:21:18 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(
|
2016-12-24 07:30:20 +00:00
|
|
|
|
new EmbedBuilder().WithOkColor()
|
2016-12-16 18:43:57 +00:00
|
|
|
|
.WithAuthor(eab => eab.WithName($"NadekoBot v{StatsService.BotVersion}")
|
|
|
|
|
.WithUrl("http://nadekobot.readthedocs.io/en/latest/")
|
|
|
|
|
.WithIconUrl("https://cdn.discordapp.com/avatars/116275390695079945/b21045e778ef21c96d175400e779f0fb.jpg"))
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.AddField(efb => efb.WithName(GetText("author")).WithValue(stats.Author).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("botid")).WithValue(NadekoBot.Client.CurrentUser.Id.ToString()).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("shard")).WithValue($"#{shardId} / {NadekoBot.Client.Shards.Count}").WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("commands_ran")).WithValue(stats.CommandsRan.ToString()).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("messages")).WithValue($"{stats.MessageCounter} ({stats.MessagesPerSecond:F2}/sec)").WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("memory")).WithValue($"{stats.Heap} MB").WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("owner_ids")).WithValue(string.Join("\n", NadekoBot.Credentials.OwnerIds)).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("uptime")).WithValue(stats.GetUptimeString("\n")).WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("presence")).WithValue(
|
|
|
|
|
GetText("presence_txt",
|
|
|
|
|
NadekoBot.Client.GetGuildCount(), stats.TextChannels, stats.VoiceChannels)).WithIsInline(true))
|
2017-02-06 06:53:27 +00:00
|
|
|
|
#if !GLOBAL_NADEKO
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.WithFooter(efb => efb.WithText(GetText("stats_songs",
|
|
|
|
|
Music.Music.MusicPlayers.Count(mp => mp.Value.CurrentSong != null),
|
|
|
|
|
Music.Music.MusicPlayers.Sum(mp => mp.Value.Playlist.Count))))
|
2017-02-06 06:53:27 +00:00
|
|
|
|
#endif
|
|
|
|
|
);
|
2016-08-18 21:00:54 +00:00
|
|
|
|
}
|
2016-10-06 17:19:42 +00:00
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-12-16 18:43:57 +00:00
|
|
|
|
public async Task Showemojis([Remainder] string emojis)
|
2016-10-06 17:19:42 +00:00
|
|
|
|
{
|
2017-01-14 22:23:11 +00:00
|
|
|
|
var tags = Context.Message.Tags.Where(t => t.Type == TagType.Emoji).Select(t => (Emoji)t.Value);
|
2016-10-06 17:19:42 +00:00
|
|
|
|
|
2017-02-22 17:16:05 +00:00
|
|
|
|
var result = string.Join("\n", tags.Select(m => GetText("showemojis", m, m.Url)));
|
2016-12-08 17:35:34 +00:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(result))
|
2017-03-01 16:12:38 +00:00
|
|
|
|
await ReplyErrorLocalized("showemojis_none").ConfigureAwait(false);
|
2016-12-08 17:35:34 +00:00
|
|
|
|
else
|
2016-12-16 18:43:57 +00:00
|
|
|
|
await Context.Channel.SendMessageAsync(result).ConfigureAwait(false);
|
2016-10-06 17:19:42 +00:00
|
|
|
|
}
|
2016-10-26 20:26:25 +00:00
|
|
|
|
|
2016-10-28 11:31:21 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
2016-12-21 08:33:47 +00:00
|
|
|
|
public async Task ListServers(int page = 1)
|
2016-10-28 11:31:21 +00:00
|
|
|
|
{
|
|
|
|
|
page -= 1;
|
|
|
|
|
|
|
|
|
|
if (page < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-01-07 18:56:44 +00:00
|
|
|
|
var guilds = await Task.Run(() => NadekoBot.Client.GetGuilds().OrderBy(g => g.Name).Skip((page - 1) * 15).Take(15)).ConfigureAwait(false);
|
2016-10-28 11:31:21 +00:00
|
|
|
|
|
|
|
|
|
if (!guilds.Any())
|
|
|
|
|
{
|
2017-02-22 17:16:05 +00:00
|
|
|
|
await ReplyErrorLocalized("listservers_none").ConfigureAwait(false);
|
2016-10-28 11:31:21 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-01 15:39:24 +00:00
|
|
|
|
await Context.Channel.EmbedAsync(guilds.Aggregate(new EmbedBuilder().WithOkColor(),
|
2016-12-08 15:40:59 +00:00
|
|
|
|
(embed, g) => embed.AddField(efb => efb.WithName(g.Name)
|
2017-02-22 17:16:05 +00:00
|
|
|
|
.WithValue(
|
|
|
|
|
GetText("listservers", g.Id, g.Users.Count,
|
|
|
|
|
g.OwnerId))
|
2016-12-16 18:43:57 +00:00
|
|
|
|
.WithIsInline(false))))
|
2016-12-08 15:40:59 +00:00
|
|
|
|
.ConfigureAwait(false);
|
2016-10-28 11:31:21 +00:00
|
|
|
|
}
|
2017-01-11 13:05:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SaveChat(int cnt)
|
|
|
|
|
{
|
|
|
|
|
var msgs = new List<IMessage>(cnt);
|
|
|
|
|
await Context.Channel.GetMessagesAsync(cnt).ForEachAsync(dled => msgs.AddRange(dled)).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
var title = $"Chatlog-{Context.Guild.Name}/#{Context.Channel.Name}-{DateTime.Now}.txt";
|
|
|
|
|
var grouping = msgs.GroupBy(x => $"{x.CreatedAt.Date:dd.MM.yyyy}")
|
|
|
|
|
.Select(g => new { date = g.Key, messages = g.OrderBy(x => x.CreatedAt).Select(s => $"【{s.Timestamp:HH:mm:ss}】{s.Author}:" + s.ToString()) });
|
|
|
|
|
await Context.User.SendFileAsync(
|
|
|
|
|
await JsonConvert.SerializeObject(grouping, Formatting.Indented).ToStream().ConfigureAwait(false), title, title).ConfigureAwait(false);
|
|
|
|
|
}
|
2016-08-13 18:45:08 +00:00
|
|
|
|
}
|
2017-02-06 06:53:27 +00:00
|
|
|
|
}
|