{"id":16865909,"url":"https://github.com/gabrieljablonski/dgg-chat","last_synced_at":"2025-08-19T04:31:06.128Z","repository":{"id":50166711,"uuid":"271979303","full_name":"gabrieljablonski/dgg-chat","owner":"gabrieljablonski","description":"A package that lets you do stuff in the destiny.gg chat","archived":false,"fork":false,"pushed_at":"2022-12-08T10:45:23.000Z","size":172,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-02T05:47:26.503Z","etag":null,"topics":["destinygg","dgg","websocket-chat","websocket-client","websockets"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabrieljablonski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-13T09:34:18.000Z","updated_at":"2024-10-30T06:04:56.000Z","dependencies_parsed_at":"2023-01-25T01:15:25.320Z","dependency_job_id":null,"html_url":"https://github.com/gabrieljablonski/dgg-chat","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljablonski%2Fdgg-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljablonski%2Fdgg-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljablonski%2Fdgg-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljablonski%2Fdgg-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrieljablonski","download_url":"https://codeload.github.com/gabrieljablonski/dgg-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230315757,"owners_count":18207478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["destinygg","dgg","websocket-chat","websocket-client","websockets"],"created_at":"2024-10-13T14:48:50.844Z","updated_at":"2024-12-18T17:41:00.076Z","avatar_url":"https://github.com/gabrieljablonski.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DGG Chat\n\nA package that lets you do stuff in [dgg](https://destiny.gg) chat, like parsing messages in chat,\nreplying to whispers, accessing the dgg API, and retrieving user logs and CDN assets.\n\nIf you're interested in making a chat bot, check the [`dgg-chat-bot`](https://github.com/gabrieljablonski/dgg-chat-bot) package.\n\n## Installing\n\nThis package is available via pip (requires python 3.8).\n\n```sh\npip install dgg-chat\n```\n\nA (very) minimal working example (more details below):\n\n```python\nfrom dgg_chat import DGGChat\n\nchat = DGGChat()\n\n@chat.on_chat_message\ndef on_chat_message(message):\n    print(message)\n\nchat.run_forever()\n```\n\n## How It Works\n\nThe package makes use of messages sent via the dgg websocket interface.\nIt's based around the `DGGChat` class, which runs the main event loop, \ninvoking the handlers implemented, as well as allowing you to reply to whispers.\n\nWhen a message is received from the websocket, it is redirected to its respective handler \n(and any other relevant [special handler](#special-events)).\n\n## How To Use\n\nA handler is a method that receives one argument (with three exceptions), which will \nbe of type `dgg_chat.messages.Message` or one of its subclasses. \n\nThe three exceptions are: the handlers for the `WHISPER_SENT` and the `WS_CLOSE` events, which have no arguments;\nand the `HANDLER_ERROR` event, which receive the exceptions raised on trying to handle the message.\n\nEach handler receives a specific type of message, defined in the [`messages`](./dgg_chat/messages/_messages.py) module.\nTo register an event handler, you must use one of the decorators listed in the \n[Event Types and Their Respective Handlers](#event-types-and-their-respective-handlers) section.\n\nAll handlers are also synchronous, that is, a handler will only be called after the previous one\nfinished its work. Asynchronous support might be implemented in the future.\n\nA simple example can be found under the [`DGGChat`](#dggchat) section. More details can be found in the [`example.py`](./example.py) file.\n\n### Event Types and Their Respective Handlers\n\n| Decorator                 | Event Description                                                                                                             |\n|:-------------------------:|:-----------------------------------------------------------------------------------------------------------------------------:|\n| `on_served_connections`   | The chat connection was established. Lists all connected users and the count of served connections.                           |\n| `on_user_joined`          | A user has joined the chat.                                                                                                   |\n| `on_user_quit`            | A user has left the chat.                                                                                                     |\n| `on_broadcast`            | A broadcast message (yellow message) was received, such as when a user subscribes.                                            |\n| `on_chat_message`         | A chat message was received.                                                                                                  |\n| `on_whisper`              | A whisper was received.                                                                                                       |\n| `on_whisper_sent`         | The whisper was successfully sent.                                                                                            |\n| `on_mute`                 | A user was muted.                                                                                                             |\n| `on_unmute`               | A user was unmuted.                                                                                                           |\n| `on_ban`                  | A user was banned.                                                                                                            |\n| `on_unban`                | A user was unbanned.                                                                                                          |\n| `on_sub_only`             | Submode was toggled in chat.                                                                                                  |\n| `on_error_message`        | A chat related error occurred (see [common errors](#common-error_message-causes)).                                            |\n\n#### Special Events\n\nBesides the already listed events, some others are triggered on special situations.\nThose are as follow:\n\n| Decorator              | Associated Event                                                                                                                                                        |\n|:----------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| `before_every_message` | Before every event listed in the previous table. The specific handlers for that event type will still be called.                                                        |\n| `after_every_message`  | After every event listed in the previous table. The specific handlers for that event type will still be called.                                                         |\n| `on_mention`           | Received a `ChatMessage` that contains the username for the authenticated user. Requires either `auth_token` or `session_id`. `CHAT_MESSAGE` handler is still called.   |\n| `on_ws_error`          | Something wrong happened with the websocket connection.                                                                                                                 |\n| `on_ws_close`          | Websocket connection got closed, usually by calling `DGGChat().disconnect()`.                                                                                           |\n| `on_handler_error`     | An exception was raised inside at least one of the handlers called.                                                                                                     |\n\n### Common `ERROR_MESSAGE` Causes\n\n| Error Message | Explanation                                                                                                                                                            |\n|:-------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| `\"throttled\"` | Messages got sent too fast with `DGGChat().send_whisper()`.                                                                                                            |\n| `\"needlogin\"` | Invalid `auth_token` or `session_login` provided. See [authentication](#authentication).                                                                               |\n| `\"notfound\"`  | Usually when target user for `DGGChat().send_whisper()` was not found.                                                                                                 |\n\n## `DGGChat`\n\nThis is the class that runs the show. It takes the handlers you've implemented and calls them when appropriate.\nThe features listed below are also available (though some are not usable right away):\n\n- Sending whispers with `DGGChat().send_whisper()`.\n- View info for current user with `DGGChat().profile` property.\n- Get unread whispers with `DGGChat().get_unread_whispers()`.\n\nAll of these features require the connection to be [authenticated](#authentication).\n\nBy default, you won't be able to send whispers. This was done intentionally and a quick look at \nthe source code should lead you to how to enable sending whispers to people who whispered you first. \nHopefully this discourages some ill-intentioned folks from using this to do dumb shit in the chat.\n\nHere's a quick example on how to setup and run the chat instance.\nMore details can be found in the [`example.py`](./example.py) file.\n\n```python\nfrom dgg_chat import DGGChat\n\ndgg_auth_token = \"\u003cyour dgg auth token\u003e\"\n\nchat = DGGChat(auth_token=dgg_auth_token)\n\n@chat.on_user_joined\ndef on_user_joined(joined):\n    print(f\"{joined.user} just joined!\")\n\n@chat.on_chat_message\ndef on_chat_message(message):\n    print(f\"{message.user} just said something: {message.content}\")\n\n@chat.on_whisper\ndef on_whisper(whisper):\n    print(f\"{whisper.user} just sent you a whisper: {whisper.content}\")\n    chat.send_whisper(whisper.user, \"Hello!\")\n\n...\n\n# blocking call\nchat.run_forever()\n```\n\n## Authentication\n\nAlthough you can run the chat anonymously and still be able to view all messages in chat,\nreplying to whispers requires your connection to be authenticated.\n\n### Auth Token\n\nThe easiest way to do that is to create an `auth_token` associated with your account. \nIt will allow you to get your profile info, send chat messages, and whisper other users.\nThis can be done by going to the dgg [developer dashboard](https://www.destiny.gg/profile/developer),\nclicking on `Connections`, and `Add login key`. The generated key should be a 64 character alphanumeric string.\n\n**CAUTION**: this key acts as your password, so be careful not to share it with anyone \n(also don't put in any of your unignored repo files!). With it, someone else can use it to send \nmessages as you and read your whispers. If you believe you've leaked your key somewhere, go back to the\ndashboard, remove it, and generate another.\n\nAuth tokens [usually do not expire](https://github.com/destinygg/website/blob/master/lib/Destiny/Controllers/ProfileController.php#L345).\n\n### Session ID\n\nIf you care about getting unread whispers received when you were offline, or any whisper you've\never received (and that wasn't deleted), you'll need a `session_id`.\n\nThis one is a bit trickier to get, and it will expire, unlike `auth_token`. First open your browser, \nnavigate to [https://www.destiny.gg/bigscreen](), and login (if you're already logged in it works too).\n\nBring up the dev tools (usually F12), go to the `Network` tab, and refresh the page.\nFind any request made on the destiny.gg domain (`bigscreen` will probably be one of the first ones).\nScroll down to the `Cookies` header. The key after `sid=` is your session id.\n\n![session id](https://i.imgur.com/v42efey.png)\n\nWith the session key setup, you should be able to retrieve messages directly from your inbox.\nBe mindful the session id expires after [5 hours without use (?)](https://github.com/destinygg/website/blob/master/public/index.php#L18), \nso if stuff stops working, check if this might be it.\n\n## Extra Features\n\n- Use `DGGChat().api` (or directly with `from dgg_chat.api import DGGAPI`) to access other functionalities of the dgg API.\n- Use `DGGCDN()` (`from dgg_chat.cdn import DGGCDN`) to retrieve info about stuff like flairs and emotes from the CDN.\n- Use `DGGLogs` (`from dgg_chat.overrustle_logs import DGGLogs`) to retrieve chat logs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrieljablonski%2Fdgg-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrieljablonski%2Fdgg-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrieljablonski%2Fdgg-chat/lists"}