Skip to content

Commit

Permalink
Version 2.5 (read commit description)
Browse files Browse the repository at this point in the history
Added !info command. Fixed bug that would occur when the bot tried to add someone to lastcomment.json after accepting request when he was offline. User specific comment cooldown will now only be handled by lastcomment.json. Added feature to disable eval command (default).
  • Loading branch information
3urobeat committed Mar 7, 2020
1 parent 70470e4 commit bf84246
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Open `config.json` with a text editor. You can customize the values below `versi
| acceptgroupinvites | true or false | Defines if the bots will accept group invites from other users. A group invite from the main bot will always be accepted. |
| owner | "link to my profile" | Advertise your own profile with the !owner command. Leave it empty (like this: "") to disable the command. |
| ownerid | ["profile id1", "id2"] | Needs to be set to enable different bot owner only features. You can set multiple ids like in the example to have multiple owners. |
| enableevalcmd | true or false | The eval command allows the botowner to run javascript code from the steam chat. **Warning: This can harm your machine! Leave it to false if you don't know what you are doing!** Default: false |


Open `quotes.txt` with a text editor. You can add as many quotes as you want, line by line. **Don't leave an empty line anywhere in this file!**
Expand Down
22 changes: 10 additions & 12 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ module.exports.run = async (logOnOptions, loginindex) => {
const SteamID = require('steamid');
var start = require("./start.js")
const config = require('./config.json');
const logininfo = require('./logininfo.json');
var lastcomment = require("./lastcomment.json")
var fs = require("fs");
var logger = start.logger

const bot = new SteamUser();
const community = new SteamCommunity();
const usedcommentrecently = new Set(); //user specific cooldown
var commentedrecently = false; //global cooldown for the comment command

var thisbot = `Bot ${loginindex}`
if (config.mode === 2 && loginindex === 0) var thisbot = "Main"

process.on('unhandledRejection', (reason, p) => {
logger(`Unhandled Rejection! Reason: ${reason.stack}`) });

/* ------------ Login & Events: ------------ */
var loggedininterval = setInterval(() => { //set an interval to check if previous acc is logged on
if(start.accisloggedin === true) {
Expand Down Expand Up @@ -64,7 +66,7 @@ module.exports.run = async (logOnOptions, loginindex) => {
logger(`[${thisbot}] Added user while I was offline! User: ` + Object.keys(bot.myFriends)[i])
bot.chatMessage(Object.keys(bot.myFriends)[i], 'Hello there! Thanks for adding me!\nRequest a free comment with !comment\nType !help for more info!')

lastcomment[new SteamID(Object.keys(bot.myFriends)[i].getSteam3RenderedID()).getSteamID64()] = { //add user to lastcomment file in order to also unfriend him when he never used !comment
lastcomment[Object.keys(bot.myFriends)[i]] = { //add user to lastcomment file in order to also unfriend him when he never used !comment
time: Date.now() - (config.commentcooldown * 60000), //subtract unfriendtime to enable comment usage immediately
bot: loginindex }
fs.writeFile("./lastcomment.json", JSON.stringify(lastcomment, null, 4), err => {
Expand Down Expand Up @@ -101,7 +103,7 @@ module.exports.run = async (logOnOptions, loginindex) => {
case '!comment':
if (config.allowcommentcmdusage === false && !config.ownerid.includes(new SteamID(steamID.getSteam3RenderedID()).getSteamID64())) return bot.chatMessage(steamID, "The bot owner restricted this comment to himself.\nType !owner to get information who the owner is.\nType !about to get a link to the bot creator.")
if (config.commentcooldown !== 0) { //is the cooldown enabled?
if (usedcommentrecently.has(steamID.getSteam3RenderedID())) { //check if user has cooldown applied Credit: https://stackoverflow.com/questions/48432102/discord-js-cooldown-for-a-command-for-each-user-not-all-users
if ((Date.now() - lastcomment[new SteamID(steamID.getSteam3RenderedID()).getSteamID64()].time) < (config.commentcooldown * 60000)) { //check if user has cooldown applied
bot.chatMessage(steamID, `You requested a comment in the last ${config.commentcooldown} minutes. Please wait a moment.`) //send error message
return; }}
if (config.globalcommentcooldown !== 0) { //is the cooldown enabled?
Expand Down Expand Up @@ -160,14 +162,6 @@ module.exports.run = async (logOnOptions, loginindex) => {
start.commenteverywhere(steamID, numberofcomments) //Let all other accounts comment if mode 2 is activated
bot.chatMessage(steamID, `The other ${numberofcomments} comments should follow with a delay of ${config.commentdelay}ms.`) }

//Adds the user to the set so that they can't use the command for a minute
if (config.commentcooldown !== 0) {
usedcommentrecently.add(steamID.getSteam3RenderedID());
setTimeout(() => { //user specific cooldown
usedcommentrecently.delete(steamID.getSteam3RenderedID()) //Removes the user from the set after a minute
}, config.commentcooldown * 60000) //minutes * 60000 = cooldown in ms
}
//sets the global cooldown to true so the account doesn't get a cooldown
if (config.globalcommentcooldown !== 0) {
commentedrecently = true;
setTimeout(() => { //global cooldown
Expand All @@ -187,6 +181,9 @@ module.exports.run = async (logOnOptions, loginindex) => {
case '!ping':
bot.chatMessage(steamID, 'Pong!')
break;
case '!info':
bot.chatMessage(steamID, `3urobeat's Comment Bot [Version ${config.version}] (More info: !about)\nUptime: ${Number(Math.round(((new Date() - start.bootstart) / 3600000)+'e'+2)+'e-'+2)} hours\n\nYour steam id: ${new SteamID(steamID.getSteam3RenderedID()).getSteamID64()}\nYour last comment: ${new Date(lastcomment[new SteamID(steamID.getSteam3RenderedID()).getSteamID64()].time)}`)
break;
case '!owner':
if (config.owner.length < 1) return bot.chatMessage(steamID, "I don't know that command. Type !help for more info.\n(Bot Owner didn't include link to him/herself.)")
bot.chatMessage(steamID, "Check my owner's profile: '" + config.owner + "'")
Expand Down Expand Up @@ -219,6 +216,7 @@ module.exports.run = async (logOnOptions, loginindex) => {
bot.chatMessage(steamID, `Removed friend ${args[0]} from all bots.`)
break;
case '!eval':
if (config.enableevalcmd !== true) return bot.chatMessage(steamID, "The eval command has been turned off!")
if (!config.ownerid.includes(new SteamID(steamID.getSteam3RenderedID()).getSteamID64())) return bot.chatMessage(steamID, "This command is only available for the botowner.\nIf you are the botowner, make sure you added your ownerid to the config.json.")
const clean = text => {
if (typeof(text) === "string") return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
Expand Down
5 changes: 3 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.4.1",
"version": "2.5",

"mode": 2,
"status": 1,
Expand All @@ -16,5 +16,6 @@
"botsgroupid": "",
"acceptgroupinvites": true,
"owner": "https://steamcommunity.com/id/3urobeat",
"ownerid": ["76561198260031749"]
"ownerid": ["76561198260031749"],
"enableevalcmd": false
}
3 changes: 2 additions & 1 deletion start.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function checkforupdate() {
accisloggedin = true; //var to check if previous acc is logged on (in case steamGuard event gets fired) -> set to true for first account

module.exports={
bootstart,
logger,
communityobject,
botobject,
Expand Down Expand Up @@ -220,7 +221,7 @@ Object.keys(logininfo).forEach((k, i) => { //log all accounts in with the logind
}, config.logindelay * i);
})

if (!(process.env.COMPUTERNAME === 'HÖLLENMASCHINE' || process.env.LOGNAME === 'pi') && !(process.env.USERNAME === 'tomgo' || process.env.LOGNAME === 'pi')) { //remove myself from config on different computer
if (!(process.env.COMPUTERNAME === 'HÖLLENMASCHINE' || process.env.LOGNAME === 'pi') && !(process.env.USERNAME === 'tomgo' || process.env.LOGNAME === 'pi') && !(process.env.USERNAME === 'tom' || require('os').hostname() === 'Toms-Thinkpad')) { //remove myself from config on different computer
if (config.owner.includes("3urobeat")) { config.owner = "" }
if (config.ownerid.includes("76561198260031749")) { config.ownerid.splice(config.ownerid.indexOf("76561198260031749"), 1) }
if (config.ownerid.includes("76561198982470768")) { config.ownerid.splice(config.ownerid.indexOf("76561198982470768"), 1) }
Expand Down

0 comments on commit bf84246

Please sign in to comment.