better subject on message + randome framadate vote

This commit is contained in:
Adrian 2024-11-12 23:09:18 +01:00
parent ad8b0a5e87
commit b353300e61

17
main.py
View File

@ -4,6 +4,7 @@ import yaml
import requests import requests
from datetime import date from datetime import date
import urllib.parse import urllib.parse
from random import shuffle
# To send discord messages (fucking async functions…) # To send discord messages (fucking async functions…)
import asyncio import asyncio
@ -46,7 +47,8 @@ def send_mail(guild, to, subject, content):
server.send_message(msg) server.send_message(msg)
def mail_message(message): def mail_message(message):
send_mass_mail(guilds[message.guild.id], f'[Mutubot] Nouveau message discord de {message.author.display_name}', f'{message.author.display_name}:\n{message.content}') # TODO add … if message is not complete on the subject
send_mass_mail(guilds[message.guild.id], f'[Mutubot] Message discord de {message.author.display_name} : {message.content:.50}', f'{message.author.display_name}:\n{message.content}')
def req(url, data): def req(url, data):
x = requests.post(url, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=data) x = requests.post(url, headers={'Content-Type': 'application/x-www-form-urlencoded'}, data=data)
@ -108,9 +110,12 @@ def create_framavote (guild, names):
# Update control sum # Update control sum
finder = scrap_framavote(guild['framavote']) finder = scrap_framavote(guild['framavote'])
# Random order
shuffle(guild['members'])
# Add lines # Add lines
for i in range(len(guild['members'])): for i in range(len(guild['members'])):
create_line_framadate(finder.token, guild['framavote'], 'AnneONyme'+str(i), names) create_line_framadate(finder.token, guild['framavote'], 'Anne ONyme'+str(i), names)
# Update links # Update links
finder = scrap_framavote(guild['framavote']) finder = scrap_framavote(guild['framavote'])
@ -118,11 +123,11 @@ def create_framavote (guild, names):
# Send links # Send links
for mail,link in zip(guild['members'], finder.public_links): for mail,link in zip(guild['members'], finder.public_links):
content = f""" content = f"""
Ce mail remplace tous les précédents ! Ce mail remplace tous les précédents sil y en a !
Voici votre lien de vote anonyme : Vous avez été convié à un vote anonyme. Voici le lien voter :
{link} {link}
""" """
send_mail(guild, mail, '[Mutubot] Votre lien de vote anonyme', content) send_mail(guild, mail, '[Mutubot] Vous êtes convié à un vote anonyme', content)
return finder.public_link return finder.public_link
@ -195,7 +200,7 @@ async def on_message(message):
if message.guild.id not in guilds: if message.guild.id not in guilds:
return return
if message.content.startswith('!randomvote '): if message.content.startswith('!randomvote '):
await message.reply('Cela va détruire le framavote actuel. Êtes vous sûr·e ? Répondez « Pamplemousse agrivoltaiste » pour confirmer') await message.reply('Créer un vote anonyme va détruire le framavote actuel. Êtes vous sûr·e ? Répondez « Pamplemousse agrivoltaiste » pour confirmer')
randomvote = message.content.split(' ')[1:] randomvote = message.content.split(' ')[1:]
return return
elif message.content == 'Pamplemousse agrivoltaiste' and message.type == discord.MessageType.reply : elif message.content == 'Pamplemousse agrivoltaiste' and message.type == discord.MessageType.reply :