mIRC Homepage

[Twitch] I need help with song request system

Posted By: Khonor

[Twitch] I need help with song request system - 26/01/16 03:09 PM

Hi there,

I need some help, I want to add in a way for the bot to recognize links so that for the !songrequest command, if one does not give a link, their input will not be accepted. I am fairly new to IRC, so I apologize if the script has errors!

For example:

This: !songrequest Maroon 5 - Sugar youtu.be/09R8_2nJtjg?list=RDRgKAFK5djSk

Should give an output of "added song name Maroon 5 - Sugar to the song queue. youtu.be/09R8_2nJtjg?list=RDRgKAFK5djSk"

Any help is appreciated. Thanks in advance!




on $*:TEXT:!songrequest &:#: {
if ((%floodsongrequest) || ($($+(%,floodsongrequest.,$nick),2))) { return }
write songlist.txt $2
write songlinks.txt $3
write songusers.txt $nick
msg $chan Added song name $2 to the song queue. %slink
}

on *:text:!currentsong:#: {
if ((%floodcurrentsong) || ($($+(%,floodcurrentsong.,$nick),2))) { return }
set -u30 %floodcurrentsong On
set -u60 %floodcurrentsong. $+ $nick On {
if ($read(songlist.txt,2)) {

var %slist2 $read(songlist.txt,1)
var %slink2 $read(songlinks.txt,1)
var %suser2 $read(songusers.txt,1)
msg $chan Current Song: %slist $chr(124) Requested by %suser $chr(124) %slink
write -dl1 songlist.txt
write -dl1 songlinks.txt
write -dl1 songusers.txt
}
else {
msg $chan There are no more songs in the queue.
write -dl1 songlist.txt
write -dl1 songlinks.txt
write -dl1 songusers.txt
}
}
}

on *:text:!nextsong:#: {
if ($nick isop #) {
if ((%floodnextsong) || ($($+(%,floodnextsong.,$nick),2))) { return }
set -u5 %floodnextsong On
set -u10 %floodnextsong. $+ $nick On {
if ($read(songlist.txt,2)) {
var %slist2 $read(songlist.txt,2)
var %slink2 $read(songlinks.txt,2)
var %suser2 $read(songusers.txt,2)

msg $chan Next Song: %slist $chr(124) Requested by %suser $chr(124) %slink
write -dl1 songlist.txt
write -dl1 songlinks.txt
write -dl1 songusers.txt
}
else {
msg $chan There are no more songs in the queue.
write -dl1 songlist.txt
write -dl1 songlinks.txt
write -dl1 songusers.txt
}
}
}
else msg # This command is only available to moderators.
}
Posted By: westor

Re: [Twitch] I need help with song request system - 26/01/16 04:02 PM

Try use this code:

($isurl from Wims)

Also i fixed some code errors, and added !clearsongs to clear the song list.

Php Code:

alias isurl { ; by Wims
  noop $regex(isurl,$1-,m@((?:(?:https?|ircs?)://(?:www\.)?|www\.)((?:(?:[-\w]+\.)+)[-\w]+)(?::\d+)?(?:/(?:[-a-zA-Z;/\d#:_?=&,().]*))?)@ig)
  if ($prop == all) {
	var %a 1
	while ($regml(isurl,%a)) { var %url = %url $v1 | inc %a 2 }
	return $iif(%url,%url,0)
  }
  return $iif($prop isnum 0-,$regml(isurl,$prop),$iif($regml(isurl,0),$true,$false))
}

on $*:TEXT:!songrequest &:#: {
  if ((%floodreqsong) || ($($+(%,floodreqsong.,$nick),2))) { return }
  if (!$2) { msg $chan Error, Please specify a song name! | return }
  if (!$3) { msg $chan Error, Please specify a song link! | return }
  if (!$isurl($3)) { msg $chan Error, Please specify a valid link url! | return }
  set -eu30 %floodreqsong On
  set -eu60 %floodreqsong. $+ $nick On
  write songlist.txt $2
  write songlinks.txt $3
  write songusers.txt $nick
  msg $chan $nick -> Added $qt($2) song name with $qt($3) link to the song queue list.
}

on *:text:!currentsong:#: {
  if ((%floodcurrentsong) || ($($+(%,floodcurrentsong.,$nick),2))) { return }
  set -eu30 %floodcurrentsong On
  set -eu60 %floodcurrentsong. $+ $nick On
  if ($read(songlist.txt,n,1)) {
	var %slist = $read(songlist.txt,n,1)
	var %slink = $read(songlinks.txt,n,1)
	var %suser = $read(songusers.txt,n,1)
	msg $chan Current Song: %slist $chr(124) Requested by %suser $chr(124) %slink
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!nextsong:#: {
  if ((%floodnextsong) || ($($+(%,floodnextsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodnextsong On
  set -eu60 %floodnextsong. $+ $nick On
  if ($read(songlist.txt,n,2)) {
	var %slist2 = $read(songlist.txt,n,2)
	var %slink2 = $read(songlinks.txt,n,2)
	var %suser2 = $read(songusers.txt,n,2)
	msg $chan Next Song: %slist2 $chr(124) Requested by %suser2 $chr(124) %slink2
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!clearsongs:#: {
  if ((%floodclearsong) || ($($+(%,floodclearsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodclearsong On
  set -eu60 %floodclearsong. $+ $nick On
  var %t = $lines(songlist.txt)
  if (%t) {
	write -c $qt(songlist.txt)
	write -c $qt(songlinks.txt)
	write -c $qt(songusers.txt)
	msg $chan $nick -> The song list has been cleared.
  }
  else { msg $chan There are no more songs in the queue list. }
}
 
Posted By: Khonor

Re: [Twitch] I need help with song request system - 26/01/16 09:21 PM

Hi @westor,

Thanks for your reply and help really appreciate it, but there is a problem, whenever I want to load a song I did not take the bot.


Example 1:

Me: !songrequest Maroon 5 - Animals https://www.youtube.com/watch?v=qpgTC9MDx1o


Bot: Not responds...





Example 2:

Me: !songrequest https://www.youtube.com/watch?v=qpgTC9MDx1o


Bot: Please specify a song link!
Posted By: Wims

Re: [Twitch] I need help with song request system - 26/01/16 10:08 PM

I didn't look at the script itself but westor edited the $isurl alias I gave him, he actually broke it, the pattern for the regex call should be in a variable or similar form of escaping, otherwise, the comma in the pattern is taken as an argument seperator, try with this alias instead:

Code:
alias isurl {
var %p m@((?:(?:https?|ircs?)://(?:www\.)?|www\.)((?:(?:[-\w]+\.)+)[-\w]+)(?::\d+)?(?:/(?:[-a-zA-Z;/\d#:_?=&,().]*))?)@ig
  noop $regex(isurl,$1-,%p)
  if ($prop == all) {
	var %a 1
	while ($regml(isurl,%a)) { var %url = %url $v1 | inc %a 2 }
	return $iif(%url,%url,0)
  }
  return $iif($prop isnum 0-,$regml(isurl,$prop),$iif($regml(isurl,0),$true,$false))
}


Worth nothing the pattern originally was an identifier, called with $regex(isurl,$1-,$url_pattern), and this method is somewhat better because it avoids any complication from the mirc parser, indeed if the pattern had a '%' after the comma and a space after some more character, /var would interpret it as a new variable declaration.

@westor if you edit, break a code and then state I made it, I'm not going to be happy cry
Posted By: Khonor

Re: [Twitch] I need help with song request system - 26/01/16 11:44 PM

Hi @Wims,

Thank you for your answer, but remains same as the examples I gave above. frown
Posted By: westor

Re: [Twitch] I need help with song request system - 29/01/16 09:10 PM

Try use this code:

Syntax: !songrequest <LINK> <NAME>

Example: !songrequest https://www.youtube.com/watch?v=qpgTC9MDx1o Maroon 5 - Animals

Php Code:

alias isurl { ; by Wims
  var %p m@((?:(?:https?|ircs?)://(?:www\.)?|www\.)((?:(?:[-\w]+\.)+)[-\w]+)(?::\d+)?(?:/(?:[-a-zA-Z;/\d#:_?=&,().]*))?)@ig
  noop $regex(isurl,$1-,%p)
  if ($prop == all) {
		var %a 1
		while ($regml(isurl,%a)) { var %url = %url $v1 | inc %a 2 }
		return $iif(%url,%url,0)
  }
  return $iif($prop isnum 0-,$regml(isurl,$prop),$iif($regml(isurl,0),$true,$false))
}
on $*:TEXT:!songrequest &:#: {
  if ((%floodreqsong) || ($($+(%,floodreqsong.,$nick),2))) { return }
  if (!$2) { msg $chan Error, Please specify a song link! | return }
  if (!$isurl($2)) { msg $chan Error, Please specify a valid link url! | return }
  if (!$3) { msg $chan Error, Please specify a song name! | return }
  set -eu30 %floodreqsong On
  set -eu60 %floodreqsong. $+ $nick On
  write songlist.txt $3-
  write songlinks.txt $2
  write songusers.txt $nick
  msg $chan $nick -> Added $qt($3-) song name with $qt($2) link to the song queue list.
}

on *:text:!currentsong:#: {
  if ((%floodcurrentsong) || ($($+(%,floodcurrentsong.,$nick),2))) { return }
  set -eu30 %floodcurrentsong On
  set -eu60 %floodcurrentsong. $+ $nick On
  if ($read(songlist.txt,n,1)) {
		var %slist = $read(songlist.txt,n,1)
		var %slink = $read(songlinks.txt,n,1)
		var %suser = $read(songusers.txt,n,1)
		msg $chan Current Song: %slist $chr(124) Requested by %suser $chr(124) %slink
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!nextsong:#: {
  if ((%floodnextsong) || ($($+(%,floodnextsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodnextsong On
  set -eu60 %floodnextsong. $+ $nick On
  if ($read(songlist.txt,n,2)) {
		var %slist2 = $read(songlist.txt,n,2)
		var %slink2 = $read(songlinks.txt,n,2)
		var %suser2 = $read(songusers.txt,n,2)
		msg $chan Next Song: %slist2 $chr(124) Requested by %suser2 $chr(124) %slink2
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!clearsongs:#: {
  if ((%floodclearsong) || ($($+(%,floodclearsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodclearsong On
  set -eu60 %floodclearsong. $+ $nick On
  var %t = $lines(songlist.txt)
  if (%t) {
		write -c $qt(songlist.txt)
		write -c $qt(songlinks.txt)
		write -c $qt(songusers.txt)
		msg $chan $nick -> The song list has been cleared.
  }
  else { msg $chan There are no more songs in the queue list. }
}
 


@Wims acutally mine version (from you) $isurl its true that is modified because there was an parsing problem but actually i cant remeber which and u fixed it, anyway.. smile
Posted By: Khonor

Re: [Twitch] I need help with song request system - 25/02/16 12:10 AM

Hi @Westor,

I tried several times with the script you gave me, but still does not work.
Posted By: Loki12583

Re: [Twitch] I need help with song request system - 25/02/16 12:58 AM

Well for a start it's got tabs in it, that's no good.
Posted By: westor

Re: [Twitch] I need help with song request system - 25/02/16 07:00 PM

Try to paste it from here:

Code:
alias isurl { ; by Wims
  var %p = m@((?:(?:https?|ircs?)://(?:www\.)?|www\.)((?:(?:[-\w]+\.)+)[-\w]+)(?::\d+)?(?:/(?:[-a-zA-Z;/\d#:_?=&,().]*))?)@ig
  noop $regex(isurl,$1-,%p)
  if ($prop == all) {
    var %a = 1
    while ($regml(isurl,%a)) { var %url = %url $v1 | inc %a 2 }
    return $iif(%url,%url,0)
  }
  return $iif($prop isnum 0-,$regml(isurl,$prop),$iif($regml(isurl,0),$true,$false))
}
on $*:TEXT:!songrequest &:#: {
  if ((%floodreqsong) || ($($+(%,floodreqsong.,$nick),2))) { return }
  if (!$2) { msg $chan Error, Please specify a song link! | return }
  if (!$isurl($2)) { msg $chan Error, Please specify a valid link url! | return }
  if (!$3) { msg $chan Error, Please specify a song name! | return }
  set -eu30 %floodreqsong On
  set -eu60 %floodreqsong. $+ $nick On
  write songlist.txt $3-
  write songlinks.txt $2
  write songusers.txt $nick
  msg $chan $nick -> Added $qt($3-) song name with $qt($2) link to the song queue list.
}

on *:text:!currentsong:#: {
  if ((%floodcurrentsong) || ($($+(%,floodcurrentsong.,$nick),2))) { return }
  set -eu30 %floodcurrentsong On
  set -eu60 %floodcurrentsong. $+ $nick On
  if ($read(songlist.txt,n,1)) {
    var %slist = $read(songlist.txt,n,1)
    var %slink = $read(songlinks.txt,n,1)
    var %suser = $read(songusers.txt,n,1)
    msg $chan Current Song: %slist $chr(124) Requested by %suser $chr(124) %slink
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!nextsong:#: {
  if ((%floodnextsong) || ($($+(%,floodnextsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodnextsong On
  set -eu60 %floodnextsong. $+ $nick On
  if ($read(songlist.txt,n,2)) {
    var %slist2 = $read(songlist.txt,n,2)
    var %slink2 = $read(songlinks.txt,n,2)
    var %suser2 = $read(songusers.txt,n,2)
    msg $chan Next Song: %slist2 $chr(124) Requested by %suser2 $chr(124) %slink2
  }
  else { msg $chan There are no more songs in the queue list. }
}

on *:text:!clearsongs:#: {
  if ((%floodclearsong) || ($($+(%,floodclearsong.,$nick),2))) { return }
  if ($nick !isop #) { msg # This command is only available to moderators! | return }
  set -eu30 %floodclearsong On
  set -eu60 %floodclearsong. $+ $nick On
  var %t = $lines(songlist.txt)
  if (%t) {
    write -c $qt(songlist.txt)
    write -c $qt(songlinks.txt)
    write -c $qt(songusers.txt)
    msg $chan $nick -> The song list has been cleared.
  }
  else { msg $chan There are no more songs in the queue list. }
}
© 2020 mIRC Discussion Forums