well it has been 4 years since i did it, and i did quit using irc, i didnt know what went wrong with it and it confused me, I had a look since i got an email sayin this has been commented on and worked on it to bring definitions.
The code is below but has some issues but works.
(i cant log into my main account btw)
Updates:
17/9/11-fixed it to show if no definitions were found.
Known issues.
No spacing between examples from the same author
Sometimes sends commands to irc server (seems to be the first world from paragraphs from defining, unsure how to fix)
alias dictionarysearch {
var %x = 1
while ($sock($+(dictionary,%x))) inc %x
sockopen $+(dictionary,%x) www.urbandictionary.com 80
sockmark $+(dictionary,%x) $1-
}
ON *:SOCKOPEN:dictionary*: {
if ($sockerr) {
var %cmd = $gettok($sock($sockname).mark,1,32)
%cmd Socket error $sockerr
return
}
sockwrite -n $sockname GET $+(/define.php?term=,$replace(%definition,$chr(32),+) HTTP/1.0)
sockwrite -n $sockname Host: www.urbandictionary.com
sockwrite $sockname $crlf
}
on *:SOCKREAD:dictionary*: {
var %g, %cmd
%cmd = $gettok($sock($sockname).mark,1,32)
if ($sockerr) {
%cmd Socket error $sockerr
return
}
while (1) {
sockread %g
if (!$sockbr) break
if (<div class="definition"> isin %g) {
inc %defnum
set %defresult [ $+ [ %defnum ] ] %defresult [ $+ [ %defnum ] ] %defnum $+ $chr(41) $htmlfree($replace(%g,<div class="example">,- $chr(32)))
}
if (%defresult3) {
sockclose $sockname
%cmd %defresult1
break
}
if (</body> == %g) {
if (!%defresult1) { set %defresult1 No definition found! }
sockclose $sockname
%cmd %defresult1
break
}
}
}
alias dictionary3 {
if (%dictionary3) {
msg %dictionary3 $+(4Definition of %definition,:)
var %defnum2 1
while (%defresult [ $+ [ %defnum2 ] ]) {
msg %dictionary3 7 %defresult [ $+ [ %defnum2 ] ]
inc %defnum2
}
}
unset %dictionary3 | unset %defresult* | unset %definition | unset %defnum
}
on *:TEXT:!define*:#: {
if (%definition) { .notice $nick sorry please wait a sec, defining in progress }
elseif (!%defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]) {
inc -u20 %defspam [ $+ [ $chan $+ [ $nick $+ [ $hash($1-,32) ] ] ] ]
set %dictionary3 $chan
set %definition $2-
dictionarysearch dictionary3 $2-
}
else { .notice $nick sorry but you cant define that word again so quick! }
}
alias -l htmlfree {
var %x, %i = $regsub($replace($1-,&,&,<,<,>,>,",",<td>,$chr(32),<tr>,$chr(20)),/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
good work :)
but here's a couple of tips:
You don't need all of the /'s
Using local variables wud be better as they are auto unset when not needed (/var rather than /set)
Also if you want you can replace:
%num1 = $rand(1,49)
:tryagainA
%num2 = $rand(1,49)
if %num2 = %num1 { /goto tryagainA }
:tryagainB
%num3 = $rand(1,49)
if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
:tryagainC
%num4 = $rand(1,49)
if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
:tryagainD
%num5 = $rand(1,49)
if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
:tryagainE
%num6 = $rand(1,49)
if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
:tryagainF
%num7 = $rand(1,49)
if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
%chan = $readini($mircdir\lotto.ini, lotto, chan)
msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )
with
var %i = 2, %num1 = $r(1,49), %lnumbers = %num1
while (%i <= 7) {
var %num [ $+ [ %i ] ] $r(1,49)
while ($istok(%lnumbers,%num [ $+ [ %i ] ],44)) {
%num [ $+ [ %i ] ] = $r(1,49)
}
%lnumbers = $addtok(%lnumbers,%num [ $+ [ %i ] ],32)
inc %i
}
%chan = $readini($mircdir\lotto.ini, lotto, chan)
msg $chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 $+($chr(40),%num7,$chr(41))
msg $chan $sorttok($deltok(%lnumbers,7,32),32,n) $+($chr(40),%num7,$chr(41))
^ this says the first 6 numbers in order of my code and then the 7th number
and you can replace
%num1 = $readini($mircdir\lotto.ini, lotto, lucky)
:tryagainA
%num2 = $rand(1,49)
if %num2 = %num1 { /goto tryagainA }
:tryagainB
%num3 = $rand(1,49)
if %num3 = %num2 || %num3 = %num1 { /goto tryagainB }
:tryagainC
%num4 = $rand(1,49)
if %num4 = %num3 || %num4 = %num2 || %num4 = %num1 { /goto tryagainC }
:tryagainD
%num5 = $rand(1,49)
if %num5 = %num4 || %num5 = %num3 || %num5 = %num2 || %num5 = %num1 { /goto tryagainD }
:tryagainE
%num6 = $rand(1,49)
if %num6 = %num5 || %num6 = %num4 || %num6 = %num3 || %num6 = %num2 || %num6 = %num1 { /goto tryagainE }
:tryagainF
%num7 = $rand(1,49)
if %num7 = %num6 || %num7 = %num5 || %num7 = %num4 || %num7 = %num3 || %num7 = %num2 || %num7 = %num1 { /goto tryagainF }
%chan = $readini($mircdir\lotto.ini, lotto, chan)
msg %chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 ( $+ %num7 $+ )
with
var %i = 2, %num1 = $readini($mircdir\lotto.ini, lotto, lucky), %lnumbers = %num1
while (%i <= 7) {
var %num [ $+ [ %i ] ] $r(1,49)
while ($istok(%lnumbers,%num [ $+ [ %i ] ],44)) {
%num [ $+ [ %i ] ] = $r(1,49)
}
%lnumbers = $addtok(%lnumbers,%num [ $+ [ %i ] ],32)
inc %i
}
msg $chan Your lucky numbers are:4 %num1 %num2 %num3 %num4 %num5 %num6 $+($chr(40),%num7,$chr(41))
$sorttok($deltok(%lnumbers,7,32),32,n) $+($chr(40),%num7,$chr(41))
They are shorter, it also uses local variables instead of global, although i think its about the same efficiency.
anyway another note is u dont need to write %chan to an ini file you can just set it
writeini $mircdir\lotto.ini lotto chan $chan
can be:
set %chan $chan
and hen you can remove any of these since its already set:
%chan = $readini($mircdir\lotto.ini, lotto, chan)
just a few tips :) :
using namespace means you're including std (since u stated std) to be used.
you can also do:
using std::cout;
if you're just using cout, which wud be more efficient if you're not using alot of std comands.
Also adding \n (when its in quotes will mean if you cout another message it well be on a new line). There is a different way but i prefer this so it would look like this:
cout << "Hello world! \n";
Keep up the good work :)
rofl. im gonna presume ur joking.
i only came back today just to look how thing changed, im not gonna reinstall mirc and spend my time on finding out why ur script doesnt work.
if you have other scripts in your remotes that possibly could affect it, but seriously i cannot help any further, my mirc scripting days are well over.
you have 3 options
Another possibility is that they updated mirc in which my script no longer works. IDK why that would happen if it did (probably not, who knows) but this is the only help i can give ;p, i mean the code is too complex for me to be revising over (and im lazy ;p)
on :text::#:{
if ($1 == !poll) {
...
set -e %pollchannel #
...
}
alias resultpollcode {
...
msg %pollchannel 12{{<<< Results: %pollresults 12>>>}}
...
so by seeing this it msgs the channel the result. since its not working for you i would probably say you are talking to a bot using this script not in a channel. if you did this in a channel and not chat then im sorry but i cant help since its been like a year since i quit.
my old email doesnt work so made a new account since forgot password lol and i dont go on mirc anymore.
$addtok has a format of:
$addtok(TextToAddTo,TextBeingAdded,Position,AsciiChar)
In the script above, it looks like there is only:
$addtok(TextToAddTo,TextBeingAdded,Position)
try:
Quote:
$addtok(%pollresults,[ $+ $gettok(%voteoptions,%toknum,9) $+ $gettok(%nforoptions,%toknum,44) ],0,32)
from what i remember (may be wrong) the last parameter is optional so if you leave the last one out then there is a null being added between each token so combines the strings.
Anyway the script was fine when i used to use it and im sure it didnt have any errors.
eugenio did u type !poll when u had the script yourself, if so then thats ur problem this script is used for a bot but can easily be changed to on input.
RESULTPOLLCODE Unknown command
erm and what is the point in /pollcode or w/e it is ?!?
/resultpollcode is a subroutine because im lazy and no point since i quit mirc ;p i can only assube that its an alias to neaten the coding, to save code repetition (possibly coz mine used to have an on input too)