Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use unix line endings #47

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
hikari==2.0.0.dev122
hikari-arc==1.1.0
ruff==0.2.0
pre-commit==3.6.0
python-dotenv==1.0.1
hikari==2.0.0.dev122
hikari-arc==1.1.0
ruff==0.2.0
pre-commit==3.6.0
python-dotenv==1.0.1
12 changes: 6 additions & 6 deletions src/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from hikari import Activity, ActivityType
from src.bot import bot
if __name__ == "__main__":
bot.run(activity=Activity(name="Webgroup issues", type=ActivityType.WATCHING))
from hikari import Activity, ActivityType

from src.bot import bot

if __name__ == "__main__":
bot.run(activity=Activity(name="Webgroup issues", type=ActivityType.WATCHING))
72 changes: 36 additions & 36 deletions src/bot.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import logging
import sys
import arc
import hikari
from src.config import DEBUG, TOKEN
if TOKEN is None:
print("TOKEN environment variable not set. Exiting.")
sys.exit(1)
bot = hikari.GatewayBot(
token=TOKEN,
banner=None,
intents=hikari.Intents.ALL_UNPRIVILEGED | hikari.Intents.MESSAGE_CONTENT,
logs="DEBUG" if DEBUG else "INFO",
)
logging.info(f"Debug mode is {DEBUG}; You can safely ignore this.")
client = arc.GatewayClient(bot, is_dm_enabled=False)
client.load_extensions_from("./src/extensions/")
@client.set_error_handler
async def error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if DEBUG:
message = f"```{exc}```"
else:
message = "If this persists, create an issue at <https://webgroup-issues.redbrick.dcu.ie/>."
await ctx.respond(f"❌ Blockbot encountered an unhandled exception. {message}")
logging.error(exc)
raise exc
import logging
import sys

import arc
import hikari

from src.config import DEBUG, TOKEN

if TOKEN is None:
print("TOKEN environment variable not set. Exiting.")
sys.exit(1)

bot = hikari.GatewayBot(
token=TOKEN,
banner=None,
intents=hikari.Intents.ALL_UNPRIVILEGED | hikari.Intents.MESSAGE_CONTENT,
logs="DEBUG" if DEBUG else "INFO",
)

logging.info(f"Debug mode is {DEBUG}; You can safely ignore this.")

client = arc.GatewayClient(bot, is_dm_enabled=False)
client.load_extensions_from("./src/extensions/")


@client.set_error_handler
async def error_handler(ctx: arc.GatewayContext, exc: Exception) -> None:
if DEBUG:
message = f"```{exc}```"
else:
message = "If this persists, create an issue at <https://webgroup-issues.redbrick.dcu.ie/>."

await ctx.respond(f"❌ Blockbot encountered an unhandled exception. {message}")
logging.error(exc)

raise exc
20 changes: 10 additions & 10 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.environ.get("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)
CHANNEL_IDS: dict[str, int] = {"lobby": 627542044390457350}
import os

from dotenv import load_dotenv

load_dotenv()

TOKEN = os.environ.get("TOKEN") # required
DEBUG = os.environ.get("DEBUG", False)

CHANNEL_IDS: dict[str, int] = {"lobby": 627542044390457350}
116 changes: 60 additions & 56 deletions src/extensions/boosts.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,60 @@
import arc
import hikari

from src.config import CHANNEL_IDS
from src.utils import get_guild

plugin = arc.GatewayPlugin(name="Boosts")

BOOST_TIERS: list[hikari.MessageType] = [
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2,
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3,
]

BOOST_MESSAGE_TYPES: list[hikari.MessageType] = BOOST_TIERS + [hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION]


def build_boost_message(
message_type: hikari.MessageType | int,
number_of_boosts: str | None,
booster_user: hikari.Member,
guild: hikari.Guild,
) -> str:
assert message_type in BOOST_MESSAGE_TYPES

base_message = f"{booster_user.display_name} just boosted the server"
multiple_boosts_message = f" **{number_of_boosts}** times" if number_of_boosts else ""

message = base_message + multiple_boosts_message + "!"

if message_type in BOOST_TIERS:
count = BOOST_TIERS.index(message_type) + 1
message += f"\n{guild.name} has reached **Level {count}!**"

return message


@plugin.listen()
async def on_message(event: hikari.GuildMessageCreateEvent) -> None:
if event.message.type not in BOOST_MESSAGE_TYPES:
return

assert event.member is not None
message = build_boost_message(
event.message.type,
number_of_boosts=event.content,
booster_user=event.member,
guild=await get_guild(plugin.client, event),
)

await plugin.client.rest.create_message(CHANNEL_IDS["lobby"], content=message)


@arc.loader
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)
import arc
import hikari

from src.config import CHANNEL_IDS
from src.utils import get_guild

plugin = arc.GatewayPlugin(name="Boosts")

BOOST_TIERS: list[hikari.MessageType] = [
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1,
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2,
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3,
]

BOOST_MESSAGE_TYPES: list[hikari.MessageType] = BOOST_TIERS + [
hikari.MessageType.USER_PREMIUM_GUILD_SUBSCRIPTION
]


def build_boost_message(
message_type: hikari.MessageType | int,
number_of_boosts: str | None,
booster_user: hikari.Member,
guild: hikari.Guild,
) -> str:
assert message_type in BOOST_MESSAGE_TYPES

base_message = f"{booster_user.display_name} just boosted the server"
multiple_boosts_message = (
f" **{number_of_boosts}** times" if number_of_boosts else ""
)

message = base_message + multiple_boosts_message + "!"

if message_type in BOOST_TIERS:
count = BOOST_TIERS.index(message_type) + 1
message += f"\n{guild.name} has reached **Level {count}!**"

return message


@plugin.listen()
async def on_message(event: hikari.GuildMessageCreateEvent) -> None:
if event.message.type not in BOOST_MESSAGE_TYPES:
return

assert event.member is not None
message = build_boost_message(
event.message.type,
number_of_boosts=event.content,
booster_user=event.member,
guild=await get_guild(plugin.client, event),
)

await plugin.client.rest.create_message(CHANNEL_IDS["lobby"], content=message)


@arc.loader
def loader(client: arc.GatewayClient) -> None:
client.add_plugin(plugin)
Loading