Playing status fixed? Added a lot of catches to try to fix the error
This commit is contained in:
parent
c24281d17b
commit
0c7d077df1
@ -749,7 +749,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
game = game ?? "";
|
||||
|
||||
await NadekoBot.Client.GetCurrentUser().ModifyStatusAsync(u => u.Game = new Game(game)).ConfigureAwait(false);
|
||||
await NadekoBot.Client.SetGame(game).ConfigureAwait(false);
|
||||
|
||||
await channel.SendMessageAsync("`New game set.`").ConfigureAwait(false);
|
||||
}
|
||||
@ -763,7 +763,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
name = name ?? "";
|
||||
|
||||
await NadekoBot.Client.GetCurrentUser().ModifyStatusAsync(u => u.Game = new Game(name, url, StreamType.Twitch)).ConfigureAwait(false);
|
||||
await NadekoBot.Client.SetStream(name, url).ConfigureAwait(false);
|
||||
|
||||
await channel.SendMessageAsync("`New stream set.`").ConfigureAwait(false);
|
||||
}
|
||||
|
@ -101,23 +101,25 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
AntiSpamSetting spamSettings;
|
||||
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings))
|
||||
return;
|
||||
|
||||
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, new UserSpamStats(msg.Content),
|
||||
(id, old) => { old.ApplyNextMessage(msg.Content); return old; });
|
||||
|
||||
if (stats.Count >= spamSettings.MessageThreshold)
|
||||
try
|
||||
{
|
||||
if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats))
|
||||
{
|
||||
var log = await PunishUser((IGuildUser)msg.Author, spamSettings.Action, spamSettings.MuteRole, ProtectionType.Spamming)
|
||||
.ConfigureAwait(false);
|
||||
try { await channel.Guild.SendMessageToOwnerAsync(log).ConfigureAwait(false); } catch { }
|
||||
}
|
||||
}
|
||||
AntiSpamSetting spamSettings;
|
||||
if (!antiSpamGuilds.TryGetValue(channel.Guild.Id, out spamSettings))
|
||||
return;
|
||||
|
||||
var stats = spamSettings.UserStats.AddOrUpdate(msg.Author.Id, new UserSpamStats(msg.Content),
|
||||
(id, old) => { old.ApplyNextMessage(msg.Content); return old; });
|
||||
|
||||
if (stats.Count >= spamSettings.MessageThreshold)
|
||||
{
|
||||
if (spamSettings.UserStats.TryRemove(msg.Author.Id, out stats))
|
||||
{
|
||||
var log = await PunishUser((IGuildUser)msg.Author, spamSettings.Action, spamSettings.MuteRole, ProtectionType.Spamming)
|
||||
.ConfigureAwait(false);
|
||||
await channel.Guild.SendMessageToOwnerAsync(log).ConfigureAwait(false); }
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
@ -27,19 +27,23 @@ namespace NadekoBot.Modules.Administration
|
||||
{
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
GuildConfig conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
try
|
||||
{
|
||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||
GuildConfig conf;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
conf = uow.GuildConfigs.For(user.Guild.Id);
|
||||
}
|
||||
|
||||
if (conf.AutoAssignRoleId == 0)
|
||||
return;
|
||||
|
||||
var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId);
|
||||
|
||||
if (role != null)
|
||||
await user.AddRolesAsync(role);
|
||||
}
|
||||
|
||||
if (conf.AutoAssignRoleId == 0)
|
||||
return;
|
||||
|
||||
var role = user.Guild.Roles.FirstOrDefault(r => r.Id == conf.AutoAssignRoleId);
|
||||
|
||||
if (role != null)
|
||||
try { await user.AddRolesAsync(role); } catch (Exception ex) { _log.Warn(ex); }
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
@ -36,17 +36,17 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
|
||||
foreach (var subscriber in Subscribers)
|
||||
if (msg.Author.Id == NadekoBot.Client.GetCurrentUser().Id) return;
|
||||
foreach (var subscriber in Subscribers)
|
||||
{
|
||||
var set = subscriber.Value;
|
||||
if (!set.Contains(msg.Channel))
|
||||
continue;
|
||||
foreach (var chan in set.Except(new[] { channel }))
|
||||
{
|
||||
var set = subscriber.Value;
|
||||
if (!set.Contains(msg.Channel))
|
||||
continue;
|
||||
foreach (var chan in set.Except(new[] { channel }))
|
||||
{
|
||||
try { await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)msg.Author, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
try { await chan.SendMessageAsync(GetText(channel.Guild, channel, (IGuildUser)msg.Author, msg)).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
@ -90,29 +90,33 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
string str = $"🕔`{prettyCurrentTime}`";
|
||||
if (before.Username != after.Username)
|
||||
str += $"**Name Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
|
||||
else if (before.Nickname != after.Nickname)
|
||||
str += $"**Nickname Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}";
|
||||
else if (before.AvatarUrl != after.AvatarUrl)
|
||||
str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
|
||||
else if (!before.Roles.SequenceEqual(after.Roles))
|
||||
try
|
||||
{
|
||||
if (before.Roles.Count() < after.Roles.Count())
|
||||
string str = $"🕔`{prettyCurrentTime}`";
|
||||
if (before.Username != after.Username)
|
||||
str += $"**Name Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`New:`{after.ToString()}`";
|
||||
else if (before.Nickname != after.Nickname)
|
||||
str += $"**Nickname Changed**👤`{before.Username}#{before.Discriminator}`\n\t\t`Old:` {before.Nickname}#{before.Discriminator}\n\t\t`New:` {after.Nickname}#{after.Discriminator}";
|
||||
else if (before.AvatarUrl != after.AvatarUrl)
|
||||
str += $"**Avatar Changed**👤`{before.Username}#{before.Discriminator}`\n\t {await _google.ShortenUrl(before.AvatarUrl)} `=>` {await _google.ShortenUrl(after.AvatarUrl)}";
|
||||
else if (!before.Roles.SequenceEqual(after.Roles))
|
||||
{
|
||||
var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
str += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
|
||||
}
|
||||
else if (before.Roles.Count() > after.Roles.Count())
|
||||
{
|
||||
var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
str += $"**User's Roles changed ⚔➖**👤`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
|
||||
if (before.Roles.Count() < after.Roles.Count())
|
||||
{
|
||||
var diffRoles = after.Roles.Where(r => !before.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
str += $"**User's Roles changed ⚔➕**👤`{before.ToString()}`\n\tNow has {string.Join(", ", diffRoles)} role.";
|
||||
}
|
||||
else if (before.Roles.Count() > after.Roles.Count())
|
||||
{
|
||||
var diffRoles = before.Roles.Where(r => !after.Roles.Contains(r)).Select(r => "`" + r.Name + "`");
|
||||
str += $"**User's Roles changed ⚔➖**👤`{before.ToString()}`\n\tNo longer has {string.Join(", ", diffRoles)} role.";
|
||||
}
|
||||
}
|
||||
else
|
||||
return;
|
||||
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
}
|
||||
else
|
||||
return;
|
||||
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
catch { }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
@ -138,14 +142,18 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
if (before.Name != after.Name)
|
||||
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id})
|
||||
try
|
||||
{
|
||||
if (before.Name != after.Name)
|
||||
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Name Changed** `#{after.Name}` ({after.Id})
|
||||
`Old:` {before.Name}
|
||||
`New:` {after.Name}").ConfigureAwait(false);
|
||||
else if ((before as ITextChannel).Topic != (after as ITextChannel).Topic)
|
||||
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{after.Name}` ({after.Id})
|
||||
else if ((before as ITextChannel).Topic != (after as ITextChannel).Topic)
|
||||
await logChannel.SendMessageAsync($@"`{prettyCurrentTime}` **Channel Topic Changed** `#{after.Name}` ({after.Id})
|
||||
`Old:` {((ITextChannel)before).Topic}
|
||||
`New:` {((ITextChannel)after).Topic}").ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
@ -365,11 +373,15 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
var str = $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{channel.Name}`
|
||||
👤`{msg.Author.Username}`: {msg.Resolve(userHandling:UserMentionHandling.NameAndDiscriminator)}";
|
||||
if (msg.Attachments.Any())
|
||||
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
|
||||
try { await logChannel.SendMessageAsync(str).ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
|
||||
try
|
||||
{
|
||||
var str = $@"🕔`{prettyCurrentTime}` **Message** 🚮 `#{channel.Name}`
|
||||
👤`{msg.Author.Username}`: {msg.Resolve(userHandling: UserMentionHandling.NameAndDiscriminator)}";
|
||||
if (msg.Attachments.Any())
|
||||
str += $"{Environment.NewLine}`Attachements`: {string.Join(", ", msg.Attachments.Select(a => a.ProxyUrl))}";
|
||||
await logChannel.SendMessageAsync(str).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex) { _log.Warn(ex); }
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
@ -377,6 +389,7 @@ namespace NadekoBot.Modules.Administration
|
||||
|
||||
private Task _client_MessageUpdated(Optional<IMessage> optmsg, IMessage imsg2)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
var after = imsg2 as IUserMessage;
|
||||
if (after == null || after.IsAuthor())
|
||||
return Task.CompletedTask;
|
||||
|
@ -58,9 +58,7 @@ namespace NadekoBot.Modules.Administration
|
||||
if (string.IsNullOrWhiteSpace(status))
|
||||
continue;
|
||||
PlayingPlaceholders.ForEach(e => status = status.Replace(e.Key, e.Value()));
|
||||
await (await NadekoBot.Client.GetCurrentUserAsync())
|
||||
.ModifyStatusAsync(mpp => mpp.Game = new Game(status))
|
||||
.ConfigureAwait(false);
|
||||
await NadekoBot.Client.SetGame(status);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -39,9 +39,10 @@ namespace NadekoBot.Modules.Administration
|
||||
return Task.CompletedTask;
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
var botUserPerms = guild.GetCurrentUser().GuildPermissions;
|
||||
try
|
||||
{
|
||||
var botUserPerms = guild.GetCurrentUser().GuildPermissions;
|
||||
|
||||
if (before.VoiceChannel == after.VoiceChannel) return;
|
||||
|
||||
if (!voicePlusTextCache.Contains(guild.Id))
|
||||
|
@ -186,6 +186,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
await Task.Delay(2500);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
NadekoBot.Client.MessageReceived -= Client_MessageReceived;
|
||||
|
@ -35,10 +35,14 @@ namespace NadekoBot.Modules.Gambling
|
||||
var num2 = gen % 10;
|
||||
var imageStream = await Task.Run(() =>
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
try
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
new[] { GetDice(num1), GetDice(num2) }.Merge().SaveAsPng(ms);
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
}
|
||||
catch { return new MemoryStream(); }
|
||||
});
|
||||
|
||||
await channel.SendFileAsync(imageStream, "dice.png", $"{umsg.Author.Mention} rolled " + Format.Code(gen.ToString())).ConfigureAwait(false);
|
||||
|
@ -42,7 +42,7 @@ namespace NadekoBot.Modules.Games.Trivia
|
||||
this.guild = guild;
|
||||
this.channel = channel;
|
||||
WinRequirement = winReq;
|
||||
Task.Run(StartGame);
|
||||
Task.Run(async () => { try { await StartGame().ConfigureAwait(false); } catch { } });
|
||||
}
|
||||
|
||||
private async Task StartGame()
|
||||
|
@ -306,7 +306,7 @@ namespace NadekoBot.Modules.Music.Classes
|
||||
var link = (await NadekoBot.Google.GetVideosByKeywordsAsync(query).ConfigureAwait(false)).FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(link))
|
||||
throw new OperationCanceledException("Not a valid youtube query.");
|
||||
var allVideos = await Task.Run(async () => await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false)).ConfigureAwait(false);
|
||||
var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty<YouTubeVideo>(); } }).ConfigureAwait(false);
|
||||
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
|
||||
var video = videos
|
||||
.Where(v => v.AudioBitrate < 192)
|
||||
|
@ -799,9 +799,10 @@ namespace NadekoBot.Modules.Music
|
||||
var queuedMessage = await textCh.SendMessageAsync($"🎵`Queued`{resolvedSong.PrettyName} **at** `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false);
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(10000).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await Task.Delay(10000).ConfigureAwait(false);
|
||||
|
||||
await queuedMessage.DeleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
catch { }
|
||||
|
@ -112,8 +112,12 @@ namespace NadekoBot.Modules.Permissions
|
||||
});
|
||||
var t = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(cdRule.Seconds * 1000);
|
||||
activeCdsForGuild.RemoveWhere(ac => ac.Command == cmd.Text.ToLowerInvariant() && ac.UserId == user.Id);
|
||||
try
|
||||
{
|
||||
await Task.Delay(cdRule.Seconds * 1000);
|
||||
activeCdsForGuild.RemoveWhere(ac => ac.Command == cmd.Text.ToLowerInvariant() && ac.UserId == user.Id);
|
||||
}
|
||||
catch { }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace NadekoBot.Modules.Searches
|
||||
var smallObj = JArray.Parse(res)[0];
|
||||
var aniData = await http.GetStringAsync("http://anilist.co/api/anime/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||
|
||||
return await Task.Run(() => JsonConvert.DeserializeObject<AnimeResult>(aniData)).ConfigureAwait(false);
|
||||
return await Task.Run(() => { try { return JsonConvert.DeserializeObject<AnimeResult>(aniData); } catch { return null; } }).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Searches
|
||||
var smallObj = JArray.Parse(res)[0];
|
||||
var aniData = await http.GetStringAsync("http://anilist.co/api/manga/" + smallObj["id"] + $"?access_token={anilistToken}").ConfigureAwait(false);
|
||||
|
||||
return await Task.Run(() => JsonConvert.DeserializeObject<MangaResult>(aniData)).ConfigureAwait(false);
|
||||
return await Task.Run(() => { try { return JsonConvert.DeserializeObject<MangaResult>(aniData); } catch { return null; } }).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -9,6 +9,7 @@ using Discord.API;
|
||||
using Discord.Logging;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NadekoBot.Extensions;
|
||||
|
||||
namespace NadekoBot
|
||||
{
|
||||
@ -70,6 +71,9 @@ namespace NadekoBot
|
||||
public Task<ISelfUser> GetCurrentUserAsync() =>
|
||||
Clients[0].GetCurrentUserAsync();
|
||||
|
||||
public Task<ISelfUser[]> GetAllCurrentUsersAsync() =>
|
||||
Task.WhenAll(Clients.Select(c => c.GetCurrentUserAsync()));
|
||||
|
||||
public IReadOnlyCollection<IGuild> GetGuilds() =>
|
||||
Clients.SelectMany(c => c.GetGuilds()).ToArray();
|
||||
|
||||
@ -87,5 +91,18 @@ namespace NadekoBot
|
||||
|
||||
internal Task DownloadAllUsersAsync() =>
|
||||
Task.WhenAll(Clients.Select(async c => { await c.DownloadAllUsersAsync(); _log.Info($"Shard #{c.ShardId} downloaded {c.GetGuilds().Sum(g => g.GetUsers().Count)} users."); }));
|
||||
|
||||
public async Task SetGame(string game)
|
||||
{
|
||||
await Task.WhenAll((await GetAllCurrentUsersAsync())
|
||||
.Select(u => u.ModifyStatusAsync(ms => ms.Game = new Discord.Game(game))));
|
||||
}
|
||||
|
||||
public async Task SetStream(string name, string url)
|
||||
{
|
||||
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