Skip to content

Commit

Permalink
Merge pull request #27 from ClanBadJas/dev
Browse files Browse the repository at this point in the history
Various small (bug)fixes
  • Loading branch information
MattsBos authored Feb 4, 2023
2 parents aa4ea7d + 17f5daa commit b3a100e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 55 deletions.
29 changes: 17 additions & 12 deletions clanbotjas/cogs/commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from math import floor
import re
import time

import discord
Expand All @@ -21,26 +22,30 @@ def __init__(self) -> None:
)

async def callback(self, interaction: discord.Interaction):
text = self.children[0].value
textToObjects = {}
for channel in interaction.client.get_all_channels():
channelName = "#" + channel.name
if channelName in text:
text = text.replace(channelName, channel.mention)
textToObjects[f"#{channel.name}"] = channel.mention
for member in interaction.client.get_all_members():
memberName = "@" + member.name
if memberName in text:
text = text.replace(memberName, member.mention)
for role in await interaction.client.get_guild(
settings.DISCORD_GUILD_ID
).fetch_roles():
textToObjects[f"@{member.name}"] = member.mention
for emoji in interaction.client.emojis:
textToObjects[f":{emoji.name}:"] = f"<:{emoji.name}:{emoji.id}>"
roles = await interaction.client.get_guild(
settings.DISCORD_GUILD_ID).fetch_roles()
for role in roles:
if role.name.startswith("@"):
roleName = role.name
else:
roleName = "@" + role.name
textToObjects[roleName] = role.mention

if roleName in text:
text = text.replace(roleName, role.mention)
names = sorted(textToObjects.keys(), key=lambda x: len(x), reverse=True)
regex = re.compile("(" + "|".join(names) + ")")

def stringToMention(match):
return textToObjects[match[0]]


text = re.sub(regex, stringToMention, self.children[0].value)
await interaction.channel.send(text)
await interaction.response.send_message("Message was sent.", ephemeral=True)

Expand Down
2 changes: 1 addition & 1 deletion clanbotjas/cogs/voicechannelbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def on_voice_state_update(self, member, before, after):
# Make sure this is not an event within the same channel

@commands.Cog.listener()
async def on_member_update(self, before, after):
async def on_presence_update(self, before, after):
"""
check if the user is playing a different game.
:param args:
Expand Down
73 changes: 31 additions & 42 deletions clanbotjas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,22 @@

load_dotenv()


def _int(name: str):
try:
return int(name)
except ValueError:
return None


# Get General Bot settings
DISCORD_TOKEN = os.getenv("BOT_TOKEN")
DISCORD_GUILD_ID = _int(os.getenv("GUILD_ID"))
DISCORD_LOG_CHANNEL = _int(os.getenv("LOG_CHANNEL"))

# Get user permission settings
DISCORD_COMMAND_PERMISSION_ROLE = _int(os.getenv("COMMAND_PERMISSION_ROLE"))

# Get Voice Auto Scaler settings
# Enable/disable feature toggles:
DISCORD_VOICE_SCALER_ENABLE = os.getenv("VOICE_SCALER_ENABLE") == "true"
DISCORD_VOICE_CHANNEL_CATEGORY = _int(os.getenv("VOICE_CHANNEL_CATEGORY"))
DISCORD_VOICE_CHANNEL_DEFAULT_NAME = os.getenv("VOICE_CHANNEL_DEFAULT_NAME")

# Get Self-Role text channel subscription settings
DISCORD_ROLEBOT_ENABLE = os.getenv("ROLEBOT_ENABLE") == "true"
DISCORD_ROLEBOT_SETTINGS_CHANNEL = _int(os.getenv("ROLEBOT_SETTINGS_CHANNEL"))

# Get Auto-Role settings
DISCORD_AUTO_ROLE_ENABLE = os.getenv("AUTO_ROLE_ENABLE") == "true"
DISCORD_AUTO_ROLES = os.getenv("AUTO_ROLES")

# Get Poll settings
DISCORD_POLL_ENABLE = os.getenv("POLL_ENABLE") == "true"
DISCORD_POLL_FONT_REGULAR = os.getenv("POLL_FONT_REGULAR")
DISCORD_POLL_FONT_BOLD = os.getenv("POLL_FONT_BOLD")
DISCORD_POLL_FONT_SCALE = _int(os.getenv("POLL_FONT_SCALE"))

# Set up a list of Guilds to connect, only one in this case
DISCORD_GUILD_IDS = [DISCORD_GUILD_ID]

# Define which intents the bot requires to function
INTENTS = discord.Intents(
members=True,
presences=True,
voice_states=True,
guild_messages=True,
guilds=True,
message_content=True,
)

# The default cog(s) to be started
DISCORD_COGS = [
Expand All @@ -64,15 +33,26 @@ def _int(name: str):
# If non-default cogs are enabled in config, add cogs to DISCORD_COGS to be started list.
if DISCORD_VOICE_SCALER_ENABLE:
DISCORD_COGS.append(OptionChoice(name="voicechannelbot", value="VoiceChannelBot"))
# Get Voice Auto Scaler settings
DISCORD_VOICE_CHANNEL_CATEGORY = _int(os.getenv("VOICE_CHANNEL_CATEGORY"))
DISCORD_VOICE_CHANNEL_DEFAULT_NAME = os.getenv("VOICE_CHANNEL_DEFAULT_NAME")

if DISCORD_ROLEBOT_ENABLE:
DISCORD_COGS.append(OptionChoice(name="rolebot", value="RoleBot"))
# Get Self-Role text channel subscription settings
DISCORD_ROLEBOT_SETTINGS_CHANNEL = _int(os.getenv("ROLEBOT_SETTINGS_CHANNEL"))

if DISCORD_AUTO_ROLE_ENABLE:
DISCORD_COGS.append(OptionChoice(name="autorole", value="AutoRole"))
if DISCORD_POLL_ENABLE:
DISCORD_COGS.append(OptionChoice(name="pollbot", value="PollBot"))
# Get Auto-Role settings
DISCORD_AUTO_ROLES = os.getenv("AUTO_ROLES")

# Set fonts, scale and image to use for poll embeds and results.
if DISCORD_POLL_ENABLE:
DISCORD_COGS.append(OptionChoice(name="pollbot", value="PollBot"))
# Get Poll settings
DISCORD_POLL_FONT_REGULAR = os.getenv("POLL_FONT_REGULAR")
DISCORD_POLL_FONT_BOLD = os.getenv("POLL_FONT_BOLD")
DISCORD_POLL_FONT_SCALE = _int(os.getenv("POLL_FONT_SCALE"))
DISCORD_TTF_SCALE_FACTOR = DISCORD_POLL_FONT_SCALE
DISCORD_TTF_POLL_NORMAL = ImageFont.truetype(
"data/{}".format(DISCORD_POLL_FONT_REGULAR), 15 * DISCORD_TTF_SCALE_FACTOR
Expand All @@ -83,10 +63,19 @@ def _int(name: str):
DISCORD_POLL_EMPTY, DISCORD_POLL_FULL, DISCORD_POLL_WIN = np.split(
np.array(Image.open("data/basepollimages.png")), 3
)
else:
DISCORD_TTF_SCALE_FACTOR = None
DISCORD_TTF_POLL_NORMAL = None
DISCORD_TTF_POLL_BOLD = None
DISCORD_POLL_EMPTY = None
DISCORD_POLL_FULL = None
DISCORD_POLL_WIN = None

# Get user permission settings
DISCORD_COMMAND_PERMISSION_ROLE = _int(os.getenv("COMMAND_PERMISSION_ROLE"))

# Set up a list of Guilds to connect, only one in this case
DISCORD_GUILD_IDS = [DISCORD_GUILD_ID]

# Define which intents the bot requires to function
INTENTS = discord.Intents(
members=True,
presences=True,
voice_states=True,
guild_messages=True,
guilds=True,
message_content=True,
)

0 comments on commit b3a100e

Please sign in to comment.