commit
b57b35e826
@ -1 +1 @@
|
||||
Subproject commit 508026d5d4f4d8780d983c63ab25e4c15ad69e59
|
||||
Subproject commit ae614b68b336941bf780b5f3c74bf7f6ea505316
|
@ -69,6 +69,8 @@ namespace NadekoBot.Modules.Administration
|
||||
try
|
||||
{
|
||||
var usrMsg = umsg as IUserMessage;
|
||||
if (usrMsg == null)
|
||||
return;
|
||||
var channel = usrMsg.Channel as ITextChannel;
|
||||
|
||||
if (channel == null || usrMsg.IsAuthor())
|
||||
|
@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Games.Commands.Hangman
|
||||
|
||||
if (msg.Channel != GameChannel)
|
||||
return; // message's channel has to be the same as game's
|
||||
if (msg.Content.Length != 1) // message must be 1 char long
|
||||
if (msg.Content.Length == 1) // message must be 1 char long
|
||||
{
|
||||
if (++MessagesSinceLastPost > 10)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
Title = svideo.FullName,
|
||||
Provider = "SoundCloud",
|
||||
Uri = svideo.StreamLink,
|
||||
ProviderType = MusicType.Normal,
|
||||
ProviderType = MusicType.Soundcloud,
|
||||
Query = svideo.TrackLink,
|
||||
AlbumArt = svideo.artwork_url,
|
||||
})
|
||||
|
@ -105,7 +105,7 @@ namespace NadekoBot.Modules.NSFW
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Yandere(IUserMessage umsg, [Remainder] string tag = null)
|
||||
=> Searches.Searches.InternalDapiSearch(tag, Searches.Searches.DapiSearchType.Yandere);
|
||||
=> Searches.Searches.InternalDapiCommand(umsg, tag, Searches.Searches.DapiSearchType.Yandere);
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
|
@ -266,17 +266,16 @@ namespace NadekoBot.Modules.Searches
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithAuthor(eab => eab.WithName("Search For: " + terms)
|
||||
.WithAuthor(eab => eab.WithName("Search For: " + terms.TrimTo(50))
|
||||
.WithUrl(fullQueryLink)
|
||||
.WithIconUrl("http://i.imgur.com/G46fm8J.png"))
|
||||
.WithTitle(umsg.Author.Mention)
|
||||
.WithFooter(efb => efb.WithText(totalResults));
|
||||
string desc = "";
|
||||
foreach (GoogleSearchResult res in results)
|
||||
{
|
||||
desc += $"[{Format.Bold(res.Title)}]({res.Link})\n{res.Text}\n\n";
|
||||
}
|
||||
await channel.EmbedAsync(embed.WithDescription(desc).Build()).ConfigureAwait(false);
|
||||
|
||||
var desc = await Task.WhenAll(results.Select(async res =>
|
||||
$"[{Format.Bold(res?.Title)}]({(await NadekoBot.Google.ShortenUrl(res?.Link))})\n{res?.Text}\n\n"))
|
||||
.ConfigureAwait(false);
|
||||
await channel.EmbedAsync(embed.WithDescription(String.Concat(desc)).Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
@ -664,17 +663,17 @@ namespace NadekoBot.Modules.Searches
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Avatar(IUserMessage umsg, [Remainder] string mention = null)
|
||||
public async Task Avatar(IUserMessage umsg, [Remainder] IUser usr = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
|
||||
var usr = umsg.MentionedUsers.FirstOrDefault();
|
||||
if (usr == null)
|
||||
{
|
||||
await channel.SendErrorAsync("Invalid user specified.").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await channel.SendMessageAsync(await NadekoBot.Google.ShortenUrl(usr.AvatarUrl).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
usr = umsg.Author;
|
||||
|
||||
await channel.EmbedAsync(new EmbedBuilder().WithOkColor()
|
||||
.WithTitle($"{usr}'s Avatar")
|
||||
.WithImageUrl(usr.AvatarUrl)
|
||||
.Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
|
@ -91,7 +91,7 @@ namespace NadekoBot
|
||||
//connect
|
||||
await Client.LoginAsync(TokenType.Bot, Credentials.Token).ConfigureAwait(false);
|
||||
await Client.ConnectAsync().ConfigureAwait(false);
|
||||
await Client.DownloadAllUsersAsync().ConfigureAwait(false);
|
||||
//await Client.DownloadAllUsersAsync().ConfigureAwait(false);
|
||||
|
||||
_log.Info("Connected");
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace NadekoBot.Services.Impl
|
||||
private ShardedDiscordClient client;
|
||||
private DateTime started;
|
||||
|
||||
public const string BotVersion = "1.0-rc2";
|
||||
public const string BotVersion = "1.0.0";
|
||||
|
||||
public string Author => "Kwoth#2560";
|
||||
public string Library => "Discord.Net";
|
||||
|
@ -5,32 +5,36 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace NadekoBot
|
||||
{
|
||||
public class ShardedDiscordClient
|
||||
public class ShardedDiscordClient
|
||||
{
|
||||
private DiscordSocketConfig discordSocketConfig;
|
||||
private Logger _log { get; }
|
||||
|
||||
public event Action<IGuildUser> UserJoined = delegate { };
|
||||
public event Action<IMessage> MessageReceived = delegate { };
|
||||
public event Action<IGuildUser> UserLeft = delegate { };
|
||||
public event Action<IGuildUser, IGuildUser> UserUpdated = delegate { };
|
||||
public event Action<Optional<IMessage>, IMessage> MessageUpdated = delegate { };
|
||||
public event Action<ulong, Optional<IMessage>> MessageDeleted = delegate { };
|
||||
public event Action<IUser, IGuild> UserBanned = delegate { };
|
||||
public event Action<IUser, IGuild> UserUnbanned = delegate { };
|
||||
public event Action<IGuildUser, IPresence, IPresence> UserPresenceUpdated = delegate { };
|
||||
public event Action<IUser, IVoiceState, IVoiceState> UserVoiceStateUpdated = delegate { };
|
||||
public event Action<IChannel> ChannelCreated = delegate { };
|
||||
public event Action<IChannel> ChannelDestroyed = delegate { };
|
||||
public event Action<IGuildUser> UserJoined = delegate { };
|
||||
public event Action<IMessage> MessageReceived = delegate { };
|
||||
public event Action<IGuildUser> UserLeft = delegate { };
|
||||
public event Action<IGuildUser, IGuildUser> UserUpdated = delegate { };
|
||||
public event Action<Optional<IMessage>, IMessage> MessageUpdated = delegate { };
|
||||
public event Action<ulong, Optional<IMessage>> MessageDeleted = delegate { };
|
||||
public event Action<IUser, IGuild> UserBanned = delegate { };
|
||||
public event Action<IUser, IGuild> UserUnbanned = delegate { };
|
||||
public event Action<IGuildUser, IPresence, IPresence> UserPresenceUpdated = delegate { };
|
||||
public event Action<IUser, IVoiceState, IVoiceState> UserVoiceStateUpdated = delegate { };
|
||||
public event Action<IChannel> ChannelCreated = delegate { };
|
||||
public event Action<IChannel> ChannelDestroyed = delegate { };
|
||||
public event Action<IChannel, IChannel> ChannelUpdated = delegate { };
|
||||
public event Action<Exception> Disconnected = delegate { };
|
||||
public event Action<Exception> Disconnected = delegate { };
|
||||
|
||||
private uint _connectedCount = 0;
|
||||
private uint _downloadedCount = 0;
|
||||
|
||||
private IReadOnlyList<DiscordSocketClient> Clients { get; }
|
||||
|
||||
public ShardedDiscordClient (DiscordSocketConfig discordSocketConfig)
|
||||
public ShardedDiscordClient(DiscordSocketConfig discordSocketConfig)
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
this.discordSocketConfig = discordSocketConfig;
|
||||
@ -42,7 +46,12 @@ namespace NadekoBot
|
||||
var client = new DiscordSocketClient(discordSocketConfig);
|
||||
clientList.Add(client);
|
||||
client.UserJoined += arg1 => { UserJoined(arg1); return Task.CompletedTask; };
|
||||
client.MessageReceived += arg1 => { MessageReceived(arg1); return Task.CompletedTask; };
|
||||
client.MessageReceived += arg1 =>
|
||||
{
|
||||
if (arg1.Author == null || arg1.Author.IsBot)
|
||||
return Task.CompletedTask; MessageReceived(arg1);
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
client.UserLeft += arg1 => { UserLeft(arg1); return Task.CompletedTask; };
|
||||
client.UserUpdated += (arg1, gu2) => { UserUpdated(arg1, gu2); return Task.CompletedTask; };
|
||||
client.MessageUpdated += (arg1, m2) => { MessageUpdated(arg1, m2); return Task.CompletedTask; };
|
||||
@ -82,14 +91,15 @@ namespace NadekoBot
|
||||
internal Task LoginAsync(TokenType tokenType, string token) =>
|
||||
Task.WhenAll(Clients.Select(async c => { await c.LoginAsync(tokenType, token).ConfigureAwait(false); _log.Info($"Shard #{c.ShardId} logged in."); }));
|
||||
|
||||
internal async Task ConnectAsync()
|
||||
{
|
||||
foreach (var c in Clients)
|
||||
internal Task ConnectAsync() =>
|
||||
Task.WhenAll(Clients.Select(async c =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
await c.ConnectAsync().ConfigureAwait(false);
|
||||
_log.Info($"Shard #{c.ShardId} connected.");
|
||||
sw.Stop();
|
||||
_log.Info($"Shard #{c.ShardId} connected after {sw.Elapsed.TotalSeconds}s ({++_connectedCount}/{Clients.Count})");
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -101,11 +111,16 @@ namespace NadekoBot
|
||||
_log.Error(ex2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
internal Task DownloadAllUsersAsync() =>
|
||||
Task.WhenAll(Clients.Select(async c => { await c.DownloadAllUsersAsync().ConfigureAwait(false); _log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users."); }));
|
||||
Task.WhenAll(Clients.Select(async c =>
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
await c.DownloadAllUsersAsync().ConfigureAwait(false);
|
||||
sw.Stop();
|
||||
_log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users after {sw.Elapsed.TotalSeconds}s ({++_downloadedCount}/{Clients.Count}).");
|
||||
}));
|
||||
|
||||
public async Task SetGame(string game)
|
||||
{
|
||||
@ -117,7 +132,7 @@ namespace NadekoBot
|
||||
{
|
||||
await Task.WhenAll((await GetAllCurrentUsersAsync())
|
||||
.Select(u => u.ModifyStatusAsync(ms => ms.Game = new Discord.Game(name, url, StreamType.Twitch))));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user