Simplify bot
This commit is contained in:
parent
f968e38acf
commit
468283967b
30
bot.py
30
bot.py
@ -3,7 +3,7 @@ from datetime import timedelta
|
|||||||
from os import environ
|
from os import environ
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from disnake import Client, Guild, Member
|
from disnake import Client, Guild
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from ics import Calendar, Event # type: ignore
|
from ics import Calendar, Event # type: ignore
|
||||||
from ics.alarm.display import DisplayAlarm # type: ignore
|
from ics.alarm.display import DisplayAlarm # type: ignore
|
||||||
@ -44,23 +44,6 @@ def get_guild_by_id(guild_id: Union[int, str]) -> Optional[Guild]:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_bot_member(guild: Guild) -> Optional[Member]:
|
|
||||||
for member in guild.members:
|
|
||||||
if member.id == client.user.id:
|
|
||||||
return member
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
async def get_guild_tag(member: Member) -> Optional[str]:
|
|
||||||
if member.guild_permissions.manage_guild:
|
|
||||||
if member.guild.vanity_url_code:
|
|
||||||
return member.guild.vanity_url_code
|
|
||||||
else:
|
|
||||||
invites = await member.guild.invites()
|
|
||||||
return invites[0].code
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def token_updater(token: str) -> None:
|
def token_updater(token: str) -> None:
|
||||||
session["oauth2_token"] = token
|
session["oauth2_token"] = token
|
||||||
|
|
||||||
@ -119,26 +102,25 @@ async def index(guild_id):
|
|||||||
if guild is None:
|
if guild is None:
|
||||||
return redirect(url_for(".login"))
|
return redirect(url_for(".login"))
|
||||||
|
|
||||||
bot = get_bot_member(guild)
|
|
||||||
guild_tag = await get_guild_tag(bot)
|
|
||||||
calendar = Calendar()
|
calendar = Calendar()
|
||||||
|
|
||||||
for scheduled_event in guild.scheduled_events:
|
for scheduled_event in guild.scheduled_events:
|
||||||
event = Event()
|
event = Event()
|
||||||
event.name = scheduled_event.name
|
event.name = scheduled_event.name
|
||||||
event.begin = scheduled_event.scheduled_start_time
|
event.begin = scheduled_event.scheduled_start_time
|
||||||
event.end = scheduled_event.scheduled_end_time
|
event.end = (
|
||||||
|
scheduled_event.scheduled_end_time
|
||||||
|
or scheduled_event.scheduled_start_time + timedelta(hours=2)
|
||||||
|
)
|
||||||
event.uid = str(scheduled_event.id)
|
event.uid = str(scheduled_event.id)
|
||||||
event.description = scheduled_event.description
|
event.description = scheduled_event.description
|
||||||
|
event.url = f"https://discord.com/events/{guild_id}/{scheduled_event.id}"
|
||||||
event.location = (
|
event.location = (
|
||||||
scheduled_event.entity_metadata.location
|
scheduled_event.entity_metadata.location
|
||||||
if scheduled_event.entity_metadata
|
if scheduled_event.entity_metadata
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
if guild_tag:
|
|
||||||
event.url = f"https://discord.gg/{guild_tag}?event={scheduled_event.id}"
|
|
||||||
|
|
||||||
alarm = DisplayAlarm()
|
alarm = DisplayAlarm()
|
||||||
alarm.trigger = timedelta(hours=1)
|
alarm.trigger = timedelta(hours=1)
|
||||||
event.alarms.append(alarm)
|
event.alarms.append(alarm)
|
||||||
|
8
poetry.lock
generated
8
poetry.lock
generated
@ -102,11 +102,11 @@ python-versions = "*"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "certifi"
|
name = "certifi"
|
||||||
version = "2021.10.8"
|
version = "2022.5.18.1"
|
||||||
description = "Python package for providing Mozilla's CA Bundle."
|
description = "Python package for providing Mozilla's CA Bundle."
|
||||||
category = "main"
|
category = "main"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = "*"
|
python-versions = ">=3.6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "charset-normalizer"
|
name = "charset-normalizer"
|
||||||
@ -735,8 +735,8 @@ blinker = [
|
|||||||
{file = "blinker-1.4.tar.gz", hash = "sha256:471aee25f3992bd325afa3772f1063dbdbbca947a041b8b89466dc00d606f8b6"},
|
{file = "blinker-1.4.tar.gz", hash = "sha256:471aee25f3992bd325afa3772f1063dbdbbca947a041b8b89466dc00d606f8b6"},
|
||||||
]
|
]
|
||||||
certifi = [
|
certifi = [
|
||||||
{file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"},
|
{file = "certifi-2022.5.18.1-py3-none-any.whl", hash = "sha256:f1d53542ee8cbedbe2118b5686372fb33c297fcd6379b050cca0ef13a597382a"},
|
||||||
{file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"},
|
{file = "certifi-2022.5.18.1.tar.gz", hash = "sha256:9c5705e395cd70084351dd8ad5c41e65655e08ce46f2ec9cf6c2c08390f71eb7"},
|
||||||
]
|
]
|
||||||
charset-normalizer = [
|
charset-normalizer = [
|
||||||
{file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"},
|
{file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"},
|
||||||
|
Loading…
Reference in New Issue
Block a user