Skip to content

Commit

Permalink
implemented giorg send
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMC2610 committed Mar 12, 2022
1 parent 7f124a4 commit 262db74
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 68 deletions.
25 changes: 25 additions & 0 deletions commands/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,31 @@ def __init__(self, ctx, skoil):
self.skoil = skoil


async def send(self, message):
if '{' in message and message[-1] == '}' and '"target"' in message and '"message"' in message:
payload = 0
try:
payload = json.loads(message)
except:
await self.ctx.author.send("Είσαι πολύ ηλίθιος, αν δεν ξέρεις ούτε σωστή **JSON** να γράφεις. 😣")
return

targetID = False
users = await self.skoil.guild.fetch_members().flatten()

try:
targetID = [i.id for i in users if str(i) == payload["target"]].pop()
await self.ctx.author.send("Αμέσως! Στέλνω μήνυμα προς **" + payload["target"] + "**.")
except Exception as e:
print("Unable to decode dictionary.", e.args)
await self.ctx.author.send('**ΚΑΤΙ ΠΑΕΙ ΛΑΘΟΣ.**\n\n Σωστός χειρισμός εντολής:\n```json\n{"message":"<μήνυμα>", "target":"Χρήστης#1234"}```')

if targetID:
user_to_send = self.skoil.client.get_user(targetID)
await user_to_send.send(payload["message"])
await self.ctx.author.send("Έφτασε το μήνυμα!")


async def announce_bot(self, message):

#this command is pm only. Abort if the command is not sent in pm.
Expand Down
83 changes: 15 additions & 68 deletions giorgobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,63 +78,27 @@ async def remove_role(member, role):
await member.remove_roles(role)
channel_log("Successfully removed role " + role.name + " from member " + member.name)

async def private_msg(message, sender):
if '{' in message and message[-1] == '}' and '"target"' in message and '"message"' in message:
payload = 0
try:
payload = json.loads(message.split("!send ")[1])
except:
await sender.send("Είσαι πολύ ηλίθιος, αν δεν ξέρεις ούτε σωστή **JSON** να γράφεις. 😣")
return

targetID = False
@client.event
async def on_ready():
await skoil.initiate()
print('Bot online.')


server = client.get_guild(322050982747963392)
users = await server.fetch_members().flatten()
@client.event
async def on_message(message):

try:
targetID = [i.id for i in users if str(i) == payload["target"]].pop()
await sender.send("Αμέσως! Στέλνω μήνυμα προς **" + payload["target"] + "**.")
except Exception as e:
print("Unable to decode dictionary.", e.args)
await sender.send('**ΚΑΤΙ ΠΑΕΙ ΛΑΘΟΣ.**\n\n Σωστός χειρισμός εντολής:\n```json\n{"message":"<μήνυμα>", "target":"<Χρήστης#1234>"}```')

if targetID:
user_to_send = client.get_user(targetID)
await user_to_send.send(payload["message"])
await sender.send("Έφτασε το μήνυμα!")

async def announce(message, sender):
if '{' in message and message[-1] == '}' and '"channel"' in message and '"message"' in message:
payload = 0
try:
payload = json.loads(message.split("!send ")[1])
except:
await sender.send("Είσαι πολύ ηλίθιος, αν δεν ξέρεις ούτε σωστή **JSON** να γράφεις 🙄")
return
targetID = False
#message log.
channel_log(str(message.author) + " in " + str(message.channel) + " says: " + message.content)

server = client.get_guild(322050982747963392)
channels = await server.fetch_channels()
#never respond to the bot itself.
if message.author == client.user:
return

try:
targetID = [i.id for i in channels if i.name == payload["channel"]].pop()
await sender.send("Εννοείται πως θα το ανακοινώσω στο <#" + str(targetID) + ">")
except Exception as e:
print("Unable to decode dictionary.", e.args)
await sender.send("Δεν το βρήκα αυτό ρε φίλε :(")

if targetID:
channel = client.get_channel(targetID)
await channel.send(payload["message"])
await sender.send('**ΝΑΙ, ΑΛΛΑ ΟΧΙ.**\n\n Σωστός χειρισμός εντολής:\n```json\n{"message":"<μήνυμα>", "channel":"akrives-onoma-kanaliou"}```')
#execute possible commands.
await parse_command(message.content, message)


@client.event
async def on_ready():
await skoil.initiate()
print('Bot online.')

async def parse_command(command : str, ctx):

#in order to call the command, it must have the correct symbol.
Expand All @@ -154,6 +118,7 @@ async def parse_command(command : str, ctx):

#commands for admins only
admin_dict = {
'send' : [str],
'announce' : [str],
'announce_bot' : [str],
'announce_geniki' : [str],
Expand Down Expand Up @@ -227,26 +192,8 @@ async def parse_command(command : str, ctx):
return

await ctx.channel.send("Δεν υπάρχει αυτό που λες, ηλίθιε.")


possible_command_symbols = ['!', '/', 'pm!', 'skoil ']

@client.event
async def on_message(message):

#message log.
channel_log(str(message.author) + " in " + str(message.channel) + " says: " + message.content)

#never respond to the bot itself.
if message.author == client.user:
return

#execute possible commands.
await parse_command(message.content, message)



#Το μέρος, όπου οι χρήστες παίρνουν ρόλο βάσει των reactions τους.
@client.event
async def on_raw_reaction_add(payload):
#αν δεν αντιστοιχεί το μήνυμα του reaction στο συγκεκριμένο reaction Που θέλουμε, τότε δεν μας ενδιαφέρει καθολου
Expand Down

0 comments on commit 262db74

Please sign in to comment.