Package: eventapi
7TV EventAPI WrapperThis is a Python wrapper for the 7TV EventAPI, which provides async access to the websocket events on
theirEmote Platform.RequirementsPython 3.8 or higherInstallationYou can install the 7TV EventAPI Wrapper using pip. Open your terminal and run the following command:pipinstalleventapiUsageHere's a simple example of how to use wrapper:importasynciofromeventapi.EventApiimportEventApifromeventapi.WebSocketimport(Dispatch,EventType,ResponseTypes,SubscriptionCondition,SubscriptionData,)asyncdefcallback(data:ResponseTypes):ifisinstance(data,Dispatch):print(f"Event data type:{data.type}")print(f"Event data body:{data.body}")else:print(f"Raw event data:{data.raw_data}")asyncdefmain():# create instance of EventApi with message callbackapp=EventApi(callback=callback)# connect to websocketawaitapp.connect()# create subscription with specified conditioncondition=SubscriptionCondition(object_id="6433b7cec07d26f890dd2d01")subscription=SubscriptionData(subscription_type=EventType.EMOTE_SET_ALL,condition=condition)awaitapp.subscribe(subscription_data=subscription)# run foreverawaitasyncio.Future()asyncio.run(main())Discord.py / Pycord example:fromtypingimportAnyimportaiohttpimportdiscordfromeventapi.EventApiimportEventApifromeventapi.WebSocketimport(Dispatch,EventType,ResponseTypes,SubscriptionCondition,SubscriptionData,)asyncdefformat_url(data:dict[str,Any])->str:base_url="https://cdn.7tv.app/emote/{}/4x".format(data.get("id"))if"animated"notindata:asyncwithaiohttp.ClientSession()ascs:asyncwithcs.get(base_url+".gif")asr:ifr.status==200:base_url+=".gif"else:ifdata.get("animated"):base_url+=".gif"returnbase_urlasyncdefcallback(data:ResponseTypes)->None:ifnotisinstance(data,Dispatch):returnifdata.type!=EventType.EMOTE_SET_UPDATE:returnchannel=client.get_channel(927288026000945162)# your channel idchanges:list[discord.Embed]=[]defadd_change(description:str,color:discord.Color,image_url:str):changes.append(discord.Embed(description=description,color=color).set_image(url=image_url))ifdata.body.pulled:forpulledindata.body.pulled:add_change("**Deleted emote:** `{}`".format(pulled.old_value.get("name")),discord.Color.brand_red(),awaitformat_url(pulled.old_value),)ifdata.body.pushed:forpushedindata.body.pushed:add_change("**Added emote:** `{}`".format(pushed.value.get("data").get("name")),discord.Color.brand_green(),awaitformat_url(pushed.value.get("data")),)ifdata.body.updated:forupdatedindata.body.updated:add_change("**Edited emote:** `{}` Â» `{}`".format(updated.old_value.get("name"),updated.value.get("name")),discord.Color.yellow(),awaitformat_url(updated.value),)iflen(changes)>0:awaitchannel.send(embeds=changes)intents=discord.Intents.default()client=discord.Client(intents=intents)client.eventapi=EventApi(callback=callback)@client.eventasyncdefon_ready():awaitclient.eventapi.connect()condition=SubscriptionCondition(object_id="6433b7cec07d26f890dd2d01")# your emote-set idsubscription=SubscriptionData(subscription_type=EventType.EMOTE_SET_ALL,condition=condition)awaitclient.eventapi.subscribe(subscription_data=subscription)client.run("your token here")# your tokenContributingContributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or
submit a pull request on theGitHub repository.LicenseThis project is licensed under theMIT License.