Fixed .setgame on sharded bots

This commit is contained in:
Kwoth 2016-10-14 08:21:45 +02:00
parent ff663c4331
commit 889050b8ae
6 changed files with 15 additions and 13 deletions

View File

@ -531,7 +531,7 @@ namespace NadekoBot.Modules.Administration
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
return; return;
await NadekoBot.Client.GetCurrentUser().ModifyAsync(u => u.Username = newName).ConfigureAwait(false); await (await NadekoBot.Client.GetCurrentUserAsync()).ModifyAsync(u => u.Username = newName).ConfigureAwait(false);
await channel.SendMessageAsync($"Successfully changed name to {newName}").ConfigureAwait(false); await channel.SendMessageAsync($"Successfully changed name to {newName}").ConfigureAwait(false);
} }
@ -554,7 +554,7 @@ namespace NadekoBot.Modules.Administration
await sr.CopyToAsync(imgStream); await sr.CopyToAsync(imgStream);
imgStream.Position = 0; imgStream.Position = 0;
await NadekoBot.Client.GetCurrentUser().ModifyAsync(u => u.Avatar = imgStream).ConfigureAwait(false); await (await NadekoBot.Client.GetCurrentUserAsync().ConfigureAwait(false)).ModifyAsync(u => u.Avatar = imgStream).ConfigureAwait(false);
} }
} }

View File

@ -52,10 +52,9 @@ namespace NadekoBot.Modules.Administration
if (string.IsNullOrWhiteSpace(status)) if (string.IsNullOrWhiteSpace(status))
continue; continue;
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value())); PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
await NadekoBot.Client await (await NadekoBot.Client.GetCurrentUserAsync())
.GetCurrentUser() .ModifyStatusAsync(mpp => mpp.Game = new Game(status))
.ModifyStatusAsync(mpp => mpp.Game = new Game(status)) .ConfigureAwait(false);
.ConfigureAwait(false);
} }
} }
catch (Exception ex) catch (Exception ex)

View File

@ -14,7 +14,7 @@ namespace NadekoBot.Modules.CustomReactions
{ {
public static Dictionary<string, Func<IUserMessage, string>> placeholders = new Dictionary<string, Func<IUserMessage, string>>() public static Dictionary<string, Func<IUserMessage, string>> placeholders = new Dictionary<string, Func<IUserMessage, string>>()
{ {
{"%mention%", (ctx) => { return $"<@{NadekoBot.Client.GetCurrentUser().Id}>"; } }, {"%mention%", (ctx) => { return $"<@{NadekoBot.Client.GetCurrentUserAsync().Id}>"; } },
{"%user%", (ctx) => { return ctx.Author.Mention; } }, {"%user%", (ctx) => { return ctx.Author.Mention; } },
{"%target%", (ctx) => { return ctx.MentionedUsers.Shuffle().FirstOrDefault()?.Mention ?? "Nobody"; } }, {"%target%", (ctx) => { return ctx.MentionedUsers.Shuffle().FirstOrDefault()?.Mention ?? "Nobody"; } },
{"%rng%", (ctx) => { return new NadekoRandom().Next(0,10).ToString(); } } {"%rng%", (ctx) => { return new NadekoRandom().Next(0,10).ToString(); } }

View File

@ -62,8 +62,8 @@ namespace NadekoBot.Services.Impl
{ {
public ulong ClientId { get; set; } public ulong ClientId { get; set; }
public ulong? BotId { get; set; } public ulong? BotId { get; set; }
public string Token { get; set; } public string Token { get; set; } = "";
public ulong[] OwnerIds { get; set; } public ulong[] OwnerIds { get; set; } = new ulong[1];
public string LoLApiKey { get; set; } public string LoLApiKey { get; set; }
public string GoogleApiKey { get; set; } public string GoogleApiKey { get; set; }
public string MashapeKey { get; set; } public string MashapeKey { get; set; }

View File

@ -35,7 +35,7 @@ namespace NadekoBot.Services.Impl
} }
public Task<string> Print() public Task<string> Print()
{ {
var curUser = client.GetCurrentUser(); var curUser = client.GetCurrentUserAsync();
return Task.FromResult($@"`Author: Kwoth` `Library: Discord.Net` return Task.FromResult($@"`Author: Kwoth` `Library: Discord.Net`
`Bot Version: {BotVersion}` `Bot Version: {BotVersion}`
`Bot id: {curUser.Id}` `Bot id: {curUser.Id}`

View File

@ -65,7 +65,10 @@ namespace NadekoBot
} }
public ISelfUser GetCurrentUser() => public ISelfUser GetCurrentUser() =>
Clients.Select(c => c.GetCurrentUser()).FirstOrDefault(u => u != null); Clients[0].GetCurrentUser();
public Task<ISelfUser> GetCurrentUserAsync() =>
Clients[0].GetCurrentUserAsync();
public IReadOnlyCollection<IGuild> GetGuilds() => public IReadOnlyCollection<IGuild> GetGuilds() =>
Clients.SelectMany(c => c.GetGuilds()).ToArray(); Clients.SelectMany(c => c.GetGuilds()).ToArray();
@ -74,7 +77,7 @@ namespace NadekoBot
Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null); Clients.Select(c => c.GetGuild(id)).FirstOrDefault(g => g != null);
public Task<IDMChannel> GetDMChannelAsync(ulong channelId) => public Task<IDMChannel> GetDMChannelAsync(ulong channelId) =>
Clients.Select(async c => await c.GetDMChannelAsync(channelId).ConfigureAwait(false)).FirstOrDefault(c => c != null); Clients[0].GetDMChannelAsync(channelId);
internal Task LoginAsync(TokenType tokenType, string token) => internal Task LoginAsync(TokenType tokenType, string token) =>
Task.WhenAll(Clients.Select(async c => { await c.LoginAsync(tokenType, token); _log.Info($"Shard #{c.ShardId} logged in."); })); Task.WhenAll(Clients.Select(async c => { await c.LoginAsync(tokenType, token); _log.Info($"Shard #{c.ShardId} logged in."); }));