commit 3e6e701b16a5cd1114b4a3bf3f3a8b4c7ca38718
parent 217a0a21e7394229aa879a35c8dd794ef6309541
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Mon, 25 Sep 2017 22:39:12 +0200
Fix issues with double-typing of indices in json responses
before, I tried to access Reply_to_message and checked for reply_to_message
Diffstat:
src/bot.d | | | 34 | +++++++++++++++++----------------- |
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/bot.d b/src/bot.d
@@ -137,25 +137,25 @@ struct Bot{
void TelegramToIRC(JSONValue Message, ref Appender!string app){
string username="< "~unknown_username~">";
- if("from" in Message){
- app~=TelegramUserToIRC(Message["from"]);
+ if(auto from="from" in Message){
+ app~=TelegramUserToIRC(*from);
app~=" ";
}
- if("forward_from" in Message){
- app~=TelegramUserToIRC(Message["forward_from"]);
+ if(auto fwd="forward_from" in Message){
+ app~=TelegramUserToIRC(*fwd);
app~=" ";
}
foreach(t; ["text", "caption"]){
- if(t in Message){
- app~=Message[t].str;
+ if(auto tv=t in Message){
+ app~=(*tv).str;
app~=" ";
}
}
- if("photo" in Message){
+ if(auto photo="photo" in Message){
string fid;
long size=long.min;
- foreach(p; Message["photo"].array){
+ foreach(p; (*photo).array){
if(p["file_size"].integer>size){
size=p["file_size"].integer;
fid=p["file_id"].str;
@@ -166,13 +166,13 @@ struct Bot{
}
foreach(t; ["audio", "document", "sticker", "video", "voice"]){
- if(t in Message){
- app~=formatProxyURL(Message[t]["file_id"].str);
+ if(auto tv=t in Message){
+ app~=formatProxyURL((*tv)["file_id"].str);
app~=" ";
}
}
- if("location" in Message){
- app~=locationToOSMUrl(Message["location"]);
+ if(auto location="location" in Message){
+ app~=locationToOSMUrl(*location);
app~=" ";
}
if("contact" in Message){
@@ -187,13 +187,13 @@ struct Bot{
app~=c["phone_number"].str;
app~=") ";
}
- if("venue" in Message){
- app~=Message["venue"]["title"].str;
- app~=locationToOSMUrl(Message["venue"]["location"]);
+ if(auto venue="venue" in Message){
+ app~=(*venue).str;
+ app~=locationToOSMUrl((*venue)["location"]);
app~=" ";
}
- if("reply_to_message" in Message){
- TelegramToIRC(Message["Reply_to_message"], app);
+ if(auto jv="reply_to_message" in Message){
+ TelegramToIRC(*jv, app);
}
}