-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.py
134 lines (98 loc) · 3.33 KB
/
worker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# controls blog management for aswinnnn.github.io
# created by Aswin S. | 24/07/2022
import subprocess
import discord
from discord.ext import commands
from pathlib import Path
from json import loads
config = []
def load_config():
with open("config.json", "r") as f:
conf = loads(f.read())
config.append(conf)
return
try:
load_config()
if config[0]["github-username"] == "the x in your x.github.io" or config[0]["discord-bot-token"] == "your discord bot token":
print("\033[93m WARNING: Please take time to figure out your config.json\n Its in the README.md\033[0m")
exit()
except:
print("\033[93m WARNING: You Haven't set up the config.json correctly!!! \033[0m\n")
exit()
config = config[0]
def create_blog(datetime: str, title: str, data: str) -> None:
"""
```
create_blog("12 June 2023", "my testy tests", "so this is the most awesome test ever.")
```
"""
base = Path(r"blog\base.html")
with open(base, "r") as f:
blog = f.read()
blog = blog.replace("##DATETIME##", datetime)
blog = blog.replace("##TITLE##", title)
blog = blog.replace("##DATA##", data)
try:
with open(Path(rf"blog\{title}.html"), "x") as nf:
nf.write(blog)
except FileExistsError:
with open(Path(rf"blog\{title}.html"), "r+") as nf:
nf.write(blog)
def update_blog() -> None:
subprocess.call("git add .")
subprocess.call('git commit -am "new blog"')
subprocess.call("git push origin main")
def url(url: str) -> str:
url = url.strip()
url = url.split(" ")
url = "%20".join(url)
return url
def pretitle(tit: str) -> str:
tit = tit.strip()
tit = tit.split(" ")
tit = " ".join(tit)
return tit
TOKEN = config["discord-bot-token"]
# The only intent the bot needs (that has to be enabled) is "message content".
# This is just easy but if you do not wish to enable
# all intents of your discord bot, change the intents to only message content.
intents = discord.Intents.all()
bot = commands.Bot(command_prefix=",", description="blog bot",intents=intents, case_insensitive=True)
@bot.event
async def on_ready():
print(f"logged in as {bot.user}")
print("———————————")
print("connected!")
print("———————————")
print("do ,help in chat to see all the commands")
blog = {}
@bot.command()
async def title(ctx, *,title: str):
blog["title"] = pretitle(title)
await ctx.send(f"{blog}")
@bot.command()
async def post(ctx):
await ctx.send(f"{blog}")
@bot.command()
async def content(ctx, *,content: str):
blog["content"] = content.replace("\n","<br>")
await ctx.send(f"{blog}")
@bot.command()
async def clear(ctx):
kills = []
for k, v in blog.items():
kills.append(k)
for k in kills:
blog.pop(k)
await ctx.send("blog cleared.")
@bot.command()
async def date(ctx,*, date: str):
blog["date"] = date
await ctx.send(f"{blog}")
@bot.command()
async def upload(ctx):
msg = await ctx.send("uploading...")
create_blog(datetime=blog["date"], title=blog["title"], data=blog["content"])
update_blog()
await msg.edit(content=f'new blog added -> https://{config["your-github-username"]}.github.io/blog/{url(blog["title"])}.html')
bot.run(TOKEN)