Skip to content

Commit

Permalink
chore: Update Articuno to v5.0.2 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
B1ue-Dev authored May 7, 2023
2 parents d1d7690 + 97e42dd commit 3eb7d36
Show file tree
Hide file tree
Showing 35 changed files with 315 additions and 76 deletions.
92 changes: 74 additions & 18 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,37 @@
(C) 2022-2023 - B1ue-Dev
"""

import sys
import logging
import time
import datetime
import interactions
from interactions.ext.prefixed_commands import setup, PrefixedHelpCommand
from const import TOKEN, VERSION
from utils.utils import get_response

def get_local_time() -> datetime:
"""Returns latest UTC+7 time."""

utc_time = datetime.datetime.utcnow()
local_time = utc_time + datetime.timedelta(hours=7)
return local_time

async def get_latest_release_version() -> str:
"""Returns the latest version of Articuno on GitHub."""

url = f"https://api.github.com/repos/B1ue-Dev/Articuno/releases/latest"
response = await get_response(url)
return response["tag_name"]

if __name__ == "__main__":

client = interactions.Client(
activity=interactions.Activity(
name=f"for {VERSION}",
type=interactions.ActivityType.WATCHING,
),
basic_logging=True,
intents=interactions.Intents.DEFAULT
| interactions.Intents.MESSAGE_CONTENT
| interactions.Intents.GUILD_MEMBERS,
status=interactions.Status.ONLINE,
send_command_tracebacks=False,
logger = logging.getLogger()
logging.Formatter.converter = lambda *args: get_local_time().timetuple()
logging.basicConfig(
format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s",
datefmt="%d/%m/%Y %H:%M:%S",
level=0,
)

setup(client, default_prefix="$")
Expand All @@ -38,20 +50,44 @@
client.load_extension("exts.utils.__init__")
client.load_extension("utils.error")


@client.listen(interactions.events.Startup)
async def on_startup() -> None:
"""Fires up READY"""
websocket = f"{client.latency * 1:.0f}"
log_time = (
datetime.datetime.utcnow() + datetime.timedelta(hours=7)
).strftime("%d/%m/%Y %H:%M:%S")
print("".join(
[
f"""[{log_time}] Logged in as {client.user.username}.""",
f"""Latency: {websocket}ms.""",
],
))

print(
"".join(
[
f"""[{log_time}] Logged in as {client.user.username}.""",
f"""Latency: {websocket}ms.""",
],
)
)
latest_release_version = await get_latest_release_version()
if latest_release_version is not None and latest_release_version > VERSION:
print("".join(
[
"This Articuno version is not up to date.",
f"Your Articuno version: {VERSION}",
f"Latest version: {latest_release_version}",
],
))
else:
print(
""" _ _
/\ | | (_)
/ \ _ __| |_ _ ___ _ _ _ __ ___
/ /\ \ | '__| __| |/ __| | | | '_ \ / _ \
/ ____ \| | | |_| | (__| |_| | | | | (_) |
/_/ \_\_| \__|_|\___|\__,_|_| |_|\___/
- By B1ue-Dev -
You are on latest version. Enjoy using Articuno!"""
)

@client.listen(interactions.events.MessageCreate)
async def bot_mentions(_msg: interactions.events.MessageCreate) -> None:
Expand All @@ -74,5 +110,25 @@ async def bot_mentions(_msg: interactions.events.MessageCreate) -> None:
)
await msg.channel.send(embeds=embed)

@client.listen(interactions.events.MessageCreate)
async def bot_mentions(_msg: interactions.events.MessageCreate) -> None:
"""Check for bot mentions."""
msg = _msg.message
if (
f"@{client.user.id}" in msg.content
or f"<@{client.user.id}>" in msg.content
):
embed = interactions.Embed(
title="It seems like you mentioned me",
description="".join(
[
f"I could not help much but noticed you mentioned me.",
f"You can type ``/`` and choose **{client.user.username}**",
f"to see a list of available commands.",
],
),
color=0x6AA4C1,
)
await msg.channel.send(embeds=embed)

client.start(TOKEN)
2 changes: 1 addition & 1 deletion const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TOKEN = os.getenv("TOKEN")
"""The token of the bot."""

VERSION = "v5.0.1"
VERSION = "v5.0.2"
"""Bot version."""

LOG_CHANNEL = os.getenv("LOG_CHANNEL")
Expand Down
2 changes: 1 addition & 1 deletion exts/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def setup(client) -> None:
datetime.datetime.utcnow() + datetime.timedelta(hours=7)
).strftime("%d/%m/%Y %H:%M:%S")
Core(client)
logging.debug("""[%s] Loaded Core extension.""", log_time)
logging.info("Loaded Core extension.")
print(f"[{log_time}] Loaded Core extension.")
7 changes: 7 additions & 0 deletions exts/core/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import interactions
from interactions.ext.prefixed_commands import (
prefixed_command,
Expand Down Expand Up @@ -220,3 +221,9 @@ async def _msg_invite(self, ctx: PrefixedContext) -> None:
)

await ctx.send(embeds=embed, components=buttons)


def setup(client) -> None:
"""Setup the extension."""
Author(client)
logging.info("Loaded Author extension.")
24 changes: 7 additions & 17 deletions exts/core/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import inspect
import contextlib
import traceback
import logging
import asyncio
import interactions
from interactions.ext.paginators import Paginator
Expand All @@ -33,7 +34,6 @@ def __init__(self, client: interactions.Client) -> None:
name="code",
description="Code to evaluate.",
required=True,
autocomplete=True,
)
],
)
Expand Down Expand Up @@ -94,22 +94,6 @@ async def eval(
else:
await ctx.send("None", ephemeral=True)

@interactions.global_autocomplete("code")
async def code_autocomplete(
self, ctx: interactions.AutocompleteContext
) -> None:
"""Autocomplete for `code`"""
s = Script(ctx.input_text).complete()[0:20]
await ctx.send(
[
{
"name": f"{ctx.input_text + x.complete}",
"value": f"{ctx.input_text + x.complete}",
}
for x in (s if len(s) < 26 else s[0:25])
]
)

@prefixed_command(name="eval")
async def _eval(self, ctx: PrefixedContext, *, code: str) -> None:
"""Evaluates some code."""
Expand Down Expand Up @@ -212,3 +196,9 @@ async def shell(
)

await paginator.send(ctx)


def setup(client) -> None:
"""Setup the extension."""
Eval(client)
logging.info("Loaded Eval extension.")
61 changes: 61 additions & 0 deletions exts/core/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""
/help command.
(C) 2022-2023 - B1ue-Dev
"""

import interactions
from interactions.ext.paginators import Page, Paginator


class Help(interactions.Extension):
def __init__(self, client: interactions.Client) -> None:
self.client: interactions.Client = client

@interactions.slash_command(
name="help",
description="Get a list of all available commands.",
)
async def help(self, ctx: interactions.SlashContext) -> None:
"""Get a list of all available commands."""

embed = interactions.Embed(
title="List of available commands.",
color=0x7CB7D3,
thumbnail=interactions.EmbedAttachment(
url=self.client.user.avatar.url
),
)
help_list = []
i = 0

for command_index, command in enumerate(
self.client.application_commands
):
if isinstance(command, interactions.SlashCommand):
if i == 15:
help_list.append(embed)
i = 0
embed = interactions.Embed(
title="List of available commands.",
color=0x7CB7D3,
thumbnail=interactions.EmbedAttachment(
url=self.client.user.avatar.url
),
)

if command.sub_cmd_name is None:
embed.add_field(
name=f"/{command.name}", value=command.description
)
else:
if str(command.sub_cmd_name) != "None":
embed.add_field(
name=f"/{command.name} {command.sub_cmd_name}",
value=f"{command.sub_cmd_description}",
)

i += 1

paginator = Paginator.create_from_embeds(self.client, *help_list)
await paginator.send(ctx)
7 changes: 7 additions & 0 deletions exts/core/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import interactions
from interactions.ext.prefixed_commands import (
prefixed_command,
Expand Down Expand Up @@ -71,3 +72,9 @@ async def _ping(self, ctx: PrefixedContext) -> None:
)

await ctx.send(embeds=embed)


def setup(client) -> None:
"""Setup the extension."""
Ping(client)
logging.info("Loaded Ping extension.")
7 changes: 7 additions & 0 deletions exts/core/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import datetime
import platform
import interactions
Expand Down Expand Up @@ -203,3 +204,9 @@ async def _stats(self, ctx: PrefixedContext) -> None:
)

await ctx.send(embeds=embed, components=button)


def setup(client) -> None:
"""Setup the extension."""
Stats(client)
logging.info("Loaded Stats extension.")
2 changes: 1 addition & 1 deletion exts/fun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def setup(client) -> None:
datetime.datetime.utcnow() + datetime.timedelta(hours=7)
).strftime("%d/%m/%Y %H:%M:%S")
Fun(client)
logging.debug("""[%s] Loaded Fun extension.""", log_time)
logging.info("Loaded Fun extension.")
print(f"[{log_time}] Loaded Fun extension.")
5 changes: 1 addition & 4 deletions exts/fun/ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,5 @@ async def text(

def setup(client) -> None:
"""Setup the extension."""
log_time = (
datetime.datetime.utcnow() + datetime.timedelta(hours=7)
).strftime("%d/%m/%Y %H:%M:%S")
ASCII(client)
logging.debug("""[%s] Loaded ASCII extension.""", log_time)
logging.info("Loaded ASCII extension.")
11 changes: 9 additions & 2 deletions exts/fun/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import random
import asyncio
import aiohttp
Expand Down Expand Up @@ -218,7 +219,7 @@ async def gay(
async def joke(self, ctx: interactions.SlashContext) -> None:
"""Sends a random joke."""

url = "https://some-random-api.ml/joke"
url = "https://some-random-api.com/joke"
resp = await get_response(url)

embed = interactions.Embed(
Expand Down Expand Up @@ -323,7 +324,7 @@ async def dictionary(
) -> None:
"""Defines a word."""

url = "https://some-random-api.ml/dictionary"
url = "https://some-random-api.com/dictionary"
params = {"word": word}
resp = await get_response(url, params=params)

Expand Down Expand Up @@ -383,3 +384,9 @@ async def ai(self, ctx: interactions.SlashContext, message: str) -> None:
resp = await resp.json()

await ctx.send(content=resp["message"])


def setup(client) -> None:
"""Setup the extension."""
Fun(client)
logging.info("Loaded Fun extension.")
7 changes: 7 additions & 0 deletions exts/fun/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import asyncio
import random
import interactions
Expand Down Expand Up @@ -276,3 +277,9 @@ def check(_message: interactions.Message):

except KeyError:
await ctx.send("No result found.", ephemeral=True)


def setup(client) -> None:
"""Setup the extension."""
Google(client)
logging.info("Loaded Google extension.")
7 changes: 7 additions & 0 deletions exts/fun/hug.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(C) 2022-2023 - B1ue-Dev
"""

import logging
import io
import interactions
import aiohttp
Expand Down Expand Up @@ -99,3 +100,9 @@ async def hug(
else None,
files=file,
)


def setup(client) -> None:
"""Setup the extension."""
Hug(client)
logging.info("Loaded Hug extension.")
Loading

0 comments on commit 3eb7d36

Please sign in to comment.