Compare commits
	
		
			4 commits
		
	
	
		
			70867e0d7e
			...
			8f74565abd
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 8f74565abd | |||
| 7c89395f70 | |||
| beeb76b2ed | |||
| ab633d50d3 | 
					 8 changed files with 55 additions and 14 deletions
				
			
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -1 +1,2 @@
 | 
			
		|||
config.json
 | 
			
		||||
/config.json
 | 
			
		||||
/data/
 | 
			
		||||
							
								
								
									
										28
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
# Hrochobot
 | 
			
		||||
Discord bot for KSP discord server.
 | 
			
		||||
 | 
			
		||||
## Installation
 | 
			
		||||
First install all required libraries:
 | 
			
		||||
```sh
 | 
			
		||||
pip install -r requirements.txt
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Then create ``data`` folder from ``data.example``:
 | 
			
		||||
```sh
 | 
			
		||||
cp data.example data -r
 | 
			
		||||
```
 | 
			
		||||
Same for ``config.json``:
 | 
			
		||||
```sh
 | 
			
		||||
cp config.example.json config.json -r
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Lastly paste your discord bot token into ``config.json``.
 | 
			
		||||
If you do not have any discord bot, learn how to create one here:
 | 
			
		||||
https://discordjs.guide/preparations/setting-up-a-bot-application.html#your-bot-s-token
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Running
 | 
			
		||||
To run the bot simply execute ``main.py``:
 | 
			
		||||
```sh
 | 
			
		||||
./main.py
 | 
			
		||||
```
 | 
			
		||||
| 
						 | 
				
			
			@ -5,11 +5,11 @@ class Basic(commands.Cog):
 | 
			
		|||
    def __init__(self, bot):
 | 
			
		||||
        self.bot = bot
 | 
			
		||||
 | 
			
		||||
    @discord.slash_command()
 | 
			
		||||
    @discord.slash_command(description="Greets the world.")
 | 
			
		||||
    async def sayhello(self, ctx):
 | 
			
		||||
        await ctx.respond('Hello world!')
 | 
			
		||||
 | 
			
		||||
    @discord.slash_command()
 | 
			
		||||
    @discord.slash_command(description="Sends the bot's latency.")
 | 
			
		||||
    async def ping(self, ctx):
 | 
			
		||||
        await ctx.respond('My ping is {:.0f}ms'.format(self.bot.latency*1000), ephemeral=True)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,8 +6,8 @@ class Ksp(commands.Cog):
 | 
			
		|||
    def __init__(self, bot):
 | 
			
		||||
        self.bot = bot
 | 
			
		||||
 | 
			
		||||
    @discord.slash_command()
 | 
			
		||||
    async def task(self, ctx, task_code):
 | 
			
		||||
    @discord.slash_command(description="Generates urls for given task.")
 | 
			
		||||
    async def task(self, ctx, task_code: str):
 | 
			
		||||
        await ctx.respond(
 | 
			
		||||
            f'**{task_code}**\n'
 | 
			
		||||
            f'Task: {task_link(task_code, solution=False)}\n'
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +15,7 @@ class Ksp(commands.Cog):
 | 
			
		|||
            ephemeral=True
 | 
			
		||||
        )
 | 
			
		||||
    
 | 
			
		||||
    @discord.slash_command()
 | 
			
		||||
    @discord.slash_command(description="Shows deadlines of currently running series.")
 | 
			
		||||
    async def deadlines(self, ctx):
 | 
			
		||||
        a_deadlines = active_deadlines()
 | 
			
		||||
        if len(a_deadlines) == 0:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,11 +11,14 @@ class Roles(commands.Cog):
 | 
			
		|||
 | 
			
		||||
    secret_roles = discord.SlashCommandGroup(
 | 
			
		||||
        "secretroles",
 | 
			
		||||
        "Commands for management of secret roles.",
 | 
			
		||||
        checks=[commands.has_permissions(manage_roles=True)]
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    @secret_roles.command()
 | 
			
		||||
    async def add(self, ctx, role: discord.role.Role, password: str):
 | 
			
		||||
    @secret_roles.command(description="Adds a new secret role.")
 | 
			
		||||
    @discord.option("role", discord.role.Role, description="Role locked behind a password.")
 | 
			
		||||
    @discord.option("password", str, description="Password for given role.")
 | 
			
		||||
    async def add(self, ctx, role, password):
 | 
			
		||||
        roles = data.load_data(ROLES_JSON)
 | 
			
		||||
        if password in roles["secret_roles"]:
 | 
			
		||||
            return await ctx.respond(f"Password ``{password}`` is already used.", ephemeral=True)
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +27,7 @@ class Roles(commands.Cog):
 | 
			
		|||
        data.dump_data(ROLES_JSON, roles)
 | 
			
		||||
        return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
 | 
			
		||||
    
 | 
			
		||||
    @secret_roles.command()
 | 
			
		||||
    @secret_roles.command(description="Lists all passwords and their secret roles")
 | 
			
		||||
    async def list(self, ctx):
 | 
			
		||||
        roles = data.load_data(ROLES_JSON)
 | 
			
		||||
        if len(roles["secret_roles"]) == 0:
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +38,9 @@ class Roles(commands.Cog):
 | 
			
		|||
            msg += f"``{passwd}``: {role.mention}\n"
 | 
			
		||||
        return await ctx.respond(msg, ephemeral=True)
 | 
			
		||||
    
 | 
			
		||||
    @secret_roles.command()
 | 
			
		||||
    async def delete(self, ctx, password: str):
 | 
			
		||||
    @secret_roles.command(description="Deletes given password and its secret role.")
 | 
			
		||||
    @discord.option("password", str, description="Password to be deleted.")
 | 
			
		||||
    async def delete(self, ctx, password):
 | 
			
		||||
        roles = data.load_data(ROLES_JSON)
 | 
			
		||||
        if password not in roles["secret_roles"]:
 | 
			
		||||
            return await ctx.respond(f"Role with passowrd {password} does not exist.", ephemeral=True)
 | 
			
		||||
| 
						 | 
				
			
			@ -49,9 +53,9 @@ class Roles(commands.Cog):
 | 
			
		|||
            ephemeral=True
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @discord.slash_command()
 | 
			
		||||
    async def secretrole(self, ctx, password: str):
 | 
			
		||||
    @discord.slash_command(description="Gives a secret role locked by a password.")
 | 
			
		||||
    @discord.option("password", str, description="Password for secret role.")
 | 
			
		||||
    async def secretrole(self, ctx, password):
 | 
			
		||||
        roles = data.load_data(ROLES_JSON)
 | 
			
		||||
        if password in roles["secret_roles"]:
 | 
			
		||||
            author = ctx.author
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										3
									
								
								config.example.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								config.example.json
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
{
 | 
			
		||||
    "token": "Paste your token here."
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								data.example/roles.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								data.example/roles.json
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
{
 | 
			
		||||
    "secret_roles": {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
py-cord
 | 
			
		||||
requests
 | 
			
		||||
		Loading…
	
		Reference in a new issue