2024-08-07 22:15:39 +01:00
|
|
|
import discord
|
2024-08-07 22:45:23 +01:00
|
|
|
import os
|
2024-08-07 23:23:52 +01:00
|
|
|
import random
|
2024-08-08 00:09:30 +01:00
|
|
|
from discord import app_commands
|
2024-08-07 22:45:23 +01:00
|
|
|
from discord.ext import commands
|
2024-08-08 00:09:30 +01:00
|
|
|
from config import TOKEN
|
2024-08-07 23:23:52 +01:00
|
|
|
|
2024-08-07 22:15:39 +01:00
|
|
|
intents = discord.Intents.default()
|
|
|
|
intents.message_content = True
|
2024-08-07 23:23:52 +01:00
|
|
|
intents.members = True
|
2024-08-07 22:15:39 +01:00
|
|
|
|
2024-08-08 00:09:30 +01:00
|
|
|
bot = commands.Bot(command_prefix='/', description="Matchy matches matchies", intents=intents)
|
2024-08-07 22:15:39 +01:00
|
|
|
|
2024-08-08 00:09:30 +01:00
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
|
|
|
print("Bot is Up and Ready!")
|
|
|
|
try:
|
|
|
|
synced = await bot.tree.sync()
|
|
|
|
print(f"Synced {len(synced)} command(s)")
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2024-08-07 23:23:52 +01:00
|
|
|
|
2024-08-08 00:09:30 +01:00
|
|
|
@bot.tree.command()
|
|
|
|
@app_commands.describe(per_group = "People per group")
|
|
|
|
async def matchy(interaction: discord.Interaction, per_group: int):
|
2024-08-07 23:23:52 +01:00
|
|
|
# Find the role
|
|
|
|
role = None
|
2024-08-08 00:09:30 +01:00
|
|
|
for r in interaction.guild.roles:
|
2024-08-07 23:23:52 +01:00
|
|
|
if r.name == "matchy":
|
|
|
|
role = r
|
|
|
|
break
|
|
|
|
if not role:
|
2024-08-08 00:09:30 +01:00
|
|
|
await interaction.response.send_message("Server has no @matchy role :(", ephemeral=True)
|
2024-08-07 23:23:52 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
# Find all the members in the role
|
|
|
|
matchies = []
|
2024-08-08 00:09:30 +01:00
|
|
|
for member in interaction.channel.members:
|
|
|
|
if not member.bot and role in member.roles:
|
|
|
|
matchies.append(member)
|
|
|
|
break
|
2024-08-07 23:23:52 +01:00
|
|
|
|
|
|
|
# Shuffle the people for randomness
|
|
|
|
random.shuffle(matchies)
|
2024-08-08 00:09:30 +01:00
|
|
|
|
|
|
|
# Calculate the number of groups to generate
|
|
|
|
total_num = len(matchies)
|
|
|
|
num_groups = total_num//per_group
|
|
|
|
if not num_groups:
|
|
|
|
num_groups = 1
|
2024-08-07 23:23:52 +01:00
|
|
|
|
2024-08-08 00:09:30 +01:00
|
|
|
# Split members into groups and share them
|
|
|
|
groups = [matchies[i::num_groups] for i in range(num_groups)]
|
|
|
|
for group in groups:
|
2024-08-07 23:23:52 +01:00
|
|
|
mentions = [m.mention for m in group]
|
2024-08-08 00:09:30 +01:00
|
|
|
await interaction.channel.send("Group : " + ", ".join(mentions))
|
|
|
|
|
|
|
|
await interaction.response.send_message("Done :)", ephemeral=True, silent=True)
|
2024-08-07 23:23:52 +01:00
|
|
|
|
2024-08-08 00:09:30 +01:00
|
|
|
bot.run(os.getenv(config.TOKEN))
|