Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chapter on chat messages #50

Open
andrewda opened this issue Oct 20, 2017 · 15 comments
Open

Add chapter on chat messages #50

andrewda opened this issue Oct 20, 2017 · 15 comments

Comments

@andrewda
Copy link
Owner

Both handling and sending

@Zendrex
Copy link

Zendrex commented Oct 20, 2017

I was actually curious about this and figured it out myself. If you like I can give the code for it with some examples of commands, etc.

@Zendrex
Copy link

Zendrex commented Oct 20, 2017

Here are some snippets. My chat log formatting is a bit different however you can change it.

Added 2 functions, 1 for giving all your items of a specific game to the bot and the other being to take all the item from the bot in a specific game. The chat listener at least in this code block ignores everything that isnt considered admin of the bot. Still need to do an array for the admin list but for now it works.

// Variables
var admin_steamID = 'your_steam_64_id_here'

// Chat listener
client.on('friendMessage', (steamID, message) => {
    if (steamID == admin_steamID) {
        // Print to console that the chat message was detected for an admin.
        console.log(' Chat From ' + steamID + ': ' + message);

        if (message.match('!help')) {
            client.chatMessage(steamID, `
--------[ Bot Commands ]--------
●  !help - Get a list of help commands.
●  !take-all (option) - Withdraw all items from the bot.
     ↪  steamcard, csgo, tf2
●  !give-all (option) - Deposite all items to the bot.
    ↪  steamcard, csgo, tf2
●  !relog - Relog the bot into steam.
●  !shutdown - Shut down the bot.`);
        } else if (message.includes("!take-all")) {
            if (message.match('!take-all steamcards')) {
                client.chatMessage(steamID, '\nTransfering all STEAMCARDS to you. Please Wait.');
                takeAll(steamID, 753, 6, false);
            } else if (message.match('!take-all csgo')) {
                client.chatMessage(steamID, '\nTransfering all CSGO Items to you. Please Wait.');
                takeAll(steamID, 730, 2, false);
            } else if (message.match('!take-all tf2')) {
                client.chatMessage(steamID, '\nTransfering all TF2 Items to you. Please Wait.');
                takeAll(steamID, 440, 2, false);
            } else {
                client.chatMessage(steamID, '\nInvalid !take-all option. Please try again.');
            }
        } else if (message.includes("!give-all")) {
            if (message.match('!give-all steamcards')) {
                client.chatMessage(steamID, '\nTransfering all STEAMCARDS from you. Please Wait.');
                giveAll(steamID, 753, 6, false);
            } else if (message.match('!give-all csgo')) {
                client.chatMessage(steamID, '\nTransfering all CSGO Items from you. Please Wait.');
                giveAll(steamID, 730, 2, false);
            } else if (message.match('!give-all tf2')) {
                client.chatMessage(steamID, '\nTransfering all TF2 Items from you. Please Wait.');
                giveAll(steamID, 440, 2, false);
            } else {
                client.chatMessage(steamID, '\nInvalid !give-all option. Please try again.');
            }
        }
    } else if (message.match('!relog')) {
        console.log(' Relog command executed.')
        client.chatMessage(steamID, '\nRe-Logging the bot into steam. brb ;)');
        client.relog();
    } else {
        console.log(' Shutdown command executed.')
        client.chatMessage(steamID, '\nShutting down the bot. Goodbye.');

        // This is the most ghetto ass way of doing it. Actually cause an error for the js to break. xD
        client.shutdown();
    }
});


// Functions

// GiveAll items
function giveAll(steamID, appid, contextid, key_only) {
    manager.loadInventory(appid, contextid, true, (err, inventory) => {
        if (err) {
            console.log(err);
            client.chatMessage(steamID, '\nThere was an error, check the console.');
        } else {
            const offer = manager.createOffer(steamID);

            manager.loadUserInventory(steamID, appid, contextid, true, (err, theirInv) => {
                const theirItem = theirInv;

                offer.addTheirItems(theirItem);
                offer.send((err, status) => {
                    if (err) {
                        console.log(err);
                        console.log(' ');
                    } else {
                        console.log(` [SENT TRADE] Offer ID: (` + offer.id + `)` + ` | SteamID: ` + steamID);
                        client.chatMessage(steamID, '\n Trade offer sent. (' + offer.id + ')\n It make take up to 30 seconds for you to recieve it.');
                    }
                });
            });
        }
    });
};

// TakeAll items
function takeAll(steamID, appid, contextid, key_only) {
    manager.loadInventory(appid, contextid, true, (err, inventory) => {
        if (err) {
            console.log(err);
            client.chatMessage(steamID, '\nThere was an error, check the console.');
        } else {
            const offer = manager.createOffer(steamID);
            const items = inventory;
            offer.addMyItems(items);
            offer.send((err, status) => {
                if (err) {
                    console.log(err);
                    console.log(' ');
                } else {
                    console.log(` [SENT TRADE] Offer ID: (` + offer.id + `)` + ` | SteamID: ` + steamID);
                    client.chatMessage(steamID, '\n Trade offer sent. (' + offer.id + ')\n It make take up to 30 seconds for you to recieve it.');
                }
            });
        }
    });
};

@andrewda
Copy link
Owner Author

Thanks @Zendrex! If you feel like it, you can write the chapter around your code. No worries if you don't have time, though, I'll definitely get around to this in the next couple weeks.

@Zendrex
Copy link

Zendrex commented Oct 20, 2017

If I get some extra time on my hands I will go ahead and fork the repo and work on some docs for it.

@xmwx38
Copy link
Contributor

xmwx38 commented Apr 3, 2018

@DentFuse has added a chapter covering chat messages, & his pull request is pending #78.

| David, your friend |

@kebaburmum
Copy link

hello this is not working, i define the manager but it says loadinventory is not a function

@DentFuse
Copy link
Contributor

@kebaburmum Try manager.getInventoryContents, check it out on the wiki

@kebaburmum
Copy link

I solved it already but I have a new problem.
Whenever i type !relog it says this,can you help me pls? I understand this but where should I specify it? Error: To use relog(), you must specify rememberPassword=true when logging on and wait for loginKey to be emitted
at SteamUser.relog (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-user\components\logon.js:255:9)
at SteamUser.client.on (C:\Users\herni\Desktop\sandvich\Nová složka\project2.js:269:16)
at SteamUser.emit (events.js:187:15)
at SteamUser._emitIdEvent (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-user\components\utility.js:29:12)
at SteamUser._handlers.(anonymous function) (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-user\components\chat.js:281:9)
at SteamUser._handleMessage (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-user\components\messages.js:249:30)
at CMClient.emit (events.js:187:15)
at CMClient._netMsgReceived (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-client\lib\cm_client.js:323:8)
at CMClient.handlers.(anonymous function) (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-client\lib\cm_client.js:609:8)
at CMClient._netMsgReceived (C:\Users\herni\Desktop\sandvich\Nová složka\node_modules\steam-client\lib\cm_client.js:305:24)

@kebaburmum
Copy link

@DentFuse

@DentFuse
Copy link
Contributor

@kebaburmum Specify rememberPassword: true in your logOnOptions

const logOnOptions = {
  accountName: config.login.username,
  password : config.login.password,
  twoFactorCode: SteamTotp.generateAuthCode(config.login.shared_secret),
  rememberPassword: true
}

@kebaburmum
Copy link

kebaburmum commented Nov 24, 2018

Alright got it, it! Thank you @DentFuse

@kebaburmum
Copy link

@DentFuse I dont know how good you are, but you seems like a experienced guy with node.js. at the chapter 2.3 - Sending trade offers, is there any way to send a specific item for their keys? And maybe how to create a chat command to process the offer?

@DentFuse
Copy link
Contributor

@kebaburmum Refer to this to understand chat messages and commands. Read the API docs and think of how you can achieve what you want.

@kebaburmum
Copy link

@DentFuse Hello I havent figured it out, but I saw a quite interesting things there. Is it somehow possible at this chapter https://github.com/Steam-Bot-Basics/node-steam-guide/blob/master/Chapter%203%20-%20User%20Interaction/Chapter%203.4%20-%20Commenting%20on%20Profile%20%26%20Removing%20Friends/README.md for example when you write !remove, the bot will remove you, but is it possible somehow that you can tell me how to for example remove other users? like !remove and here ill put steam id. It would be really cool

@kebaburmum
Copy link

As I said im really new so pls take it easy on me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants