Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

How can i connect a bot to a Chat Guild #3

Closed
CoericK opened this issue Sep 26, 2013 · 5 comments
Closed

How can i connect a bot to a Chat Guild #3

CoericK opened this issue Sep 26, 2013 · 5 comments

Comments

@CoericK
Copy link

CoericK commented Sep 26, 2013

Like the title says, it is possible to make to the bot connects to a Guild's Chat? I mean no just a simple chat room, if is possible how could i do that?
Thanks for Advance, awesome job!!

@rjackson
Copy link
Member

I think you will have to extend my chat.js (https://github.com/RJacksonm1/node-dota2/blob/master/handlers/chat.js) code so that you can pass the guild channel type ( DOTAChannelType_Guild ) to the joinChat method to grab the guild channel ID (I.e. pass guild name and chat channel type = guild), and then the rest of the code should work fine with a guild channel. There is the possibility of a channel name conflict if you join a regular chat channel that shares the name as a guild, so that's something to look out for.

When I get some time I might revisit the chat code; I originally wrote it to be compatible with only regular chat channels, however there are certainly some valid use-cases for the other chat types that I should work to enable. I'm currently very busy with another project though, so I may not get around to that any time soon.

RJ

@CoericK
Copy link
Author

CoericK commented Sep 26, 2013

Thanks for ur fast answer, before u tell me this i tried to join to a regular chat and tried to send a message, it joins, but doesnt send the message.
Dota2.joinChat("MYNAMECHAT");
setTimeout(function(){ Dota2.sendMessage("MYNAMECHAT", "my msg"); }, 10000);

I mean it says "Sending message to MYNAMECHAT" but it doesnt shows in to the chat room in the game.

Also what do u mean with updating this part?
so that you can pass the guild channel type ( DOTAChannelType_Guild ) to the joinChat method to grab the guild channel ID (I.e. pass guild name and chat channel type = guild),

I replaced:
"channelType": Dota2.DOTAChatChannelType_t.DOTAChannelType_Custom
by :
"channelType": Dota2.DOTAChatChannelType_t.DOTAChannelType_Guild and it doesnt join to the channel.

PD: i know this is maybe wrong >.<!.
Again Thank you for advance!

@rjackson
Copy link
Member

Ah, my apologies. It turns out a change I made before (replacing array maps with filters) caused the problems sending chat messages, and I somehow didn't catch that. I have just fixed it - 658ce56.

I've also tried my suggestion about joining and interfacing with guilds, and you are correct - it doesn't join the guild. Looking at the protobufs I'm not sure what else to suggest right now. The best thing to do would be to inspect the messages Steam itself sends (via SteamRE's NetHook), and then we can figure out how to recreate those messages in with this library. I'll throw it on my todo list, but until then I don't think I can be of much help I'm afraid.

@CoericK
Copy link
Author

CoericK commented Sep 26, 2013

Oh thank so much for the fix now it send messages to the regular chats, about inspect Steam via SteamRE's NetHook, i dont know so much about that, maybe there is some guide than i can follow up? or maybe can i contact u in private so i can expend some time trying to figure out about how to join and send messages to guild's chat.

I have another question and i dont know if i should open another post, its about how can i get the ID's Guild? and if i have the steamid how can i get the account id?
I mean to use on this:

guildInvite (guildId, guildName, inviter, guildInviteDataObject)
guildId - ID of the guild.
guildName - Name of the guild.
inviter - Account ID of user whom invited you.
guildInviteDataObject - The raw guildInviteData object to do with as you wish.

I will appreciate if u can give me a hand with this.

Thanks for ur time i know u are bussy, Grettings.

@rjackson
Copy link
Member

The comment about Nethook was just to remind me to look into it, and I have done just that.

It seems when the client launches Dota 2 it sends the message k_EMsgGCRequestGuildData with an (empty) serialized payload of CMsgDOTARequestGuildData. The server responds to this with a number of things but most notably for each guild you are in the GC sends a k_EMsgGCGuildOpenPartyRefresh with a CMsgDOTAGuildOpenPartyRefresh payload - which contains guild_id and open_parties properties. There doesn't seem to be anything to suggest which guild name is associated to which guild_id, however.

The Dota 2 Client then sends some k_EMsgGCJoinChatChannel messages, like our existing joinChat method, however it for channel_name it passes Guild_[guild_id], e.g. Guild_2755, and it also passes channel_type = DOTAChannelType_Guild. The GC later responds with channel_ids, as our existing code handles.

So, what we'll need to do is add k_EMsgGCGuildOpenPartyRefresh: 7268, to the Dota2.EDOTAGCMsg object in generated/messages.js, add a method to send k_EMsgGCRequestGuildData and a handler to receive k_EMsgGCGuildOpenPartyRefresh in handlers/guild.js, and then adjust the joinChat function to take DOTAChannelType_Guild as you have already done.

So, the final program flow to do this would be something like:

  • Wait for ready event.
  • Send requestGuildData
  • For each GuildOpenPartyRefresh event send joinChat("Guild_[guild_id]")
  • Use our chat functions as they are written now, but pass the channel name as Guild_[guild_id].

Once you figure out the guild_id, via the above, you probably wouldn't need to requestGuildData anymore, just send the joinChat call straight away.


An account id is the lower 32 bits of a Steam ID, however Javascript is a bit iffy with long numbers, so we have to use a buffer to process this. Here's a snippet of code that should do the job:

require('ref');  // Adds 64 bit method stuffs, as stock buffers only go up to 32 bits.

function getAccountId(steamId64) {
    // Takes a 64-bit Steam ID and returns the account ID.
    var tmpBuffer = new Buffer(8);
    tmpBuffer.writeUInt64LE(steamId64, 0);
    return tmpBuffer.readUInt32LE(0);
}
// > getAccountId("76561197989222171");
// 28956443

Feel free to have a go at implementing the guild related code yourself, if you want. Otherwise I'll have a go at it over the weekend.

rjackson added a commit that referenced this issue Sep 27, 2013
rjackson pushed a commit that referenced this issue May 3, 2014
jimmydorry pushed a commit that referenced this issue Oct 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants