Printing a URL with 2 Queries and 2 defaults

Asked Apr 23, 2020·2 replies·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hi all, I am newb at this stuff.

I'm trying to create a lookup command for players to type in twitch chat that will spit out a link to their game/match history on OP.GG.

The command would use 2 arguments/queries (in-game-name and server) and then the link will be the output. These are the same inputs needed for the League of Legends commands.
If no queries are entered, then I'd like the output to use the user's name (twitch user name) and NA (server).

I have found similar topics, but none involving 2 queries which could default to something else.
This is what I have so far:

https://$(eval $(query)na).op.gg/summoner/userName=$(eval $(query)$(user))

WITHOUT query entries, the result is perfect:
MajinSona: !opgg
Nightbot: https://na.op.gg/summoner/userName=majinsona

WITH query entries, the result is scuffed but the link still works LMAO:
MajinSona: !opgg majinsona na

ALSO scuffed with only one query entry and the link does not work:
MajinSona: !opgg majinsona

I've also tried using $(2) for the SERVER and $(1) for the IN-GAME-NAME for arguments which replace $(query). But when no query in entered, "null" is printed on the link. Query entries work fine.
MajinSona: !opgg

Anyways, this is where I'm at and any help is appreciated. Thanks!

image.pngimage.pngimage.png

2 replies

Hey @Sandy Badger!

Here's a solution:

$(eval q=[]; if(`$(query)`){q=decodeURIComponent(`$(querystring)`).toLowerCase().split(` `);} q[0]==`help`?`!opgg <in-game username if different than Twitch username, required if <server> is used> <server if different than NA>`:q.length==0?`https://na.op.gg/summoner/userName=$(user)`:q.length==1?`https://na.op.gg/summoner/userName=${q}`:q.length==2?`https://${q[1]}.op.gg/summoner/userName=${q[0]}`:`Please enter no more than two arguments, for help type: !opgg help`;)

Here are the possible uses:
!opgg → gives a link with the Twitch username on NA server
!opgg USERNAME → gives a link with in-game username on NA server
!opgg USERNAME SERVER → gives a link with in game username on a different server than NA
!opgg help → gives a help guide

OMG @Polar Cat you're amazing! Wow... I definitely couldn't do this myself. Everything works excellently 10/10 👍 Thank you sooo much~! <3

1.png