Skip to content

Instantly share code, notes, and snippets.

@Hunter87ff
Last active October 27, 2023 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hunter87ff/2be4608face1ae4a14308d8c7349e03d to your computer and use it in GitHub Desktop.
Save Hunter87ff/2be4608face1ae4a14308d8c7349e03d to your computer and use it in GitHub Desktop.
discord scrim managing bot v1.0
import discord, re, pytz, time
from discord.ext import commands, tasks
#from datetime import datetime
intents = discord.Intents.default()
intents.members = True
intents.presences = True
intents.message_content = True
bot = commands.AutoShardedBot(shard_count=1,command_prefix='.',intents=intents)
# async def extensions():
# await bot.load_extension("test2")
@bot.event
async def on_ready():
#await extensions()
print('Bot is ready.')
@bot.command()
@commands.bot_has_permissions(send_messages=True)
@commands.cooldown(2, 60, commands.BucketType.user)
async def ping(ctx):
await ctx.reply(f'**api latency : `{round(bot.latency*100)} ms`**')
def time_format(delta):
delta = str(delta)
time = ""
lst = delta.split(".")[0].split(":")
if(len(lst)<=3):
h,m,s = delta.split(".")[0].split(":")
time = f"{h}hr, {m}min, {s}sec"
elif(len(lst)>3):
d,h,m,s = delta.split(".")[0].split(":")
time = f"{d}day, {h}hr, {m}min, {s}sec"
return time
def find_team(message):
content = message.content.lower()
teamname = re.search(r"team.*", content)
if teamname is None:
return f"{message.author}'s team"
teamname = re.sub(r"<@*#*!*&*\d+>|team|name|[^\w\s]", "", teamname.group()).strip()
teamname = f"{teamname.title()}" if teamname else f"{message.author}'s team"
return teamname
async def ft_ch(message):
ctx = message
messages = [message async for message in ctx.channel.history(limit=123)]
for fmsg in messages:
if fmsg.author.id != ctx.author.id:
for mnt in fmsg.mentions:
if mnt not in message.mentions:
return None
if mnt in message.mentions:
return mnt
async def team_struct(msg, crole, tmrole):
msgs = [ms async for ms in msg.channel.history(limit=200)][::-1]
teams = "```"
tms = 1
for ms in msgs:
if tmrole in ms.author.roles or ms.author.bot:
pass
else:
tm = find_team(ms)
teams += f"{tms}) {tm} : {ms.author}\n"
tms += 1
teams += "```"
time_taken = msgs[-1].created_at - msgs[0].created_at
em = discord.Embed(title="Team List", description=teams, color=0x00ff00)
em.set_footer(text=f"Time Taken : {time_format(time_taken)}")
mes = await msg.channel.send(embed=em)
await mes.add_reaction("✅")
async def team_reg(message):
msg = message
tmrole = discord.utils.get(msg.guild.roles, name="scrim-mod") #tourney-mod role
if tmrole in msg.author.roles:
return
if message.author.bot or message.author == bot.user:
return
if message.channel.id != 1167331222494646302: #registration channel
return
req_men = 2
tslot = 12
crole = message.guild.get_role(1167424093574930432) #confirm role
ment = message.mentions
if not ment or len(ment) < req_men:
await message.reply(f"You must mention `{req_men}` or more members to register a team.", delete_after=5)
return await msg.delete()
ft = await ft_ch(message)
if ft != None:
return await message.reply(f"You've mentioned `{ft}` who is already in a team.")
else:
await message.author.add_roles(crole)
await message.add_reaction("✅")
if len(crole.members) == tslot:
await msg.channel.send("Registration closed")
return await team_struct(message, crole, tmrole)
@bot.command()
async def pub(ctx, channel:discord.TextChannel):
message = [ms async for ms in channel.history(limit=2)][0]
crole = message.guild.get_role(1167424093574930432)
tmrole = discord.utils.get(channel.guild.roles, name="scrim-mod")
ms = await ctx.send("Processing")
await team_struct(message, crole, tmrole)
await ms.edit(content="Done")
@bot.event
async def on_message(message):
await team_reg(message)
await bot.process_commands(message)
bot.run("token")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment