-
Notifications
You must be signed in to change notification settings - Fork 8
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
Showing
9 changed files
with
260 additions
and
231 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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)) |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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} |
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 |
---|---|---|
@@ -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) |
Oops, something went wrong.