-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (56 loc) · 2.31 KB
/
Copy pathmain.py
File metadata and controls
69 lines (56 loc) · 2.31 KB
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
# This example requires the 'message_content' intent.
import uuid
import json
import discord
import requests
import os
from discord.ext import commands
baseUrlCurseForge = "https://api.curseforge.com"
config_json = "config.json"
headers = {
"Accept": "application/json",
"x-api-key": "$2a$10$JV09XCjRXdYEcz1gCuWTk.QZOEjDlCluyZdRe4fOgJXydPQlRnMiO",
}
if not os.path.exists(config_json):
with open(config_json, "w", encoding="utf-8") as f:
json.dump({"modlist": [], "patch": f"{uuid.uuid1()}"}, f, indent=4)
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.command()
async def list(ctx):
with open(config_json, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
liststring = "Mods List :\n"
for mod in data["modlist"]:
liststring += "mod:" + mod["modid"] + " version:" + mod["version"] + "\n"
await ctx.send(liststring)
@bot.command()
async def addmod(ctx, arg1, arg2):
# r = requests.get(baseUrlCurseForge + "/v1/mods/{arg}", headers=headers)
with open(config_json, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
for i in data["modlist"]:
if arg1 == i["modid"]:
await ctx.send("existe deja")
return
data["patch"] = f"{uuid.uuid1()}"
data["modlist"].append({"modid": arg1, "version": arg2})
with open(config_json, "w", encoding="utf-8") as json_file:
json.dump(data, json_file, indent=4)
await ctx.send(arg1 + " ajoute !")
@bot.command()
async def deletemod(ctx, arg1):
# r = requests.get(baseUrlCurseForge + "/v1/mods/{arg}", headers=headers)
with open(config_json, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
for index, i in enumerate(data["modlist"]):
if arg1 == i["modid"]:
data["patch"] = f"{uuid.uuid1()}"
data["modlist"].pop(index)
with open(config_json, "w", encoding="utf-8") as json_file:
json.dump(data, json_file, indent=4)
await ctx.send(arg1 + " suppime !")
return
await ctx.send("deja supprimer/ ou inexistant")
bot.run("MTQ2OTcxOTM5MTk1MTI2MTg0Nw.Gx5RYt.T3bcRGzcQ83xRkfiMS0BcCDewRNRjJiJPyvcVg")