Skip to content

Commit

Permalink
feat: add status loop task
Browse files Browse the repository at this point in the history
  • Loading branch information
eunwoo1104 committed Dec 20, 2023
1 parent 00a03ea commit 81dea00
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion addons/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import traceback
from asyncio import TimeoutError

from config import Config
from dico import ActionRow, Button, ButtonStyles, Channel, Embed, GuildMember, Role
from dico_command import on
from dico_interaction import InteractionContext

from config import Config
from laythe import (
BotPermissionNotFound,
LaytheAddonBase,
Expand Down
2 changes: 1 addition & 1 deletion addons/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
slash,
)

from laythe import LaytheAddonBase, LaytheBot
from laythe import LaytheAddonBase, LaytheBot, has_perm
from laythe.utils import EmbedColor, create_index_bar


Expand Down
43 changes: 43 additions & 0 deletions addons/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from asyncio import Task, sleep

from dico import Activity, ActivityTypes

from laythe import LaytheAddonBase, LaytheBot


class Tasks(LaytheAddonBase):
loop_status_task: Task

def on_load(self):
self.loop_status_task = self.bot.loop.create_task(self.loop_status())

def on_unload(self):
self.loop_status_task.cancel()

async def loop_status(self):
while True:
try:
await self.bot.wait_ready()

texts = [
"'laythe.codenu.kr'을 방문해보세요!",
f"{self.bot.guild_count}개 서버에서 사용",
]
for x in texts:
await self.bot.update_presence(
activities=[Activity(name=x, activity_type=ActivityTypes.GAME)]
)
await sleep(15)
except:
from traceback import print_exc

print_exc()
await sleep(15)


def load(bot: LaytheBot):
bot.load_addons(Tasks)


def unload(bot: LaytheBot):
bot.unload_addons(Tasks)
2 changes: 1 addition & 1 deletion addons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import platform

import psutil
from config import Config
from dico import (
ActionRow,
ApplicationCommandOptionType,
Expand All @@ -18,6 +17,7 @@
from dico_interaction import __version__ as interaction_version
from dico_interaction import checks, option, slash

from config import Config
from laythe import (
LaytheAddonBase,
LaytheBot,
Expand Down
3 changes: 2 additions & 1 deletion laythe/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from logging import Logger
from typing import Optional, Union

from config import Config
from dico import AllowedMentions, Embed, Guild, GuildMember, Intents, User
from dico.exception import HTTPError
from dico_command import Bot, Message
from dico_interaction import AutoComplete, ComponentCallback
from dico_interaction import InteractionClient as InteractionBase
from dico_interaction import InteractionCommand, InteractionContext

from config import Config

from .database import LaytheDB, Warn
from .utils import EmbedColor, kstnow

Expand Down

0 comments on commit 81dea00

Please sign in to comment.