slight print update and added new systemctl service instead of using timer

This commit is contained in:
jenz 2022-05-30 19:40:10 +02:00
parent f7a399cb27
commit 153f1c28ce
2 changed files with 26 additions and 5 deletions

View File

@ -1,9 +1,12 @@
#!/usr/bin/python3
import discord
from discord.ext import commands
from discord.ext.tasks import loop
from discord import HTTPException
from settings import token
import time
import traceback
import datetime
client = discord.Client()
@ -36,22 +39,23 @@ def get_suggestion_type(msg):
async def on_message(message):
if message.author.bot:
return
if message.author.id in ignore_list:
msg = f'{message.author.name} Your suggestion was ignored because you made too many shitty suggestions already. Do not post in this channel anymore because your retarded.'
await message.channel.send()
return
if message.channel.name == 'suggestion-box': #suggestion-box
channel = client.get_channel(872925751295504476) #872925751295504476
message_content = message.content
#print('message_content: ', message_content)
suggestion_type, message_content = get_suggestion_type(message_content)
now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
send_msg = f"""```DISCORD USER ID: {message.author.id}\nUSERNAME: {message.author}\nTYPE: {suggestion_type}\nTIME: {now}\nSTATUS: No admin interested yet (mark with an emote to prevent suggestion deletion within 48 hours)\nSUGGESTION: {message_content}```"""
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. \nSpamming the suggestion channel with useless crap will lead to ban."""
print('send_channel_msg: ', send_channel_msg)
print('send_msg: ', send_msg)
await message.channel.send(send_channel_msg)
await channel.send(send_msg)
j = None
@loop(seconds = 10)
async def check_suggestions_to_delete():
global j
global client
for channel in client.get_all_channels():
if channel.name == 'suggestion-admin':
@ -60,7 +64,11 @@ async def check_suggestions_to_delete():
status_msg = "STATUS: No admin interested yet (mark with an emote to prevent suggestion deletion within 48 hours)"
status = 'STATUS:'
suggestion = 'SUGGESTION:'
j = j1
for msg in j1:
if not msg.author.bot:
continue
#print('msg: ', msg)
if len(msg.reactions) == 0:
created_at = msg.created_at
if created_at < datetime.datetime.now()-datetime.timedelta(days=2):
@ -76,6 +84,7 @@ async def check_suggestions_to_delete():
last_part = msg.content.split(suggestion)[1]
user_reactions = []
for react in msg.reactions:
#print('react: ', react)
users = react.users()
j2 = await users.flatten()
for user in j2:
@ -84,7 +93,8 @@ async def check_suggestions_to_delete():
final_msg = f'{first_part}STATUS: Admins interested in topic:{user_reactions}\n{suggestion}{last_part}'
try:
await msg.edit(content=final_msg)
except HTTPException:
except Exception:
traceback.print_exc()
time.sleep(300)
client = discord.Client()
check_suggestions_to_delete.start()

View File

@ -0,0 +1,11 @@
[Unit]
Description=runs discord suggestions
[Service]
Type=simple
User=nonroot
Restart=always
RuntimeMaxSec=432000
Environment=PYTHONUNBUFFERED=1
WorkingDirectory=/home/nonroot/discord_suggestions
ExecStart=/home/nonroot/discord_suggestions/discord_suggestions.py