workaround for an exception being thrown when shouldn't
This commit is contained in:
parent
4f70bba30c
commit
bc3e583926
44
Program.cs
44
Program.cs
@ -46,7 +46,7 @@ namespace silverworker_discord
|
||||
Console.WriteLine("Bot is connected! going to sign up for message received and user joined in client ready");
|
||||
botChatterChannel = _client.GetChannel(ulong.Parse(config["botChatterChannel"])) as ISocketMessageChannel;
|
||||
announcementChannel = _client.GetChannel(ulong.Parse(config["announcementChannel"])) as ISocketMessageChannel;
|
||||
mtgChannel= _client.GetChannel(ulong.Parse(config["mtgChannel"])) as ISocketMessageChannel;
|
||||
mtgChannel = _client.GetChannel(ulong.Parse(config["mtgChannel"])) as ISocketMessageChannel;
|
||||
|
||||
_client.MessageReceived += MessageReceived;
|
||||
_client.UserJoined += UserJoined;
|
||||
@ -74,7 +74,7 @@ namespace silverworker_discord
|
||||
{
|
||||
await twitchery.twitcherize(type, subData);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
await message.Channel.SendMessageAsync($"aaaadam!\n{JsonConvert.SerializeObject(e)}");
|
||||
}
|
||||
@ -94,11 +94,11 @@ namespace silverworker_discord
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(message.Channel.Id == mtgChannel.Id)
|
||||
else if (message.Channel.Id == mtgChannel.Id)
|
||||
{
|
||||
Console.WriteLine("magic channel, checking if card search");
|
||||
var cardSearch = new Regex("\\[([^\\]]+)\\]").Matches(message.Content);
|
||||
if(cardSearch.Count > 0)
|
||||
if (cardSearch.Count > 0)
|
||||
{
|
||||
Console.WriteLine($"looks like I should search scryfall for {cardSearch[0]}");
|
||||
scryfallSearch(cardSearch[0].Value, message);
|
||||
@ -124,41 +124,43 @@ namespace silverworker_discord
|
||||
}
|
||||
|
||||
private async void scryfallSearch(string cardName, SocketUserMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = WebRequest.Create("https://api.scryfall.com/cards/named?fuzzy=" + cardName.Replace(' ', '+'));
|
||||
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
|
||||
if(response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
|
||||
using (var dataStream = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
string responseFromServer = dataStream.ReadToEnd();
|
||||
var cardObj = JsonConvert.DeserializeObject<Scryfalltypes.Card>(responseFromServer);
|
||||
if(cardObj != null){
|
||||
if(cardObj.image_uris.png == null)
|
||||
if (cardObj != null)
|
||||
{
|
||||
if (cardObj.image_uris.png == null)
|
||||
{
|
||||
await mtgChannel.SendMessageAsync("I know that card, but no image.");
|
||||
}
|
||||
else{
|
||||
using(var cardImgDataStream = WebRequest.Create(cardObj.image_uris.png).GetResponse().GetResponseStream())
|
||||
else
|
||||
{
|
||||
using (var cardImgDataStream = WebRequest.Create(cardObj.image_uris.png).GetResponse().GetResponseStream())
|
||||
{
|
||||
await mtgChannel.SendFileAsync(cardImgDataStream, $"{cardName}.png");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"weird 404 searching for card {cardName}");
|
||||
await mtgChannel.SendMessageAsync("¯\\_(ツ)_/¯");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(response.StatusCode == HttpStatusCode.NotFound)
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"regular 404 searching for card {cardName}");
|
||||
await mtgChannel.SendMessageAsync("¯\\_(ツ)_/¯");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine("idgi but something happened.");
|
||||
await message.AddReactionAsync(Emote.Parse("<:problemon:859453047141957643>"));
|
||||
Console.Error.WriteLine("who's fucking idea was it that on 404 you THROW AN EXCEPTION, even though there's a way to read the status code?");
|
||||
Console.Error.Write(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +172,7 @@ namespace silverworker_discord
|
||||
ytdl.OutputFolder = "";
|
||||
ytdl.OutputFileTemplate = "tiktokbad.%(ext)s";
|
||||
var res = await ytdl.RunVideoDownload(link.ToString());
|
||||
if(!res.Success)
|
||||
if (!res.Success)
|
||||
{
|
||||
Console.Error.WriteLine("tried to dl, failed. \n" + string.Join('\n', res.ErrorOutput));
|
||||
await message.AddReactionAsync(Emote.Parse("<:problemon:859453047141957643>"));
|
||||
@ -178,13 +180,13 @@ namespace silverworker_discord
|
||||
else
|
||||
{
|
||||
string path = res.Data;
|
||||
if(File.Exists(path))
|
||||
if (File.Exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
await message.Channel.SendFileAsync(path);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
await message.Channel.SendMessageAsync($"aaaadam!\n{JsonConvert.SerializeObject(e)}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user