Slap Script


#1

So been battling this for a bit and trying to learn some JS and hit a wall, we’re trying to create a mIRC style !slap command but for some reason the bot quits randomizing. Any help for what I’m doing wrong here?

https://www.hastebin.com/arotoriroj.sm

Looking at the console it’s not throwing any errors, if I run the code in a browser it properly pulls a semi-random (understandable since there is a low amount of items in the array) value.


#2

Since var randomSlap = slapReasons[Math.floor(Math.random()*slapReasons.length)]; is outside the command callback, it will only be loaded once on startup, try placing it right before the line that sends the message to chat.


#3

Makes sense, seems to work - however - to make it do so I had to rename the command as eventually !slap just flat out quit responding.

If i run it as !slaptest it worked, !slap doesn’t answer at all. Removed the module, rebooted the bot and the commands still show in the Permissions list and if I put the module back in (this is physically removing the file, deleting the module from the db with !module delete etc) it still doesn’t work.

Wat do? :frowning:


#4

The command will stay in the permissions table. The only way to remove it from the permissions table would be to edit the database and delete the row. Can you show me your current code so I can do some testing?


#5

Hi! I like the idea but I’d rather it pick a random user in chat. I also made the script load the responses dynamically so you can add more on the fly (reloading them with !loadslaps).

Click Here to Download my copy

All you should need to do is shutdown your bot, and then extract the scripts folder found in the zip file to your bot root (where your existing scripts folder is).

It will ask you to merge the folders, and it will also replace your existing slap command, so if you want to keep that make a backup.

If you have issues running it let me know so I can help.


#6

Code is identical to that in the OP, I just moved the line per your suggestion.

That did fix the issue, however the !slap command became unresponsive (regardless of argument provided). When I renamed the command to !slaptest and rebooted the bot, the command then worked.


#7

A side update to this…so it turns out anybody but myself can use the command. I’ve tried w/ admin and without and no difference (the bot disregards my input).

All other users, subscribers, moderators etc can use the command without issue.


#8

Could you enable the bot’s debug mode by typing debugon in the console, then hit enter, and try running the command again. Please paste what the bot outputs in the console here. Thanks!