This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pixeldeee
committed
Aug 31, 2023
1 parent
4962a75
commit 2f0a3db
Showing
5 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from typing import Literal, Any | ||
from datetime import datetime | ||
from time import mktime | ||
from asyncio import create_task | ||
|
||
from .web import BaseWebhook, GatewayRequest | ||
|
||
class Activity: | ||
def __init__(self, name: str, type: Literal[0, 1, 2, 3, 4, 5] = 0, state: str = None, *, url: str = None, data: dict[str, Any] = None) -> None: | ||
if data: | ||
self.name = data.get('name') | ||
self.type = data.get('type') | ||
self.url = data.get('url') | ||
self.created_at = data.get('created_at') | ||
self.timestamps = data.get('timestamps') | ||
self.application_id = data.get('application_id') | ||
self.details = data.get('details') | ||
self.state = data.get('state') | ||
self.emoji = data.get('emoji') | ||
self.party = data.get('party') | ||
self.assets = data.get('assets') | ||
self.secrets = data.get('secrets') | ||
self.instance = data.get('instance') | ||
self.flags = data.get('flags') | ||
self.buttons = data.get('buttons') | ||
else: | ||
self.name = name | ||
self.type = type | ||
self.url = url | ||
self.state = state | ||
|
||
def eval(self) -> dict[str, Any]: | ||
return { | ||
'name': self.name, | ||
'type': self.type, | ||
'url': self.url, | ||
'state': self.state | ||
} | ||
|
||
|
||
class Presence: | ||
def __init__(self, activities: list[Activity], status: Literal['online', 'dnd', 'idle', 'invisible', 'offline'] = 'online', afk: bool = False) -> None: | ||
self.since: int = int(mktime(datetime.now().timetuple()) * 1000) | ||
self.activities = activities | ||
self.status = status | ||
self.afk = afk | ||
|
||
def register(self, webhook: BaseWebhook): | ||
if webhook.stream.running: | ||
create_task(webhook.stream.send_request(GatewayRequest(3, { | ||
'since': self.since, | ||
'activities': [i.eval() for i in self.activities], | ||
'status': self.status, | ||
'afk': self.afk | ||
}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Callable | ||
from asyncio import create_task | ||
from datetime import datetime | ||
from time import mktime | ||
|
||
class TimerLoop: | ||
def __init__(self, callable: Callable, days: int = 0, hours: int = 0, minutes: int = 0, seconds: int = 0) -> None: | ||
self.callable = callable | ||
|
||
self.every_time = seconds | ||
self.every_time += minutes * 60 | ||
self.every_time += hours * 60 * 60 | ||
self.every_time += days * 60 * 60 * 24 | ||
|
||
async def __thread(self): | ||
start_time = int(mktime(datetime.now().timetuple())) | ||
|
||
while True: | ||
time = int(mktime(datetime.now().timetuple())) | ||
|
||
if time - start_time >= self.every_time: | ||
start_time = int(mktime(datetime.now().timetuple())) | ||
|
||
await self.callable() | ||
|
||
|
||
def run(self): | ||
create_task(self.__thread()) |