Skip to content

Instantly share code, notes, and snippets.

@Mte90
Last active January 25, 2022 11:27
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 Mte90/9c733fa8bf15eb042c159fec2dcae2d7 to your computer and use it in GitHub Desktop.
Save Mte90/9c733fa8bf15eb042c159fec2dcae2d7 to your computer and use it in GitHub Desktop.
Insultatore del server Discord dei redditor italiani
#!/usr/bin/env python3
from random import random, randint, choice, shuffle
import discord
from discord.ext import tasks
TOKEN = 'pensavichelomettessianchequavero?'
file = open('insulti.txt', 'r')
INSULTS = file.readlines()
file.close()
MSG_COUNTER = randint(8, 20)
TURN_ME_ON = False
MENTIONED = ''
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'{client.user.name} has connected to Discord')
@client.event
async def on_message(message):
global MSG_COUNTER, TURN_ME_ON, MENTIONED
content = message.content.lower()
if message.author == client.user:
return
if TURN_ME_ON:
if MSG_COUNTER == 1:
await message.channel.send(MENTIONED + ', ' + choice(INSULTS))
TURN_ME_ON = False
MENTIONED = ''
MSG_COUNTER = 2
return
else:
MSG_COUNTER -= 1
elif "<@!933767304800518204>" in content:
MSG_COUNTER = randint(8, 20)
await message.channel.send(f"Che voi coso? Aspetta {MSG_COUNTER} messaggi e ti faccio vedere io!")
TURN_ME_ON = True
MENTIONED = message.author.mention
return
elif content == 'insulta' and len(content) == 7:
await message.channel.send(choice(INSULTS))
MSG_COUNTER -= 1
return
elif content.startswith('insulta <@'):
await message.channel.send(content.replace('insulta ', '') + ', ' + choice(INSULTS))
MSG_COUNTER -= 1
return
client.run(TOKEN)
@alombi
Copy link

alombi commented Jan 22, 2022

Dato che il messaggio che il bot invia sul server è @tag, [insulto] , sarebbe forse più corretto che l’insulto inizi con una lettera minuscola, e non maiuscola.
Non posso testare il codice in questo momento, ma la modifica potrebbe essere apportata in questo modo:

msg = choice(INSULTS)
msg = msg[0].lower() + msg[1:]
await message.channel.send(msg)

@Mte90
Copy link
Author

Mte90 commented Jan 22, 2022

Ad oggi i casi sono due:

  • solo insulto
  • insulto con tag

La pate che appende il tag però non pulisce quindi se tipo uno scrive "insulta @tag perchè puzza" la frase sarà "@tag perchè puzza, [insulto]" quindi diciamo che quella parte ha bisogno di essere più sofisticat anche per gestire più di una menzione. Solo che non ho il tempo per farlo quindi per il momento se ne resta così. Non ha anche un sistema per evitare lo spam aggressivo, ovvero che lo chiami più di 3 volte nel giro di un minuto.
@alombi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment