Skip to content
Snippets Groups Projects
Commit e7eb8157 authored by heineke.pb's avatar heineke.pb
Browse files

bots bots

parent 0d61a902
Branches
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ async def help(ctx):
command_info = []
for command in commands_list:
short_description = command.brief or "Keine kurze Beschreibung verfügbar."
command_info.append(f"`{command.name}` - {short_description}")
command_info.append(f"`{command.name}` - {short_description}\n")
await ctx.send(command_info)
......
......@@ -82,24 +82,32 @@ class MedievalGame:
class RPGLoader(commands.Cog):
def __init__(self, bot):
self.bot = bot
def __init__(self, client):
self.client = client
self.game = None
self.channel = None
self.users = []
self.channel_id = 1200993669478621226
self.channel = self.client.get_channel(self.channel_id)
self.users = {}
self.load_usernames()
@commands.command()
@commands.is_owner()
async def aitargetchannel(self, ctx, channelid):
self.channel = channelid
await ctx.send("ChannelID set")
async def aitargetchannel(self, ctx, channelid=None):
if channelid is None:
self.channel = self.client.get_channel(self.channel_id)
else:
self.channel = self.client.get_channel(channelid)
await self.channel.send("ChannelID set")
@commands.command()
async def listgames(self, ctx):
directory_path = "./modules/gameStates/"
try:
# Überprüfe, ob das Verzeichnis existiert
if not os.path.exists():
if not os.path.exists(directory_path):
await self.channel.send(f"Fehler: der Pfad {directory_path} existiert nicht")
# Liste alle Dateien im Verzeichnis auf
files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
......@@ -120,8 +128,10 @@ class RPGLoader(commands.Cog):
@commands.command(aliases=["startgame"])
async def loadgame(self, ctx, gameStateName=None):
try:
self.game = MedievalGame('medievalrpgai')
self.game = MedievalGame('middleagerpg')
self.game.loadGame(gameStateName)
if gameStateName is None:
gameStateName = "new Game"
await ctx.send(f"Loaded {gameStateName}")
except Exception as e:
await self.channel.send("Error ", e)
......@@ -134,27 +144,70 @@ class RPGLoader(commands.Cog):
await self.channel.send(game.chat())
@commands.command()
async def setUsername(self, ctx, username):
async def load_usernames(self):
try:
with open(self.users, 'r') as file0:
file = list(json.load(file0))
self.users = file
with open("players.json", 'r') as file0:
self.users = json.load(file0)
except FileNotFoundError:
# Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren
self.users = {}
#######################################################
@commands.command(brief="Hier kannst du deinen Adventurer Namen anpassen!")
async def setusername(self, ctx, username):
try:
with open("players.json", 'r') as file0:
self.users = json.load(file0)
except FileNotFoundError:
# Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren
self.users = {}
user_name = ctx.author.name
if user_name in self.users:
# Der Benutzer existiert bereits, aktualisiere den Ingame-Namen
self.users[user_name] = username
else:
# Der Benutzer existiert nicht, füge ihn hinzu
self.users[user_name] = username
try:
with open("players.json", 'w') as file0:
json.dump(self.users, file0, indent=1)
await self.channel.send(f"Username {username} gesetzt.")
except Exception as e:
with open(self.users, 'w') as file0:
json.dump(self.users, file0)
with open(self.users, 'r') as file0:
file = list(json.load(file0))
self.gameStateContent = file
await self.channel.send(f"Fehler beim Speichern: {e}")
self.users.append({f'{ctx.author.name}' : f'{username}'})
@commands.command(brief="Habe ich einen Adventurer Namen?")
async def getusername(self, ctx):
try:
with open("players.json", 'r') as file0:
self.users = json.load(file0)
except FileNotFoundError:
# Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren
self.users = {}
user_name = ctx.author.name
if user_name in self.users:
ingame_user = self.users[user_name]
await self.channel.send(f"Dein Abenteurer heißt {ingame_user}")
else:
await self.channel.send("Du hast noch keinen Namen!")
############################################################################
@commands.Cog.listener()
async def on_message(self, message):
if not any(item in message.content for item in ["setUsername","savegame", "loadgame", "aitargetchannel", "listgames", "downloadgame"]):
await self.channel.send(self.game.chat())
@commands.command(aliases=["c"])
async def chat(self, ctx, *, message):
if ctx.author.name in self.users:
ingameuser = self.users[ctx.author.name]
await self.channel.send(self.game.chat(ingameuser, message))
else:
await self.channel.send("No Ingame Name!")
async def setup(client):
......
No preview for this file type
[
{
"role": "system",
"content": "Messages are given to you like this: \"Seraphina : message-conent\". You respond to the Adventurers Inputs after his or her Name. In this example, the Adventurer (Which is the Player) named Seraphina says to you \"Hi\" When you answer the player you dont say \"Here is Seraphinas Inventory\" instead you say \"Here is your inventory\". Because the name in front of the Message content is the players name. The player decided to name the character \"Seraphina\" in this example."
},
{
"role": "user",
"content": "Seraphina: Hi"
},
{
"role": "assistant",
"content": "You nod in greeting as you look over Seraphina's inventory. \"Greetings, Seraphina. What can I help you with today?\""
},
{
"role": "user",
"content": "Seraphina: Inventory"
},
{
"role": "assistant",
"content": "You nod and say, \"Of course! Here is Seraphina's inventory:\n\n* 10 Potions of Healing\n* 5 Scrolls of Protection from Evil and Good\n* 3 Vials of Dragon's Breath (Breath Weapon)\n* A small pouch containing 25 gold pieces\n* A map of the surrounding area with several marked locations of interest\n* A note from a mysterious stranger, inviting Seraphina to a secret location for a unknown purpose\n\nIs there anything specific you would like to know or do?\""
},
{
"role": "user",
"content": "Seraphina: Inventory"
},
{
"role": "assistant",
"content": "You nod and say, \"Of course! Here is Seraphina's inventory:\n\n* 10 Potions of Healing\n* 5 Scrolls of Protection from Evil and Good\n* 3 Vials of Dragon's Breath (Breath Weapon)\n* A small pouch containing 25 gold pieces\n* A map of the surrounding area with several marked locations of interest\n* A note from a mysterious stranger, inviting Seraphina to a secret location for a unknown purpose\n\nIs there anything specific you would like to know or do?\""
}
]
\ No newline at end of file
{
"r4ge_6168": "Ragnar",
"n1ghtw1tch": "Ingvar"
}
\ No newline at end of file
[]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment