Package: dgg-chat
DGG ChatA package that lets you do stuff indggchat, like parsing messages in chat,
replying to whispers, accessing the dgg API, and retrieving user logs and CDN assets.InstallingThis package is available via pip!pipinstalldgg-chatA (very) minimal working example (more details below):fromdgg_chatimportDGGChatchat=DGGChat()@chat.on_chat_messagedefon_chat_message(message):print(message)chat.run_forever()How It WorksThe package makes use of messages sent via the dgg websocket interface.
It's based around theDGGChatclass, which runs the main event loop,
invoking the handlers implemented, as well as allowing you to reply to whispers.When a message is received from the websocket, it is redirected to its respective handler
(and any other relevantspecial handler).How To UseA handler is a method that receives one argument (with three exceptions), which will
be of typedgg_chat.messages.Messageor one of its subclasses.The three exceptions are: the handlers for theWHISPER_SENTand theWS_CLOSEevents, which have no arguments;
and theHANDLER_ERRORevent, which receive the exceptions raised on trying to handle the message.Each handler receives a specific type of message, defined in themessagesmodule.
To register an event handler, you must use one of the decorators listed in theEvent Types and Their Respective Handlerssection.All handlers are also synchronous, that is, a handler will only be called after the previous one
finished its work. Asynchronous support might be implemented in the future.A simple example can be found under theDGGChatsection. More details can be found in theexample.pyfile.Event Types and Their Respective HandlersDecoratorEvent Descriptionon_served_connectionsThe chat connection was established. Lists all connected users and the count of served connections.on_user_joinedA user has joined the chat.on_user_quitA user has left the chat.on_broadcastA broadcast message (yellow message) was received, such as when a user subscribes.on_chat_messageA chat message was received.on_whisperA whisper was received.on_whisper_sentThe whisper was successfully sent.on_muteA user was muted.on_unmuteA user was unmuted.on_banA user was banned.on_unbanA user was unbanned.on_sub_onlySubmode was toggled in chat.on_error_messageA chat related error occurred (seecommon errors).Special EventsBesides the already listed events, some others are triggered on special situations.
Those are as follow:DecoratorAssociated Eventbefore_every_messageBefore every event listed in the previous table. The specific handlers for that event type will still be called.after_every_messageAfter every event listed in the previous table. The specific handlers for that event type will still be called.on_mentionReceived aChatMessagethat contains the username for the authenticated user. Requires eitherauth_tokenorsession_id.CHAT_MESSAGEhandler is still called.on_ws_errorSomething wrong happened with the websocket connection.on_ws_closeWebsocket connection got closed, usually by callingDGGChat().disconnect().on_handler_errorAn exception was raised inside at least one of the handlers called.CommonERROR_MESSAGECausesError MessageExplanation"throttled"Messages got sent too fast withDGGChat().send_whisper()."needlogin"Invalidauth_tokenorsession_loginprovided. Seeauthentication."notfound"Usually when target user forDGGChat().send_whisper()was not found.DGGChatThis is the class that runs the show. It takes the handlers you've implemented and calls them when appropriate.
The features listed below are also available (though some are not usable right away):Sending whispers withDGGChat().send_whisper().View info for current user withDGGChat().profileproperty.Get unread whispers withDGGChat().get_unread_whispers().All of these features require the connection to beauthenticated.By default, you won't be able to send whispers. This was done intentionally and a quick look at
the source code should lead you to how to enable sending whispers to people who whispered you first.
Hopefully this discourages some ill-intentioned folks from using this to do dumb shit in the chat.Here's a quick example on how to setup and run the chat instance.
More details can be found in theexample.pyfile.fromdgg_chatimportDGGChatdgg_auth_token="<your dgg auth token>"chat=DGGChat(auth_token=dgg_auth_token)@chat.on_user_joineddefon_user_joined(joined):print(f"{joined.user}just joined!")@chat.on_chat_messagedefon_chat_message(message):print(f"{message.user}just said something:{message.content}")@chat.on_whisperdefon_whisper(whisper):print(f"{whisper.user}just sent you a whisper:{whisper.content}")chat.send_whisper(whisper.user,"Hello!")...# blocking callchat.run_forever()AuthenticationAlthough you can run the chat anonymously and still be able to view all messages in chat,
replying to whispers requires your connection to be authenticated.Auth TokenThe easiest way to do that is to create anauth_tokenassociated with your account.
It will allow you to get your profile info, send chat messages, and whisper other users.
This can be done by going to the dggdeveloper dashboard,
clicking onConnections, andAdd login key. The generated key should be a 64 character alphanumeric string.CAUTION: this key acts as your password, so be careful not to share it with anyone
(also don't put in any of your unignored repo files!). With it, someone else can use it to send
messages as you and read your whispers. If you believe you've leaked your key somewhere, go back to the
dashboard, remove it, and generate another.Auth tokensusually do not expire.Session IDIf you care about getting unread whispers received when you were offline, or any whisper you've
ever received (and that wasn't deleted), you'll need asession_id.This one is a bit trickier to get, and it will expire, unlikeauth_token. First open your browser,
navigate tohttps://www.destiny.gg/bigscreen, and login (if you're already logged in it works too).Bring up the dev tools (usually F12), go to theNetworktab, and refresh the page.
Find any request made on the destiny.gg domain (bigscreenwill probably be one of the first ones).
Scroll down to theCookiesheader. The key aftersid=is your session id.With the session key setup, you should be able to retrieve messages directly from your inbox.
Be mindful the session id expires after5 hours without use (?),
so if stuff stops working, check if this might be it.Extra FeaturesUseDGGChat().api(or directly withfrom dgg_chat.api import DGGAPI) to access other functionalities of the dgg API.UseDGGCDN()(from dgg_chat.cdn import DGGCDN) to retrieve info about stuff like flairs and emotes from the CDN.UseDGGLogs(from dgg_chat.overrustle_logs import DGGLogs) to retrieve chat logs.