|
| 1 | +import typing |
| 2 | +import discord |
| 3 | +from discord.ext import commands |
| 4 | +from . import http |
| 5 | + |
| 6 | + |
| 7 | +class SlashContext: |
| 8 | + def __init__(self, |
| 9 | + _http: http.SlashCommandRequest, |
| 10 | + _json: dict, |
| 11 | + _discord: commands.Bot): |
| 12 | + self.__token = _json["token"] |
| 13 | + self.name = _json["data"]["name"] |
| 14 | + self.__id = _json["id"] |
| 15 | + self.id = _json["data"]["id"] |
| 16 | + self._http = _http |
| 17 | + self.guild: discord.Guild = _discord.get_guild(int(_json["guild_id"])) |
| 18 | + self.author: discord.Member = self.guild.get_member(int(_json["member"]["user"]["id"])) |
| 19 | + |
| 20 | + async def send(self, |
| 21 | + send_type: int = 4, |
| 22 | + text: str = "", |
| 23 | + embeds: typing.List[discord.Embed] = None, |
| 24 | + tts: bool = False): |
| 25 | + base = { |
| 26 | + "type": send_type, |
| 27 | + "data": { |
| 28 | + "tts": tts, |
| 29 | + "content": text, |
| 30 | + "embeds": [x.to_dict() for x in embeds] if embeds else [], |
| 31 | + "allowed_mentions": [] |
| 32 | + } |
| 33 | + } |
| 34 | + await self._http.post(base, self.__id, self.__token) |
| 35 | + |
| 36 | + |
| 37 | +""" |
| 38 | +{ |
| 39 | + "type": 2, |
| 40 | + "token": "A_UNIQUE_TOKEN", |
| 41 | + "member": { |
| 42 | + "user": { |
| 43 | + "id": 53908232506183680, |
| 44 | + "username": "Mason", |
| 45 | + "avatar": "a_d5efa99b3eeaa7dd43acca82f5692432", |
| 46 | + "discriminator": "1337", |
| 47 | + "public_flags": 131141 |
| 48 | + }, |
| 49 | + "roles": [539082325061836999], |
| 50 | + "premium_since": null, |
| 51 | + "permissions": "2147483647", |
| 52 | + "pending": false, |
| 53 | + "nick": null, |
| 54 | + "mute": false, |
| 55 | + "joined_at": "2017-03-13T19:19:14.040000+00:00", |
| 56 | + "is_pending": false, |
| 57 | + "deaf": false |
| 58 | + }, |
| 59 | + "id": "786008729715212338", |
| 60 | + "guild_id": "290926798626357999", |
| 61 | + "data": { |
| 62 | + "options": [{ |
| 63 | + "name": "cardname", |
| 64 | + "value": "The Gitrog Monster" |
| 65 | + }], |
| 66 | + "name": "cardsearch", |
| 67 | + "id": "771825006014889984" |
| 68 | + }, |
| 69 | + "channel_id": "645027906669510667" |
| 70 | +} |
| 71 | +""" |
0 commit comments