rewrite wordpress
This commit is contained in:
parent
dbb0abd467
commit
7953b41a07
2 changed files with 53 additions and 84 deletions
|
@ -1,31 +0,0 @@
|
||||||
import disnake
|
|
||||||
from disnake.ext import commands
|
|
||||||
from disnake import TextInputStyle
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
from random import randint
|
|
||||||
import aiosqlite as sqlite3
|
|
||||||
import aiohttp
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
import os
|
|
||||||
|
|
||||||
class usercommands(commands.Cog):
|
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@commands.user_command(
|
|
||||||
name="hello",
|
|
||||||
description="say hi anywhere!",
|
|
||||||
)
|
|
||||||
async def hellousercommand(self, inter: disnake.ApplicationCommandInteraction):
|
|
||||||
await inter.response.send_message("User installable commands everyone!")
|
|
||||||
|
|
||||||
@commands.user_command(
|
|
||||||
name="meonlytest",
|
|
||||||
description="say hi anywhere!",
|
|
||||||
)
|
|
||||||
async def meonlytestcommand(self, inter: disnake.ApplicationCommandInteraction):
|
|
||||||
await inter.response.send_message("User installable commands everyone!")
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
|
||||||
bot.add_cog(usercommands(bot))
|
|
66
wordpress.py
66
wordpress.py
|
@ -1,6 +1,6 @@
|
||||||
import disnake
|
import nextcord
|
||||||
from disnake.ext import commands
|
from nextcord.ext import commands
|
||||||
from disnake import TextInputStyle
|
from nextcord import TextInputStyle
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from random import randint
|
from random import randint
|
||||||
import aiosqlite as sqlite3
|
import aiosqlite as sqlite3
|
||||||
|
@ -11,59 +11,59 @@ import base64
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class ApplicationModal(disnake.ui.Modal):
|
class BlogModal(nextcord.ui.Modal):
|
||||||
def __init__(self,endpoint,credentials):
|
def __init__(self,endpoint,credentials):
|
||||||
self.endpoint = endpoint
|
self.endpoint = endpoint
|
||||||
self.credentials = credentials
|
self.credentials = credentials
|
||||||
components = [
|
super().__init__(
|
||||||
disnake.ui.TextInput(
|
f"create a post"
|
||||||
|
)
|
||||||
|
|
||||||
|
self.name = nextcord.ui.TextInput(
|
||||||
label="Title",
|
label="Title",
|
||||||
placeholder="Why pasta is better than bread",
|
placeholder="Why pasta is better than bread",
|
||||||
custom_id="title",
|
|
||||||
style=TextInputStyle.short,
|
style=TextInputStyle.short,
|
||||||
max_length=100,
|
max_length=100,
|
||||||
),
|
)
|
||||||
disnake.ui.TextInput(
|
self.add_item(self.name)
|
||||||
|
|
||||||
|
self.author = nextcord.ui.TextInput(
|
||||||
label="Author",
|
label="Author",
|
||||||
placeholder="insertapp",
|
placeholder="insertapp",
|
||||||
custom_id="author",
|
|
||||||
style=TextInputStyle.short,
|
style=TextInputStyle.short,
|
||||||
max_length=32,
|
max_length=32,
|
||||||
),
|
)
|
||||||
disnake.ui.TextInput(
|
self.add_item(self.author)
|
||||||
|
self.catergory = nextcord.ui.TextInput(
|
||||||
label="catergory id, if you don't know put 1",
|
label="catergory id, if you don't know put 1",
|
||||||
placeholder="1",
|
placeholder="1",
|
||||||
custom_id="catergory",
|
|
||||||
style=TextInputStyle.short,
|
style=TextInputStyle.short,
|
||||||
max_length=2,
|
max_length=2,
|
||||||
),
|
)
|
||||||
disnake.ui.TextInput(
|
self.add_item(self.catergory)
|
||||||
|
self.content = nextcord.ui.TextInput(
|
||||||
label="content",
|
label="content",
|
||||||
placeholder="words...",
|
placeholder="words...",
|
||||||
custom_id="content",
|
|
||||||
style=TextInputStyle.paragraph,
|
style=TextInputStyle.paragraph,
|
||||||
max_length=4000,
|
max_length=4000,
|
||||||
),
|
)
|
||||||
disnake.ui.TextInput(
|
self.add_item(self.content)
|
||||||
label="content2",
|
self.contenttwo = nextcord.ui.TextInput(
|
||||||
|
label="contenttwo",
|
||||||
placeholder="optional more words...",
|
placeholder="optional more words...",
|
||||||
required = False,
|
required = False,
|
||||||
custom_id="content2",
|
|
||||||
style=TextInputStyle.paragraph,
|
style=TextInputStyle.paragraph,
|
||||||
max_length=4000,
|
max_length=4000,
|
||||||
),
|
)
|
||||||
]
|
self.add_item(self.contenttwo)
|
||||||
super().__init__(title=f"create a post", components=components)
|
|
||||||
|
|
||||||
async def callback(self, inter: disnake.ModalInteraction):
|
async def callback(self, interaction: nextcord.Interaction) -> None:
|
||||||
filledoutresponse = inter.text_values
|
|
||||||
values = list(filledoutresponse.values())
|
|
||||||
token = base64.b64encode(self.credentials.encode())
|
token = base64.b64encode(self.credentials.encode())
|
||||||
dt = datetime.now()
|
dt = datetime.now()
|
||||||
date = dt.isoformat()
|
date = dt.isoformat()
|
||||||
fromatedtitle = f"{values[0]} by {values[1]}"
|
fromatedtitle = f"{self.name.value} by {self.author.value}"
|
||||||
formatedcontent = str(values[3])+" " + str(values[4])
|
formatedcontent = str(self.content.value)+" " + str(self.contenttwo.value)
|
||||||
catergory = int(values[2])
|
catergory = int(self.catergory.value)
|
||||||
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
|
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
|
||||||
post = {
|
post = {
|
||||||
'title' : fromatedtitle,
|
'title' : fromatedtitle,
|
||||||
|
@ -73,19 +73,19 @@ class ApplicationModal(disnake.ui.Modal):
|
||||||
'date' : date
|
'date' : date
|
||||||
}
|
}
|
||||||
responce = requests.post(self.endpoint, headers=header, json=post)
|
responce = requests.post(self.endpoint, headers=header, json=post)
|
||||||
await inter.response.send_message("<@666378959184855042> someone posted to the blog, you should probably approve it")
|
await interaction.response.send_message(f"<@666378959184855042> someone posted to the blog, you should probably approve it {responce.status_code}")
|
||||||
|
|
||||||
|
|
||||||
class wordpress(commands.Cog):
|
class wordpress(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.slash_command(
|
@nextcord.slash_command(
|
||||||
name="blog",
|
name="blog",
|
||||||
description="create a blog post",
|
description="create a blog post",
|
||||||
)
|
)
|
||||||
async def blog(self, inter: disnake.ApplicationCommandInteraction):
|
async def blog(self, interaction: nextcord.Interaction):
|
||||||
await inter.response.send_modal(modal=ApplicationModal("https://pastablog.insertapp.net/wp-json/wp/v2/posts",self.bot.blogcredentials))
|
await interaction.response.send_modal(BlogModal("https://pastablog.insertapp.net/wp-json/wp/v2/posts",self.bot.blogcredentials))
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
bot.add_cog(wordpress(bot))
|
bot.add_cog(wordpress(bot))
|
Loading…
Reference in a new issue