mirror of
https://github.com/stijndcl/didier.git
synced 2026-04-07 15:48:29 +02:00
Merge pull request #72 from stijndcl/flask-backend
Create basics for backend server, + small fixes
This commit is contained in:
commit
a310d1696c
23 changed files with 357 additions and 97 deletions
|
|
@ -5,6 +5,7 @@ from discord.ext import commands
|
|||
from functions import checks, easterEggResponses
|
||||
from functions.database import stats, muttn, custom_commands, commands as command_stats
|
||||
import pytz
|
||||
from settings import READY_MESSAGE, SANDBOX, STATUS_MESSAGE
|
||||
import time
|
||||
import traceback
|
||||
|
||||
|
|
@ -30,20 +31,13 @@ class Events(commands.Cog):
|
|||
"""
|
||||
Function called when the bot is ready & done leading.
|
||||
"""
|
||||
# Change status
|
||||
with open("files/status.txt", "r") as statusFile:
|
||||
status = statusFile.readline()
|
||||
# Set status
|
||||
await self.client.change_presence(status=discord.Status.online, activity=discord.Game(STATUS_MESSAGE))
|
||||
|
||||
await self.client.change_presence(status=discord.Status.online, activity=discord.Game(str(status)))
|
||||
|
||||
# Print a message in the terminal to show that he's ready
|
||||
with open("files/readyMessage.txt", "r") as readyFile:
|
||||
readyMessage = readyFile.readline()
|
||||
|
||||
print(readyMessage)
|
||||
print(READY_MESSAGE)
|
||||
|
||||
# Add constants to the client as a botvar
|
||||
self.client.constants = constants.Live if "zandbak" not in readyMessage else constants.Zandbak
|
||||
self.client.constants = constants.Live if SANDBOX else constants.Zandbak
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message):
|
||||
|
|
|
|||
26
cogs/ipc.py
Normal file
26
cogs/ipc.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from discord.ext import commands, ipc
|
||||
|
||||
|
||||
class IPC(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@ipc.server.route()
|
||||
async def send_dm(self, data):
|
||||
print("got here")
|
||||
user = self.client.get_user(data.user)
|
||||
await user.send(data.message)
|
||||
print("sent")
|
||||
return True
|
||||
|
||||
@ipc.server.route()
|
||||
async def get_bot_latency(self, data):
|
||||
"""
|
||||
Get Didier's latency
|
||||
"""
|
||||
|
||||
return self.client.latency * 1000
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(IPC(client))
|
||||
|
|
@ -246,7 +246,7 @@ class Tasks(commands.Cog):
|
|||
Task that checks for new Ufora announcements every few minutes
|
||||
"""
|
||||
# Don't run this when testing
|
||||
if self.client.user.id == int(constants.coolerDidierId):
|
||||
if self.client.user.id != int(constants.didierId):
|
||||
return
|
||||
|
||||
# Get new notifications
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class Translate(commands.Cog):
|
|||
def cog_check(self, ctx):
|
||||
return not self.client.locked
|
||||
|
||||
# @commands.command(name="Translate", aliases=["Tl", "Trans"], usage="[Tekst] [Van]* [Naar]*")
|
||||
# @help.Category(Category.Words)
|
||||
@commands.command(name="Translate", aliases=["Tl", "Trans"], usage="[Tekst] [Van]* [Naar]*")
|
||||
@help.Category(Category.Words)
|
||||
async def translate(self, ctx, query=None, to="nl", fr="auto"):
|
||||
if query is None:
|
||||
return await ctx.send("Controleer je argumenten.")
|
||||
|
|
@ -39,9 +39,11 @@ class Translate(commands.Cog):
|
|||
embed.set_author(name="Didier Translate")
|
||||
|
||||
if fr == "auto":
|
||||
language = translation.extra_data["original-language"]
|
||||
language = translation.src
|
||||
embed.add_field(name="Gedetecteerde taal", value=tc(LANGUAGES[language]))
|
||||
embed.add_field(name="Zekerheid", value="{}%".format(translation.extra_data["confidence"] * 100))
|
||||
|
||||
if translation.extra_data["confidence"] is not None:
|
||||
embed.add_field(name="Zekerheid", value="{}%".format(translation.extra_data["confidence"] * 100))
|
||||
|
||||
embed.add_field(name="Origineel ({})".format(translation.src.upper()), value=query, inline=False)
|
||||
embed.add_field(name="Vertaling ({})".format(to.upper()), value=translation.text)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue