Compare commits

..

No commits in common. "python" and "main" have entirely different histories.
python ... main

View file

@ -109,9 +109,7 @@ async def countdown(channel):
with open('config.json') as f: with open('config.json') as f:
config = json.load(f) config = json.load(f)
intents = discord.Intents.default() client = discord.Client()
intents.members = True
client = discord.Client(intents=intents)
async def handle_guild_message(message): async def handle_guild_message(message):
if not message.content.startswith('!waggle'): if not message.content.startswith('!waggle'):
@ -183,34 +181,33 @@ async def handle_guild_message(message):
await message.channel.send("{} Welcome to pollination! You'll be randomly paired up, moved into separate voice channels, spend some time chatting, and then move to a new channel and meet somebody else. Each round will last 5 minutes, and there'll be {} rounds total. I'll announce when your time is nearly up so you can wrap up your conversations, and I'll automatically move you to a different voice channel at the start of each new round. If you keep this text channel open, you'll get audible countdowns via text-to-speech at the end of each round. **Feel free to leave at any time if you need to. You won't get moved into new voice channels if you disconnect from voice.** If you find yourself alone in a channel, the person you were paired with for that round may have left; just relax and take a break for 5 minutes. Have fun!".format(mention_all, len(schedule))) await message.channel.send("{} Welcome to pollination! You'll be randomly paired up, moved into separate voice channels, spend some time chatting, and then move to a new channel and meet somebody else. Each round will last 5 minutes, and there'll be {} rounds total. I'll announce when your time is nearly up so you can wrap up your conversations, and I'll automatically move you to a different voice channel at the start of each new round. If you keep this text channel open, you'll get audible countdowns via text-to-speech at the end of each round. **Feel free to leave at any time if you need to. You won't get moved into new voice channels if you disconnect from voice.** If you find yourself alone in a channel, the person you were paired with for that round may have left; just relax and take a break for 5 minutes. Have fun!".format(mention_all, len(schedule)))
first_round = True
for matching in schedule: for matching in schedule:
await message.channel.send('Next round starting in 30 seconds:') announcement = 'Next round starting in 30 seconds:\n'
for ((a, b), c) in zip(matching, pollination_channels): announcement += '\n'.join('{0} and {1} in {2}'.format(a.mention, b.mention, c.name) for ((a, b), c) in zip(matching, pollination_channels))
await message.channel.send('{0} and {1} in {2}'.format(a.mention, b.mention, c.name)) await message.channel.send(announcement)
await countdown(message.channel) await countdown(message.channel)
for (pair, c) in zip(matching, pollination_channels): for ((a, b), c) in zip(matching, pollination_channels):
for u in pair: try:
if u.voice is not None and ((first_round and u.voice.channel == main_voice_channel) or u.voice.channel in pollination_channels): await a.move_to(c)
try: except discord.DiscordException as e:
await u.move_to(c) print('failed to move participant {}: {}'.format(a, e), file=sys.stderr)
except discord.DiscordException as e: try:
print('failed to move participant {}: {}'.format(u, e), file=sys.stderr) await b.move_to(c)
except discord.DiscordException as e:
print('failed to move participant {}: {}'.format(b, e), file=sys.stderr)
await asyncio.sleep(60*3) await asyncio.sleep(60*3)
await message.channel.send('Round ending in 2 minutes {}'.format(mention_all)) await message.channel.send('Round ending in 2 minutes {}'.format(mention_all))
await asyncio.sleep(60) await asyncio.sleep(60)
await message.channel.send('Round ending in 1 minute {}'.format(mention_all)) await message.channel.send('Round ending in 1 minute {}'.format(mention_all))
await asyncio.sleep(30) await asyncio.sleep(30)
first_round = False
await message.channel.send('Returning to main channel in 30 seconds {}'.format(mention_all)) await message.channel.send('Returning to main channel in 30 seconds {}'.format(mention_all))
await countdown(message.channel) await countdown(message.channel)
for u in participants: for u in participants:
if u.voice is not None and u.voice.channel in pollination_channels: try:
try: await u.move_to(main_voice_channel)
await u.move_to(main_voice_channel) except discord.DiscordException as e:
except discord.DiscordException as e: print('failed to move participant {}: {}'.format(u, e), file=sys.stderr)
print('failed to move participant {}: {}'.format(u, e), file=sys.stderr)
await delete_if_possible(pollination_channels) await delete_if_possible(pollination_channels)
@ -223,22 +220,22 @@ async def handle_dm(message):
discriminator = match.group(2) discriminator = match.group(2)
matching_users = [u for u in client.users if u.name == name and u.discriminator == discriminator] matching_users = [u for u in client.users if u.name == name and u.discriminator == discriminator]
if len(matching_users) == 0: if len(matching_users) == 0:
await message.channel.send("sorry, I can't find user {}, it looks like they're not in any of the discords I'm in".format(handle), allowed_mentions=discord.AllowedMentions.none()) await message.channel.send("sorry, I can't find user {}, it looks like they're not in any of the discords I'm in".format(handle))
else: else:
target = matching_users[0].id target = matching_users[0].id
if target in get_blocks().get(requester, []): if target in get_blocks().get(requester, []):
await message.channel.send("removing {} from your list of blocked users for pollination".format(handle), allowed_mentions=discord.AllowedMentions.none()) await message.channel.send("removing {} from your list of blocked users for pollination".format(handle))
remove_block(requester, target) remove_block(requester, target)
else: else:
await message.channel.send("adding {} to your list of blocked users for pollination".format(handle), allowed_mentions=discord.AllowedMentions.none()) await message.channel.send("adding {} to your list of blocked users for pollination".format(handle))
add_block(requester, target) add_block(requester, target)
blocks = get_blocks().get(requester, []) blocks = get_blocks().get(requester, [])
if len(blocks) == 0: if len(blocks) == 0:
await message.channel.send("you currently don't have anyone blocked for pollination") await message.channel.send("you currently don't have anyone blocked for pollination")
else: else:
await message.channel.send("your current list of blocked users for pollination is:\n{}".format('\n'.join('@{}#{}'.format(u.name, u.discriminator) for u in [client.get_user(uid) for uid in blocks] if u is not None)), allowed_mentions=discord.AllowedMentions.none()) await message.channel.send("your current list of blocked users for pollination is:\n{}".format('\n'.join('@{}#{}'.format(u.name, u.discriminator) for u in [client.get_user(uid) for uid in blocks] if u is not None)))
await message.channel.send("to block or unblock a user, DM me their handle, like @creep#0000. to see this message and your list of blocked users, DM me something random. buzz buzz!", allowed_mentions=discord.AllowedMentions.none()) await message.channel.send("to block or unblock a user, DM me their handle, like @creep#0000. to see this message and your list of blocked users, DM me something random. buzz buzz!")
@client.event @client.event
async def on_ready(): async def on_ready():