From 23aee061cd2bbd6d93842a9dc3be8a596f849642 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 14 Feb 2016 16:48:46 +0100 Subject: [PATCH] removed (Exception) from catches, added -readme/-guide command --- NadekoBot/Classes/Music/StreamRequest.cs | 4 ++-- NadekoBot/Classes/NadekoStats.cs | 4 ++-- NadekoBot/Classes/SearchHelper.cs | 6 +++--- NadekoBot/Commands/DiceRollCommand.cs | 2 +- NadekoBot/Commands/HelpCommand.cs | 5 +++++ NadekoBot/Commands/RequestsCommand.cs | 2 +- NadekoBot/Commands/SpeedTyping.cs | 2 +- NadekoBot/Modules/Administration.cs | 24 ++++++++++++------------ NadekoBot/Modules/Conversations.cs | 6 +++--- NadekoBot/Modules/Searches.cs | 4 ++-- NadekoBot/NadekoBot.cs | 4 ++-- 11 files changed, 34 insertions(+), 29 deletions(-) diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index 877f64a3..8d3c7c64 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -192,7 +192,7 @@ namespace NadekoBot.Classes.Music { try { p.CancelOutputRead(); p.Close(); - } catch (Exception) { } + } catch { } Console.WriteLine("Buffering canceled, stream is completed."); return; } @@ -221,7 +221,7 @@ namespace NadekoBot.Classes.Music { try { p.CancelOutputRead(); p.Close(); - } catch (Exception) { } + } catch { } Console.WriteLine($"Didn't read anything from the stream for {attempt} attempts. {buffer.Length/1.MB()}MB length"); return; diff --git a/NadekoBot/Classes/NadekoStats.cs b/NadekoBot/Classes/NadekoStats.cs index 57dd7c35..33ac4a4d 100644 --- a/NadekoBot/Classes/NadekoStats.cs +++ b/NadekoBot/Classes/NadekoStats.cs @@ -89,7 +89,7 @@ namespace NadekoBot ConnectedServers = connectedServers, DateAdded = DateTime.Now }); - } catch (Exception) { + } catch { Console.WriteLine("DB Exception in stats collecting."); break; } @@ -110,7 +110,7 @@ namespace NadekoBot CommandName = e.Command.Text, DateAdded = DateTime.Now }); - } catch (Exception) { + } catch { Console.WriteLine("Parse error in ran command."); } } diff --git a/NadekoBot/Classes/SearchHelper.cs b/NadekoBot/Classes/SearchHelper.cs index 2a003e12..a148563d 100644 --- a/NadekoBot/Classes/SearchHelper.cs +++ b/NadekoBot/Classes/SearchHelper.cs @@ -47,7 +47,7 @@ namespace NadekoBot.Classes { rq = new RestSharp.RestRequest("anime/" + smallObj["id"]); rq.AddParameter("access_token", token); return await Task.Run(() => JsonConvert.DeserializeObject(cl.Execute(rq).Content)); - } catch (Exception) { + } catch { return null; } } @@ -174,7 +174,7 @@ namespace NadekoBot.Classes { var matches = Regex.Matches(webpage, "data-large-file-url=\"(?.*?)\""); return await $"http://danbooru.donmai.us{ matches[rng.Next(0, matches.Count)].Groups["id"].Value }".ShortenUrl(); - } catch (Exception) { + } catch { return null; } } @@ -190,7 +190,7 @@ namespace NadekoBot.Classes { //now extract the image from post page var match = Regex.Match(webpage, "\"(?http://simg4.gelbooru.com//images.*?)\""); return match.Groups["url"].Value; - } catch (Exception) { + } catch { return null; } } diff --git a/NadekoBot/Commands/DiceRollCommand.cs b/NadekoBot/Commands/DiceRollCommand.cs index 98c21632..74588fae 100644 --- a/NadekoBot/Commands/DiceRollCommand.cs +++ b/NadekoBot/Commands/DiceRollCommand.cs @@ -58,7 +58,7 @@ namespace NadekoBot { Bitmap bitmap = dices.Merge(); await e.Send(values.Count + " Dies rolled. Total: **" + values.Sum() + "** Average: **" + (values.Sum() / (1.0f * values.Count)).ToString("N2") + "**"); await e.Channel.SendFile("dices.png", bitmap.ToStream(ImageFormat.Png)); - } catch (Exception) { + } catch { await e.Send("Please enter a number of dices to roll."); return; } diff --git a/NadekoBot/Commands/HelpCommand.cs b/NadekoBot/Commands/HelpCommand.cs index b733d834..f02d0059 100644 --- a/NadekoBot/Commands/HelpCommand.cs +++ b/NadekoBot/Commands/HelpCommand.cs @@ -61,6 +61,11 @@ namespace NadekoBot cgb.CreateCommand("-hgit") .Description("Help command stylized for github readme") .Do(DoGitFunc()); + cgb.CreateCommand("-readme") + .Alias("-guide") + .Description("Sends a readme and a guide links to the channel.") + .Do(async e => + await e.Send("**FULL README**: \n\n**GUIDE ONLY**: ")); } private string PrintCommandHelp(Command com) diff --git a/NadekoBot/Commands/RequestsCommand.cs b/NadekoBot/Commands/RequestsCommand.cs index 61e3849c..7bd16904 100644 --- a/NadekoBot/Commands/RequestsCommand.cs +++ b/NadekoBot/Commands/RequestsCommand.cs @@ -52,7 +52,7 @@ namespace NadekoBot.Commands { try { SaveRequest(e, str); - } catch (Exception) { + } catch { await e.Send("Something went wrong."); return; } diff --git a/NadekoBot/Commands/SpeedTyping.cs b/NadekoBot/Commands/SpeedTyping.cs index a7474415..b3d9ff40 100644 --- a/NadekoBot/Commands/SpeedTyping.cs +++ b/NadekoBot/Commands/SpeedTyping.cs @@ -14,7 +14,7 @@ namespace NadekoBot.Commands { var data = Classes.DBHandler.Instance.GetAllRows(); try { return data.ToList()[new Random().Next(0, data.Count())].Text; - } catch (Exception) { + } catch { return "Failed retrieving data from parse. Owner didn't add any articles to type using `typeadd`."; } } diff --git a/NadekoBot/Modules/Administration.cs b/NadekoBot/Modules/Administration.cs index ce78d356..f1a63fa9 100644 --- a/NadekoBot/Modules/Administration.cs +++ b/NadekoBot/Modules/Administration.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Modules { await usr.RemoveRoles(new Role[] { role }); await e.Send($"Successfully removed role **{role.Name}** from user **{usr.Name}**"); } catch (InvalidOperationException) { - } catch (Exception) { + } catch { await e.Send("Failed to remove roles. Most likely reason: Insufficient permissions."); } }); @@ -199,7 +199,7 @@ namespace NadekoBot.Modules { await usr.Server.Unban(usr); await e.Send("Unbanned user " + usr.Name + " Id: " + usr.Id); } - } catch (Exception) { } + } catch { } }); cgb.CreateCommand(".k").Alias(".kick") @@ -212,7 +212,7 @@ namespace NadekoBot.Modules { await e.Message.MentionedUsers.First().Kick(); await e.Send("Kicked user " + usr.Name + " Id: " + usr.Id); } - } catch (Exception) { + } catch { await e.Send("No sufficient permissions."); } }); @@ -231,7 +231,7 @@ namespace NadekoBot.Modules { await u.Edit(isMuted: true); } await e.Send("Mute successful"); - } catch (Exception) { + } catch { await e.Send("I do not have permission to do that most likely."); } }); @@ -251,7 +251,7 @@ namespace NadekoBot.Modules { await u.Edit(isMuted: false); } await e.Send("Unmute successful"); - } catch (Exception) { + } catch { await e.Send("I do not have permission to do that most likely."); } }); @@ -272,7 +272,7 @@ namespace NadekoBot.Modules { await u.Edit(isDeafened: true); } await e.Send("Deafen successful"); - } catch (Exception) { + } catch { await e.Send("I do not have permission to do that most likely."); } }); @@ -293,7 +293,7 @@ namespace NadekoBot.Modules { await u.Edit(isDeafened: false); } await e.Send("Undeafen successful"); - } catch (Exception) { + } catch { await e.Send("I do not have permission to do that most likely."); } }); @@ -307,7 +307,7 @@ namespace NadekoBot.Modules { await e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Voice).FirstOrDefault()?.Delete(); await e.Send($"Removed channel **{e.GetArg("channel_name")}**."); } - } catch (Exception) { + } catch { await e.Send("No sufficient permissions."); } }); @@ -321,7 +321,7 @@ namespace NadekoBot.Modules { await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Voice); await e.Send($"Created voice channel **{e.GetArg("channel_name")}**."); } - } catch (Exception) { + } catch { await e.Send("No sufficient permissions."); } }); @@ -335,7 +335,7 @@ namespace NadekoBot.Modules { await e.Server.FindChannels(e.GetArg("channel_name"), ChannelType.Text).FirstOrDefault()?.Delete(); await e.Send($"Removed text channel **{e.GetArg("channel_name")}**."); } - } catch (Exception) { + } catch { await e.Send("No sufficient permissions."); } }); @@ -349,7 +349,7 @@ namespace NadekoBot.Modules { await e.Server.CreateChannel(e.GetArg("channel_name"), ChannelType.Text); await e.Send($"Added text channel **{e.GetArg("channel_name")}**."); } - } catch (Exception) { + } catch { await e.Send("No sufficient permissions."); } }); @@ -361,7 +361,7 @@ namespace NadekoBot.Modules { try { if (e.User.ServerPermissions.ManageChannels) await e.Channel.Edit(topic: e.GetArg("topic")); - } catch (Exception) { } + } catch { } }); cgb.CreateCommand(".uid").Alias(".userid") diff --git a/NadekoBot/Modules/Conversations.cs b/NadekoBot/Modules/Conversations.cs index 3493a637..b1c10a17 100644 --- a/NadekoBot/Modules/Conversations.cs +++ b/NadekoBot/Modules/Conversations.cs @@ -101,7 +101,7 @@ namespace NadekoBot.Modules { "\n**Online Members:** " + server.Users.Where(u => u.Status == UserStatus.Online).Count() + "\n**Invite:** " + inv.Url); break; - } catch (Exception) { continue; } + } catch { continue; } } }); /* @@ -272,7 +272,7 @@ namespace NadekoBot.Modules { try { await (await client.GetInvite(e.Args[0])).Accept(); await e.Send("I got in!"); - } catch (Exception) { + } catch { await e.Send("Invalid code."); } }); @@ -352,7 +352,7 @@ namespace NadekoBot.Modules { var invite = await s.CreateInvite(0); invites += invite.Url + "\n"; i++; - } catch (Exception) { + } catch { j++; continue; } diff --git a/NadekoBot/Modules/Searches.cs b/NadekoBot/Modules/Searches.cs index 966974d0..4b181446 100644 --- a/NadekoBot/Modules/Searches.cs +++ b/NadekoBot/Modules/Searches.cs @@ -79,7 +79,7 @@ namespace NadekoBot.Modules { .GetResponse() .GetResponseStream()) .ReadToEnd())["file"].ToString()); - } catch (Exception) { } + } catch { } }); cgb.CreateCommand("~i") @@ -176,7 +176,7 @@ namespace NadekoBot.Modules { try { await e.Channel.SendFile($"{e.GetArg("usr")}.png", new MemoryStream(cle.Result)); await e.Send($"`Profile Link:`https://osu.ppy.sh/u/{Uri.EscapeDataString(e.GetArg("usr"))}\n`Image provided by https://lemmmy.pw/osusig`"); - } catch (Exception) { } + } catch { } }; } catch { await e.Channel.SendMessage("💢 Failed retrieving osu signature :\\"); diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 3dc3c136..5146c822 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -110,7 +110,7 @@ namespace NadekoBot { try { OwnerPrivateChannel = await client.CreatePrivateChannel(OwnerID); - } catch (Exception) { + } catch { Console.WriteLine("Failed creating private channel with the owner"); } @@ -146,7 +146,7 @@ namespace NadekoBot { await (await client.GetInvite(e.Message.Text)).Accept(); await e.Send("I got in!"); return; - } catch (Exception) { + } catch { if (e.User.Id == 109338686889476096) { //carbonitex invite await e.Send("Failed to join the server."); return;