2022-05-30 19:40:10 +02:00
#!/usr/bin/python3
2021-08-07 14:22:30 +02:00
import discord
from discord . ext import commands
2021-08-11 23:01:02 +02:00
from discord . ext . tasks import loop
2021-09-17 16:03:11 +02:00
from discord import HTTPException
2021-08-07 14:22:30 +02:00
from settings import token
2021-09-17 16:03:11 +02:00
import time
2022-05-30 19:40:10 +02:00
import traceback
2021-08-07 14:22:30 +02:00
import datetime
2022-06-12 02:36:45 +02:00
clientI = discord . Client ( )
2021-09-17 16:03:11 +02:00
ignore_list = [ 846756271910158378 ]
2021-08-07 14:22:30 +02:00
#shit api. got switched like 1 year ago so like every single discusison about it is outdated.
def get_suggestion_type ( msg ) :
suggestion_type = " GENERIC "
if msg . startswith ( ' !ze ' ) :
suggestion_type = " ZOMBIE ESCAPE "
msg = msg . replace ( ' !ze ' , ' ' )
elif msg . startswith ( ' !mg ' ) :
suggestion_type = " MINIGAME "
msg = msg . replace ( ' !mg ' , ' ' )
elif msg . startswith ( ' !zr ' ) :
suggestion_type = " ZOMBIE RIOT "
msg = msg . replace ( ' !zr ' , ' ' )
elif msg . startswith ( ' !forum ' ) :
suggestion_type = " FORUM "
msg = msg . replace ( ' !forum ' , ' ' )
elif msg . startswith ( ' !discord ' ) :
suggestion_type = " DISCORD "
msg = msg . replace ( ' !discord ' , ' ' )
elif msg . startswith ( ' !meta ' ) :
suggestion_type = " META "
msg = msg . replace ( ' !meta ' , ' ' )
return suggestion_type , msg . strip ( )
2022-06-12 02:36:45 +02:00
@clientI.event
2021-08-07 14:22:30 +02:00
async def on_message ( message ) :
if message . author . bot :
return
if message . channel . name == ' suggestion-box ' : #suggestion-box
message_content = message . content
2022-06-12 02:36:45 +02:00
global clientI
channel_suggestion_admin = clientI . get_channel ( 872925751295504476 )
2022-05-30 19:40:10 +02:00
#print('message_content: ', message_content)
2021-08-07 14:22:30 +02:00
suggestion_type , message_content = get_suggestion_type ( message_content )
now = datetime . datetime . now ( ) . strftime ( " % Y- % m- %d % H: % M: % S " )
2021-08-11 23:01:02 +02:00
send_msg = f """ ```DISCORD USER ID: { message . author . id } \n USERNAME: { message . author } \n TYPE: { suggestion_type } \n TIME: { now } \n STATUS: No admin interested yet (mark with an emote to prevent suggestion deletion within 48 hours) \n SUGGESTION: { message_content } ``` """
2021-09-17 16:03:11 +02:00
send_channel_msg = f """ { message . author } your suggestion was sent to admins as type: { suggestion_type } . Specify Suggestion types by appending your message with one of the following commands: !ze !zr !mg !forum !discord !meta. \n Spamming the suggestion channel with useless crap will lead to ban. """
2022-05-30 19:40:10 +02:00
print ( ' send_channel_msg: ' , send_channel_msg )
print ( ' send_msg: ' , send_msg )
2021-08-07 14:22:30 +02:00
await message . channel . send ( send_channel_msg )
2022-06-12 02:36:45 +02:00
await channel_suggestion_admin . send ( send_msg )
2021-08-07 14:22:30 +02:00
2022-05-30 19:40:10 +02:00
j = None
2021-08-11 23:01:02 +02:00
@loop ( seconds = 10 )
async def check_suggestions_to_delete ( ) :
2022-05-30 19:40:10 +02:00
global j
2022-06-12 02:36:45 +02:00
global clientI
for channel in clientI . get_all_channels ( ) :
2021-08-11 23:01:02 +02:00
if channel . name == ' suggestion-admin ' :
msgs_history = channel . history ( )
j1 = await msgs_history . flatten ( )
status_msg = " STATUS: No admin interested yet (mark with an emote to prevent suggestion deletion within 48 hours) "
2021-08-12 19:50:13 +02:00
status = ' STATUS: '
suggestion = ' SUGGESTION: '
2022-05-30 19:40:10 +02:00
j = j1
2021-08-11 23:01:02 +02:00
for msg in j1 :
2022-05-30 19:40:10 +02:00
if not msg . author . bot :
continue
#print('msg: ', msg)
2021-08-11 23:01:02 +02:00
if len ( msg . reactions ) == 0 :
created_at = msg . created_at
if created_at < datetime . datetime . now ( ) - datetime . timedelta ( days = 2 ) :
print ( ' deleting message: ' , msg . content )
await msg . delete ( )
2021-08-12 19:50:13 +02:00
else :
first_part = msg . content . split ( status ) [ 0 ]
last_part = msg . content . split ( suggestion ) [ 1 ]
final_msg = f ' { first_part } { status_msg } \n { suggestion } { last_part } '
await msg . edit ( content = final_msg )
elif status in msg . content :
first_part = msg . content . split ( status ) [ 0 ]
last_part = msg . content . split ( suggestion ) [ 1 ]
2021-08-11 23:01:02 +02:00
user_reactions = [ ]
for react in msg . reactions :
2022-05-30 19:40:10 +02:00
#print('react: ', react)
2021-08-11 23:01:02 +02:00
users = react . users ( )
j2 = await users . flatten ( )
for user in j2 :
if user . name not in user_reactions :
user_reactions . append ( user . name )
2021-08-12 19:50:13 +02:00
final_msg = f ' { first_part } STATUS: Admins interested in topic: { user_reactions } \n { suggestion } { last_part } '
2021-09-17 16:03:11 +02:00
try :
await msg . edit ( content = final_msg )
2022-05-30 19:40:10 +02:00
except Exception :
2022-06-12 02:36:45 +02:00
err = traceback . format_exc ( )
print ( " err traceback: " , err )
"""
2021-09-17 16:03:11 +02:00
client = discord . Client ( )
check_suggestions_to_delete . start ( )
client . run ( token )
2022-06-12 02:36:45 +02:00
"""
2021-08-11 23:01:02 +02:00
#the entire syntax that is visisble from python3 terminal is not very well displayed in the docs of discord.py and nobody has the current syntax in any suggestions anywhere on the internet. almost every single thing is out of date reee
if __name__ == ' __main__ ' :
check_suggestions_to_delete . start ( )
2022-06-12 02:36:45 +02:00
clientI . run ( token )