Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from discord.ext.commands import has_any_role
- from discord.ext import tasks, commands
- from discord.ext import commands
- from discord.utils import get
- import discord
- import asyncio
- lobby_id = 790994912752566282
- sights_ids = [
- 791322835837648927,
- 791322883137732608,
- 791322947797123143,
- 791322991593914368
- ]
- gamemaster = 'Moderator'
- escaping_id = 734825521673666611
- ok_emoji = '\N{THUMBS UP SIGN}'
- book_emoji = '\N{BOOKS}'
- computer_emoji = '\N{DESKTOP COMPUTER}'
- envelope_emoji = '\N{ENVELOPE}'
- class Escaperoom_General(commands.Cog):
- def __init__(self, client):
- self.client = client
- self.ready = False
- @commands.Cog.listener()
- async def on_ready(self):
- print('Cog: Escaperoom Test is loaded in.')
- @commands.command()
- @has_any_role(gamemaster)
- async def reset(self, context):
- self.lobby = context.guild.get_channel(lobby_id)
- if context.message.channel != self.lobby:
- return
- self.sights = []
- for sight in sights_ids:
- self.sights.append(context.guild.get_channel(sight))
- for sight in self.sights:
- while len(await sight.history(limit = 1).flatten()) > 0:
- await sight.purge(limit = 10)
- self.escaper_role = get(context.guild.roles, id = escaping_id)
- await self.lobby.set_permissions(self.escaper_role, read_messages = True,
- send_messages = False,
- add_reactions = False)
- for sight_channel in self.sights:
- await sight_channel.set_permissions(self.escaper_role, read_messages = False)
- msg = await self.lobby.send(f'{context.author.mention}, lobby has been reset.')
- await asyncio.sleep(3)
- await msg.delete()
- self.ready = True
- await self.example_function()
- # await self.example_function_2()
- @commands.command()
- @has_any_role(gamemaster)
- async def escaperoom(self, context, *args):
- if not self.ready:
- await context.message.channel.send('The escaperoom hasn\'t been reset or is in progress.')
- return
- self.amount_of_players = len(args)
- self.players = args
- user = context.message.author
- log_msg = 'Escaperoom was started by ' + str(user) + ' with players: '
- for person in context.message.mentions:
- await person.add_roles(self.escaper_role)
- log_msg += person.name + ', '
- print(log_msg[:-2])
- self.ready = False
- async def timer(self):
- while self.game_in_progress:
- await asyncio.sleep(1)
- self.time_so_far += 1
- @commands.command()
- @has_any_role(gamemaster)
- async def intro(self, context, *args):
- if context.message.channel != self.lobby:
- return
- if self.amount_of_players == 1:
- prefix = 'Welcome, player, '
- elif self.amount_of_players == 2:
- prefix = 'Welcome, you two, '
- else:
- prefix = f'Welcome, you {self.amount_of_players}, '
- intro_msg = await self.lobby.send(prefix + 'to the escape room. Press the reaction if everything is clear.')
- await intro_msg.add_reaction(ok_emoji)
- reaction, _ = await self.client.wait_for('reaction_add')
- while not reaction.count > self.amount_of_players:
- await asyncio.sleep(1)
- await intro_msg.delete()
- await self.sights[0].set_permissions(self.escaper_role, read_messages = True, send_messages = False, add_reactions = True)
- await self.sights[1].set_permissions(self.escaper_role, read_messages = True, send_messages = False, add_reactions = True)
- await self.sights[2].set_permissions(self.escaper_role, read_messages = True, send_messages = False, add_reactions = True)
- await self.sights[3].set_permissions(self.escaper_role, read_messages = True, send_messages = False, add_reactions = True)
- self.game_in_progress = True
- self.time_so_far = 0
- await self.timer()
- # @tasks.loop(seconds=50.0)
- async def example_function(self):
- while len(await self.sights[0].history(limit = 1).flatten()) > 0:
- await self.sights[0].purge(limit = 10)
- await self.sights[0].send('This is the north wall. You see a **book**, a **computer** and an **envelope**.')
- msg = await self.sights[0].send(file = discord.File('cogs/walls/north.png'))
- await msg.add_reaction(book_emoji)
- book_reaction, _ = await self.client.wait_for('reaction_add')
- await msg.add_reaction(computer_emoji)
- computer_reaction, _ = await self.client.wait_for('reaction_add')
- await msg.add_reaction(envelope_emoji)
- envelope_reaction, _ = await self.client.wait_for('reaction_add')
- while (book_reaction.count == 1 and
- computer_reaction.count == 1 and
- envelope_reaction.count == 1):
- await asyncio.sleep(1)
- print('waiting for reaction north')
- if book_reaction.count > 1:
- print('Book!')
- elif computer_reaction.count > 1:
- print('Computer!')
- elif envelope_reaction.count > 1:
- print('Envelope!')
- # @tasks.loop(seconds=50.0)
- async def example_function_2(self):
- while len(await self.sights[1].history(limit = 1).flatten()) > 0:
- await self.sights[1].purge(limit = 10)
- await self.sights[1].send('This is the east wall. You see a **book**, a **computer** and an **envelope**.')
- msg = await self.sights[1].send(file = discord.File('cogs/walls/north.png'))
- await msg.add_reaction(book_emoji)
- book_reaction, _ = await self.client.wait_for('reaction_add')
- await msg.add_reaction(computer_emoji)
- computer_reaction, _ = await self.client.wait_for('reaction_add')
- await msg.add_reaction(envelope_emoji)
- envelope_reaction, _ = await self.client.wait_for('reaction_add')
- while (book_reaction.count == 1 and
- computer_reaction.count == 1 and
- envelope_reaction.count == 1):
- await asyncio.sleep(1)
- print('waiting for reaction north')
- if book_reaction.count > 1:
- print('Book!')
- elif computer_reaction.count > 1:
- print('Computer!')
- elif envelope_reaction.count > 1:
- print('Envelope!')
- def setup(client):
- client.add_cog(Escaperoom_General(client))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement