diff --git a/suggestionsbot/discord_suggestions.py b/suggestionsbot/discord_suggestions.py index 7a048fb0..7a1e99b2 100644 --- a/suggestionsbot/discord_suggestions.py +++ b/suggestionsbot/discord_suggestions.py @@ -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() diff --git a/suggestionsbot/discord_suggestions.service b/suggestionsbot/discord_suggestions.service new file mode 100644 index 00000000..fd612120 --- /dev/null +++ b/suggestionsbot/discord_suggestions.service @@ -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