rewrite parts of start and stop commands

This commit is contained in:
Aaron Riedel 2022-01-31 22:13:16 +01:00
parent a493945552
commit 9525db62b5

42
bot.py
View file

@ -19,9 +19,15 @@ def right(s, amount):
def mid(s, offset, amount): def mid(s, offset, amount):
return s[offset:offset+amount] return s[offset:offset+amount]
intents = discord.Intents(
guilds=True,
members=True,
messages=True,
)
token = os.environ['TOKEN'] token = os.environ['TOKEN']
prefix = os.environ['PREFIX'] prefix = os.environ['PREFIX']
bot = commands.Bot(command_prefix=prefix) bot = commands.Bot(intents=intents, command_prefix=prefix)
client = discord.Client() client = discord.Client()
admin_role=261603488331595776 admin_role=261603488331595776
@ -230,23 +236,18 @@ async def say(ctx, *, arg):
@bot.command(help="Starte ne Runde PnP", usage="@Rolle") @bot.command(help="Starte ne Runde PnP", usage="@Rolle")
@is_gm() @is_gm()
async def start(ctx, role_id): async def start(ctx, role_mention):
await ctx.message.delete() await ctx.message.delete()
role_id = right(left(role_id, len(role_id)-1), len(role_id) - 4) await pnp_info = ctx.guild.fetch_channel(435501602485305345)
for r in ctx.author.roles: await pnp_voice = ctx.guild.fetch_channel(435869507123281920)
if str(r.id) == role_id: role = ctx.message.role_mentions[0]
role = r
em = discord.Embed(description='gespieltes PnP: %s\nTeilnehmer (zum Start):' % role.mention, colour=0x00770d) em = discord.Embed(description='gespieltes PnP: %s\nTeilnehmer (zum Start):' % role.mention, colour=0x00770d)
move_member = [] for c in ctx.guild.voice_channels:
for c in ctx.guild.channels: for m in c.members:
if str(c.type) == "voice": if role in m.roles:
for m in c.members: await m.move_to(pnp_voice)
if role in m.roles: em.add_field(name=":white_check_mark: " + m.display_name, value = m.mention + " ist am Start! Juhu!", inline=False)
move_member.append(m) start_msg = await pnp_info.send(content=":game_die: **INFO: PnP Sitzung gestartet!**",embed=em)
for m in move_member:
await m.move_to(bot.get_channel(435869507123281920))
em.add_field(name=":white_check_mark: " + m.display_name, value = m.mention + "ist am Start! Juhu!", inline=False)
start_msg = await bot.get_channel(435501602485305345).send(content=":game_die: **INFO: PnP Sitzung gestartet!**",embed=em)
text_file = open("start_id.txt", "w") text_file = open("start_id.txt", "w")
text_file.write(str(start_msg.id)) text_file.write(str(start_msg.id))
text_file.close() text_file.close()
@ -255,15 +256,18 @@ async def start(ctx, role_id):
@is_gm() @is_gm()
async def stop(ctx): async def stop(ctx):
await ctx.message.delete() await ctx.message.delete()
await pnp_info = ctx.guild.fetch_channel(435501602485305345)
await pnp_voice = ctx.guild.fetch_channel(435869507123281920)
await move_to_talk = ctx.guild.fetch_channel(801869864745697280)
text_file = open("start_id.txt", "r") text_file = open("start_id.txt", "r")
start_id = text_file.read() start_id = text_file.read()
text_file.close() text_file.close()
start_msg = await bot.get_channel(435501602485305345).fetch_message(start_id) start_msg = await pnp_info.fetch_message(start_id)
now_time = datetime.datetime.utcnow().replace(microsecond=0, tzinfo=datetime.timezone.utc) now_time = datetime.datetime.utcnow().replace(microsecond=0, tzinfo=datetime.timezone.utc)
then_time = start_msg.created_at.replace(microsecond=0, tzinfo=datetime.timezone.utc) then_time = start_msg.created_at.replace(microsecond=0, tzinfo=datetime.timezone.utc)
dauer = str(now_time - then_time) dauer = str(now_time - then_time)
for m in bot.get_channel(435869507123281920).members: for m in pnp_voice.members:
await m.move_to(bot.get_channel(801869864745697280)) await m.move_to(move_to_talk)
await start_msg.edit(content=":game_die: **INFO: PnP Sitzung beendet!** Dauer: %s" % dauer) await start_msg.edit(content=":game_die: **INFO: PnP Sitzung beendet!** Dauer: %s" % dauer)
@bot.command(help="bringt dich ins Labor :)", usage="") @bot.command(help="bringt dich ins Labor :)", usage="")