Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Commit af6a743

Browse files
committed
Try and catch these exceptions
1 parent cd06891 commit af6a743

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

BotHATTwaffle2/src/Handlers/CommandHandler.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,31 +304,33 @@ Disabled since Discord added large message embeds
304304
$"\n`{message.Content}`" +
305305
$"\n`{message.Channel}`");
306306
}
307-
308-
if(blacklistCheck)
307+
try
308+
{
309+
if (blacklistCheck)
309310
if (new BlacklistHandler(_dataService.Blacklist, message, _dataService).CheckBlacklist())
310311
{
311-
try
312-
{
312+
313313
await message.DeleteAsync();
314-
}
315-
catch (Exception e)
316-
{
317-
string error = $"Issue deleting a black list message.\n`{e}`" +
318-
$"\n\n`{message.Author}`" +
319-
$"\n`{message.Content}`" +
320-
$"\n`{message.Channel}`";
321-
322-
if (error.Length > 1800)
323-
error = error.Substring(0, 1800);
324-
325-
//Sometimes this would cause a crash. I think it is due to the user not being a guild user in some situations.
326-
await _log.LogMessage(error);
327-
}
314+
328315

329316
return;
330317
}
331318

319+
}
320+
catch (Exception e)
321+
{
322+
string error = $"Issue deleting a black list message.\n`{e}`" +
323+
$"\n\n`{message.Author}`" +
324+
$"\n`{message.Content}`" +
325+
$"\n`{message.Channel}`";
326+
327+
if (error.Length > 1800)
328+
error = error.Substring(0, 1800);
329+
330+
//Sometimes this would cause a crash. I think it is due to the user not being a guild user in some situations.
331+
await _log.LogMessage(error);
332+
}
333+
332334
// Embed Steam workshop links
333335
if (message.Content.Contains("://steamcommunity.com/sharedfiles/filedetails/",
334336
StringComparison.OrdinalIgnoreCase) || message.Content.Contains(

BotHATTwaffle2/src/Handlers/ScheduleHandler.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ScheduleHandler
3131
private bool _allowPlayingCycle = true;
3232
private int _playtestCount;
3333
private string _lastBannerPath;
34+
const string PLAYERBASE_URL = @"https://www.tophattwaffle.com/demos/playerBase/fetchPlayers.php";
3435

3536
public ScheduleHandler(DataService data, DiscordSocketClient client, LogHandler log,
3637
PlaytestService playtestService
@@ -271,12 +272,18 @@ protected override WebRequest GetWebRequest(Uri uri)
271272

272273
private async Task UpdatePlayerbase()
273274
{
274-
const string playerbaseUrl = @"https://www.tophattwaffle.com/demos/playerBase/fetchPlayers.php";
275-
var webClient = new TimeoutWebClient { Timeout = 120};
276-
var response = webClient.DownloadString(playerbaseUrl).Trim();
275+
try
276+
{
277+
var webClient = new TimeoutWebClient { Timeout = 120};
278+
var response = webClient.DownloadString(PLAYERBASE_URL).Trim();
277279

278-
await _log.LogMessage($"Got the following response when updating playerbase: `{response}`",
279-
color: LOG_COLOR);
280+
await _log.LogMessage($"Got the following response when updating playerbase: `{response}`",
281+
color: LOG_COLOR);
282+
}
283+
catch (Exception e)
284+
{
285+
await _log.LogMessage($"Failed to update playbase!\n{e}", false, color: LOG_COLOR);
286+
}
280287
}
281288

282289
private async Task DailyDemoRequests()

0 commit comments

Comments
 (0)