2017-01-01 15:39:24 +00:00
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
2016-12-11 16:18:25 +00:00
|
|
|
|
using NadekoBot.Extensions;
|
2017-01-01 15:39:24 +00:00
|
|
|
|
using System;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-01-01 15:39:24 +00:00
|
|
|
|
using System.IO;
|
2016-09-30 02:24:56 +00:00
|
|
|
|
using System.Linq;
|
2017-01-01 15:39:24 +00:00
|
|
|
|
using System.Net.Http;
|
2016-09-30 02:24:56 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
using Discord.WebSocket;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2017-03-31 12:07:18 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NadekoBot.Common.Attributes;
|
|
|
|
|
using NadekoBot.Modules.Administration.Services;
|
2017-10-10 16:24:36 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NadekoBot.Common.ShardCom;
|
2017-10-23 02:28:49 +00:00
|
|
|
|
using Discord.Net;
|
2016-06-05 17:24:09 +00:00
|
|
|
|
|
2016-09-30 02:24:56 +00:00
|
|
|
|
namespace NadekoBot.Modules.Administration
|
|
|
|
|
{
|
|
|
|
|
public partial class Administration
|
|
|
|
|
{
|
|
|
|
|
[Group]
|
2017-07-15 16:34:34 +00:00
|
|
|
|
public class SelfCommands : NadekoSubmodule<SelfService>
|
2016-09-30 02:24:56 +00:00
|
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
|
private readonly DbService _db;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
|
|
|
|
|
private static readonly object _locker = new object();
|
2017-06-19 13:42:10 +00:00
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
private readonly IImagesService _images;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
private readonly IBotConfigProvider _bc;
|
2017-09-14 17:37:41 +00:00
|
|
|
|
private readonly NadekoBot _bot;
|
2017-09-27 06:32:33 +00:00
|
|
|
|
private readonly IBotCredentials _creds;
|
2017-10-10 16:24:36 +00:00
|
|
|
|
private readonly IDataCache _cache;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
|
2017-09-14 17:37:41 +00:00
|
|
|
|
public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client,
|
2017-09-29 22:46:33 +00:00
|
|
|
|
IImagesService images, IBotConfigProvider bc,
|
2017-10-10 16:24:36 +00:00
|
|
|
|
IBotCredentials creds, IDataCache cache)
|
2017-02-14 16:22:57 +00:00
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
_db = db;
|
|
|
|
|
_client = client;
|
|
|
|
|
_images = images;
|
2017-07-20 03:10:39 +00:00
|
|
|
|
_bc = bc;
|
2017-09-14 17:37:41 +00:00
|
|
|
|
_bot = bot;
|
2017-09-27 06:32:33 +00:00
|
|
|
|
_creds = creds;
|
2017-10-10 16:24:36 +00:00
|
|
|
|
_cache = cache;
|
2017-03-31 12:07:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task StartupCommandAdd([Remainder] string cmdText)
|
|
|
|
|
{
|
2017-10-09 00:57:03 +00:00
|
|
|
|
if (cmdText.StartsWith(Prefix + "die"))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-03-31 12:07:18 +00:00
|
|
|
|
var guser = ((IGuildUser)Context.User);
|
|
|
|
|
var cmd = new StartupCommand()
|
|
|
|
|
{
|
|
|
|
|
CommandText = cmdText,
|
|
|
|
|
ChannelId = Context.Channel.Id,
|
|
|
|
|
ChannelName = Context.Channel.Name,
|
|
|
|
|
GuildId = Context.Guild?.Id,
|
|
|
|
|
GuildName = Context.Guild?.Name,
|
|
|
|
|
VoiceChannelId = guser.VoiceChannel?.Id,
|
|
|
|
|
VoiceChannelName = guser.VoiceChannel?.Name,
|
|
|
|
|
};
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-03-31 12:07:18 +00:00
|
|
|
|
{
|
|
|
|
|
uow.BotConfig
|
|
|
|
|
.GetOrCreate(set => set.Include(x => x.StartupCommands))
|
|
|
|
|
.StartupCommands.Add(cmd);
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
|
|
|
|
.WithTitle(GetText("scadd"))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("server"))
|
|
|
|
|
.WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("channel"))
|
|
|
|
|
.WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true))
|
|
|
|
|
.AddField(efb => efb.WithName(GetText("command_text"))
|
|
|
|
|
.WithValue(cmdText).WithIsInline(false)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task StartupCommands(int page = 1)
|
|
|
|
|
{
|
|
|
|
|
if (page < 1)
|
|
|
|
|
return;
|
|
|
|
|
page -= 1;
|
|
|
|
|
IEnumerable<StartupCommand> scmds;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-03-31 12:07:18 +00:00
|
|
|
|
{
|
|
|
|
|
scmds = uow.BotConfig
|
|
|
|
|
.GetOrCreate(set => set.Include(x => x.StartupCommands))
|
|
|
|
|
.StartupCommands
|
|
|
|
|
.OrderBy(x => x.Id)
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
scmds = scmds.Skip(page * 5).Take(5);
|
|
|
|
|
if (!scmds.Any())
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("startcmdlist_none").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-13 12:15:46 +00:00
|
|
|
|
await Context.Channel.SendConfirmAsync("", string.Join("\n", scmds.Select(x =>
|
2017-03-31 12:07:18 +00:00
|
|
|
|
{
|
2017-07-13 12:15:46 +00:00
|
|
|
|
string str = $"```css\n[{GetText("server") + "]: " + (x.GuildId == null ? "-" : x.GuildName + " #" + x.GuildId)}";
|
2017-03-31 12:07:18 +00:00
|
|
|
|
|
|
|
|
|
str += $@"
|
2017-07-13 12:15:46 +00:00
|
|
|
|
[{GetText("channel")}]: {x.ChannelName} #{x.ChannelId}
|
|
|
|
|
[{GetText("command_text")}]: {x.CommandText}```";
|
2017-03-31 12:07:18 +00:00
|
|
|
|
return str;
|
2017-05-19 08:02:29 +00:00
|
|
|
|
})), footer: GetText("page", page + 1))
|
2017-03-31 12:07:18 +00:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Wait(int miliseconds)
|
|
|
|
|
{
|
|
|
|
|
if (miliseconds <= 0)
|
2017-05-19 08:02:29 +00:00
|
|
|
|
return;
|
2017-03-31 12:07:18 +00:00
|
|
|
|
Context.Message.DeleteAfter(0);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var msg = await Context.Channel.SendConfirmAsync($"⏲ {miliseconds}ms")
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
msg.DeleteAfter(miliseconds / 1000);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
await Task.Delay(miliseconds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task StartupCommandRemove([Remainder] string cmdText)
|
|
|
|
|
{
|
|
|
|
|
StartupCommand cmd;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-03-31 12:07:18 +00:00
|
|
|
|
{
|
|
|
|
|
var cmds = uow.BotConfig
|
|
|
|
|
.GetOrCreate(set => set.Include(x => x.StartupCommands))
|
|
|
|
|
.StartupCommands;
|
|
|
|
|
cmd = cmds
|
|
|
|
|
.FirstOrDefault(x => x.CommandText.ToLowerInvariant() == cmdText.ToLowerInvariant());
|
|
|
|
|
|
|
|
|
|
if (cmd != null)
|
|
|
|
|
{
|
|
|
|
|
cmds.Remove(cmd);
|
|
|
|
|
await uow.CompleteAsync().ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 08:02:29 +00:00
|
|
|
|
if (cmd == null)
|
2017-03-31 12:07:18 +00:00
|
|
|
|
await ReplyErrorLocalized("scrm_fail").ConfigureAwait(false);
|
|
|
|
|
else
|
|
|
|
|
await ReplyConfirmLocalized("scrm").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireContext(ContextType.Guild)]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task StartupCommandsClear()
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-03-31 12:07:18 +00:00
|
|
|
|
{
|
|
|
|
|
uow.BotConfig
|
|
|
|
|
.GetOrCreate(set => set.Include(x => x.StartupCommands))
|
|
|
|
|
.StartupCommands
|
|
|
|
|
.Clear();
|
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ReplyConfirmLocalized("startcmds_cleared").ConfigureAwait(false);
|
2017-02-14 16:22:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task ForwardMessages()
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-02-14 16:22:57 +00:00
|
|
|
|
{
|
2017-10-26 09:31:44 +00:00
|
|
|
|
var config = uow.BotConfig.GetOrCreate(set => set);
|
2017-07-20 03:10:39 +00:00
|
|
|
|
config.ForwardMessages = !config.ForwardMessages;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
2017-07-20 03:10:39 +00:00
|
|
|
|
_bc.Reload();
|
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
if (_service.ForwardDMs)
|
2017-02-14 16:22:57 +00:00
|
|
|
|
await ReplyConfirmLocalized("fwdm_start").ConfigureAwait(false);
|
|
|
|
|
else
|
|
|
|
|
await ReplyConfirmLocalized("fwdm_stop").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task ForwardToAll()
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using (var uow = _db.UnitOfWork)
|
2017-02-14 16:22:57 +00:00
|
|
|
|
{
|
2017-10-26 09:31:44 +00:00
|
|
|
|
var config = uow.BotConfig.GetOrCreate(set => set);
|
2017-02-14 16:22:57 +00:00
|
|
|
|
lock (_locker)
|
2017-07-20 03:10:39 +00:00
|
|
|
|
config.ForwardToAllOwners = !config.ForwardToAllOwners;
|
2017-02-14 16:22:57 +00:00
|
|
|
|
uow.Complete();
|
|
|
|
|
}
|
2017-07-20 03:10:39 +00:00
|
|
|
|
_bc.Reload();
|
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
if (_service.ForwardDMsToAllOwners)
|
2017-02-14 16:22:57 +00:00
|
|
|
|
await ReplyConfirmLocalized("fwall_start").ConfigureAwait(false);
|
|
|
|
|
else
|
|
|
|
|
await ReplyConfirmLocalized("fwall_stop").ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
}
|
2017-06-11 14:54:10 +00:00
|
|
|
|
|
2017-10-10 16:24:36 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
public async Task ShardStats(int page = 1)
|
|
|
|
|
{
|
|
|
|
|
if (--page < 0)
|
|
|
|
|
return;
|
|
|
|
|
var db = _cache.Redis.GetDatabase();
|
|
|
|
|
var statuses = db.ListRange(_creds.RedisKey() + "_shardstats")
|
|
|
|
|
.Select(x => JsonConvert.DeserializeObject<ShardComMessage>(x));
|
|
|
|
|
|
|
|
|
|
var status = string.Join(", ", statuses
|
|
|
|
|
.GroupBy(x => x.ConnectionState)
|
|
|
|
|
.Select(x => $"{x.Count()} {x.Key}")
|
|
|
|
|
.ToArray());
|
|
|
|
|
|
|
|
|
|
var allShardStrings = statuses
|
|
|
|
|
.Select(x =>
|
|
|
|
|
{
|
|
|
|
|
var timeDiff = DateTime.UtcNow - x.Time;
|
2017-10-23 17:46:59 +00:00
|
|
|
|
if (timeDiff >= TimeSpan.FromSeconds(30))
|
2017-10-10 16:24:36 +00:00
|
|
|
|
return $"Shard #{Format.Bold(x.ShardId.ToString())} **UNRESPONSIVE** for {timeDiff.ToString(@"hh\:mm\:ss")}";
|
|
|
|
|
return GetText("shard_stats_txt", x.ShardId.ToString(),
|
|
|
|
|
Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.ToString()), timeDiff.ToString(@"hh\:mm\:ss"));
|
|
|
|
|
})
|
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
|
|
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25));
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(str))
|
|
|
|
|
str = GetText("no_shards_on_page");
|
|
|
|
|
|
|
|
|
|
return new EmbedBuilder()
|
|
|
|
|
.WithAuthor(a => a.WithName(GetText("shard_stats")))
|
|
|
|
|
.WithTitle(status)
|
|
|
|
|
.WithOkColor()
|
|
|
|
|
.WithDescription(str);
|
2017-10-17 14:10:51 +00:00
|
|
|
|
}, allShardStrings.Length, 25);
|
2017-10-10 16:24:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task RestartShard(int shardid)
|
|
|
|
|
{
|
|
|
|
|
if (shardid < 0 || shardid >= _creds.TotalShards)
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("no_shard_id").ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var pub = _cache.Redis.GetSubscriber();
|
2017-10-29 09:49:39 +00:00
|
|
|
|
pub.Publish(_creds.RedisKey() + "_shardcoord_restart",
|
2017-10-10 16:24:36 +00:00
|
|
|
|
JsonConvert.SerializeObject(_client.ShardId),
|
|
|
|
|
StackExchange.Redis.CommandFlags.FireAndForget);
|
|
|
|
|
await ReplyConfirmLocalized("shard_reconnecting", Format.Bold("#" + shardid)).ConfigureAwait(false);
|
|
|
|
|
}
|
2017-02-04 17:45:07 +00:00
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-09-30 02:24:56 +00:00
|
|
|
|
[OwnerOnly]
|
2016-12-17 00:16:14 +00:00
|
|
|
|
public async Task Leave([Remainder] string guildStr)
|
2016-09-30 02:24:56 +00:00
|
|
|
|
{
|
|
|
|
|
guildStr = guildStr.Trim().ToUpperInvariant();
|
2017-05-27 08:19:27 +00:00
|
|
|
|
var server = _client.Guilds.FirstOrDefault(g => g.Id.ToString() == guildStr) ??
|
|
|
|
|
_client.Guilds.FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == guildStr);
|
2016-08-20 14:02:06 +00:00
|
|
|
|
|
2016-09-30 02:24:56 +00:00
|
|
|
|
if (server == null)
|
|
|
|
|
{
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyErrorLocalized("no_server").ConfigureAwait(false);
|
2016-09-30 02:24:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-27 08:19:27 +00:00
|
|
|
|
if (server.OwnerId != _client.CurrentUser.Id)
|
2016-09-30 02:24:56 +00:00
|
|
|
|
{
|
|
|
|
|
await server.LeaveAsync().ConfigureAwait(false);
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("left_server", Format.Bold(server.Name)).ConfigureAwait(false);
|
2016-09-30 02:24:56 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await server.DeleteAsync().ConfigureAwait(false);
|
2017-03-31 12:07:18 +00:00
|
|
|
|
await ReplyConfirmLocalized("deleted_server", Format.Bold(server.Name)).ConfigureAwait(false);
|
2016-09-30 02:24:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-01 15:39:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Die()
|
|
|
|
|
{
|
2017-02-14 21:07:28 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await ReplyConfirmLocalized("shutting_down").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2017-01-01 15:39:24 +00:00
|
|
|
|
await Task.Delay(2000).ConfigureAwait(false);
|
2017-10-22 14:09:51 +00:00
|
|
|
|
var sub = _cache.Redis.GetSubscriber();
|
|
|
|
|
sub.Publish(_creds.RedisKey() + "_die", "", StackExchange.Redis.CommandFlags.FireAndForget);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 06:32:33 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Restart()
|
|
|
|
|
{
|
|
|
|
|
var cmd = _creds.RestartCommand;
|
|
|
|
|
if (cmd == null || string.IsNullOrWhiteSpace(cmd.Cmd))
|
|
|
|
|
{
|
|
|
|
|
await ReplyErrorLocalized("restart_fail").ConfigureAwait(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ReplyConfirmLocalized("restarting").ConfigureAwait(false);
|
|
|
|
|
Process.Start(cmd.Cmd, cmd.Args);
|
2017-10-24 02:29:03 +00:00
|
|
|
|
var sub = _cache.Redis.GetSubscriber();
|
|
|
|
|
sub.Publish(_creds.RedisKey() + "_die", "", StackExchange.Redis.CommandFlags.FireAndForget);
|
2017-09-27 06:32:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-01 15:39:24 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SetName([Remainder] string newName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(newName))
|
|
|
|
|
return;
|
|
|
|
|
|
2017-10-23 02:28:49 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await _client.CurrentUser.ModifyAsync(u => u.Username = newName).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (RateLimitedException)
|
|
|
|
|
{
|
|
|
|
|
_log.Warn("You've been ratelimited. Wait 2 hours to change your name.");
|
|
|
|
|
}
|
2017-01-01 15:39:24 +00:00
|
|
|
|
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("bot_name", Format.Bold(newName)).ConfigureAwait(false);
|
2017-01-04 15:53:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-11 14:54:10 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageNicknames)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(0)]
|
2017-06-11 14:54:10 +00:00
|
|
|
|
public async Task SetNick([Remainder] string newNick = null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(newNick))
|
|
|
|
|
return;
|
|
|
|
|
var curUser = await Context.Guild.GetCurrentUserAsync();
|
|
|
|
|
await curUser.ModifyAsync(u => u.Nickname = newNick).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
await ReplyConfirmLocalized("bot_nick", Format.Bold(newNick) ?? "-").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[RequireBotPermission(GuildPermission.ManageNicknames)]
|
|
|
|
|
[RequireUserPermission(GuildPermission.ManageNicknames)]
|
2017-07-15 03:04:16 +00:00
|
|
|
|
[Priority(1)]
|
2017-06-11 14:54:10 +00:00
|
|
|
|
public async Task SetNick(IGuildUser gu, [Remainder] string newNick = null)
|
|
|
|
|
{
|
|
|
|
|
await gu.ModifyAsync(u => u.Nickname = newNick).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
await ReplyConfirmLocalized("user_nick", Format.Bold(gu.ToString()), Format.Bold(newNick) ?? "-").ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-04 15:53:39 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SetStatus([Remainder] SettableUserStatus status)
|
|
|
|
|
{
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _client.SetStatusAsync(SettableUserStatusToUserStatus(status)).ConfigureAwait(false);
|
2017-01-04 15:53:39 +00:00
|
|
|
|
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("bot_status", Format.Bold(status.ToString())).ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SetAvatar([Remainder] string img = null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(img))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
using (var http = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
using (var sr = await http.GetStreamAsync(img))
|
|
|
|
|
{
|
|
|
|
|
var imgStream = new MemoryStream();
|
|
|
|
|
await sr.CopyToAsync(imgStream);
|
|
|
|
|
imgStream.Position = 0;
|
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _client.CurrentUser.ModifyAsync(u => u.Avatar = new Image(imgStream)).ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("set_avatar").ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SetGame([Remainder] string game = null)
|
|
|
|
|
{
|
2017-09-14 17:37:41 +00:00
|
|
|
|
await _bot.SetGameAsync(game).ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("set_game").ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task SetStream(string url, [Remainder] string name = null)
|
|
|
|
|
{
|
|
|
|
|
name = name ?? "";
|
|
|
|
|
|
2017-05-27 08:19:27 +00:00
|
|
|
|
await _client.SetGameAsync(name, url, StreamType.Twitch).ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("set_stream").ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task Send(string where, [Remainder] string msg = null)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(msg))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var ids = where.Split('|');
|
|
|
|
|
if (ids.Length != 2)
|
|
|
|
|
return;
|
|
|
|
|
var sid = ulong.Parse(ids[0]);
|
2017-05-27 08:19:27 +00:00
|
|
|
|
var server = _client.Guilds.FirstOrDefault(s => s.Id == sid);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
|
|
|
|
|
if (server == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (ids[1].ToUpperInvariant().StartsWith("C:"))
|
|
|
|
|
{
|
|
|
|
|
var cid = ulong.Parse(ids[1].Substring(2));
|
2017-02-14 16:22:57 +00:00
|
|
|
|
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
if (ch == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await ch.SendMessageAsync(msg).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else if (ids[1].ToUpperInvariant().StartsWith("U:"))
|
|
|
|
|
{
|
|
|
|
|
var uid = ulong.Parse(ids[1].Substring(2));
|
2017-02-14 16:22:57 +00:00
|
|
|
|
var user = server.Users.FirstOrDefault(u => u.Id == uid);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await user.SendMessageAsync(msg).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyErrorLocalized("invalid_format").ConfigureAwait(false);
|
|
|
|
|
return;
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
2017-02-14 21:07:28 +00:00
|
|
|
|
await ReplyConfirmLocalized("message_sent").ConfigureAwait(false);
|
2017-01-01 15:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-03 08:54:22 +00:00
|
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
|
[OwnerOnly]
|
|
|
|
|
public async Task ReloadImages()
|
|
|
|
|
{
|
2017-06-19 13:42:10 +00:00
|
|
|
|
var sw = Stopwatch.StartNew();
|
|
|
|
|
_images.Reload();
|
|
|
|
|
sw.Stop();
|
|
|
|
|
await ReplyConfirmLocalized("images_loaded", sw.Elapsed.TotalSeconds.ToString("F3")).ConfigureAwait(false);
|
2017-02-03 08:54:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:08:14 +00:00
|
|
|
|
private static UserStatus SettableUserStatusToUserStatus(SettableUserStatus sus)
|
|
|
|
|
{
|
|
|
|
|
switch (sus)
|
|
|
|
|
{
|
|
|
|
|
case SettableUserStatus.Online:
|
|
|
|
|
return UserStatus.Online;
|
|
|
|
|
case SettableUserStatus.Invisible:
|
|
|
|
|
return UserStatus.Invisible;
|
|
|
|
|
case SettableUserStatus.Idle:
|
|
|
|
|
return UserStatus.AFK;
|
|
|
|
|
case SettableUserStatus.Dnd:
|
|
|
|
|
return UserStatus.DoNotDisturb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return UserStatus.Online;
|
|
|
|
|
}
|
2017-02-02 02:21:02 +00:00
|
|
|
|
|
|
|
|
|
public enum SettableUserStatus
|
|
|
|
|
{
|
|
|
|
|
Online,
|
|
|
|
|
Invisible,
|
|
|
|
|
Idle,
|
|
|
|
|
Dnd
|
|
|
|
|
}
|
2016-09-30 02:24:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-31 12:07:18 +00:00
|
|
|
|
}
|