Browse Source

libpq-dev hint @ README, .gitinore PyCharm, copy instead of move example file with missing settings, bugfixes for \!8ball & \!dice

root 3 years ago
parent
commit
98ade06aa3
5 changed files with 39 additions and 17 deletions
  1. 5 1
      .gitignore
  2. 3 2
      README.md
  3. 27 11
      bot/commands/games.py
  4. 2 2
      bot/local_settings_example.py
  5. 2 1
      bot/main.py

+ 5 - 1
.gitignore

@@ -13,4 +13,8 @@ db.sqlite3
 **/migrations/*.py
 
 # Configuration
-local_settings.py
+local_settings.py
+
+
+# PyCharm IDE
+.idea

+ 3 - 2
README.md

@@ -3,14 +3,15 @@ A Discord robot for the Angels Discord written in Python.
 
 ## Requirements
 * Python3
-* PostgreSQL
+* PostgreSQL (libpq-dev) 
 * Web server gateway interface like uWSGI or Gunicorn
+* A discord token
 
 ## Installation
 1. Clone the git repository: `git clone ` ...
 1. Change into the repo directory: `cd ` ...
 1. Create virtual environment: `python3 -m venv .`
-1. Activate virutal environment: `source bin/activate`
+1. Activate virtual environment: `source bin/activate`
 1. Install required packages: `pip3 install -r requirements.txt`
 
 ### Web interface

+ 27 - 11
bot/commands/games.py

@@ -19,19 +19,20 @@ class Games(commands.Cog):
 		help="Roll two dice."
 	)
 	async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
-		if amount and amount < 1:
-			await ctx.send("You want me to roll less as one die? How!?")
-		elif amount and amount > 25:
+		if not amount:
+			amount = 2
+		if not sides:
+			sides = 6
+
+		if amount < 1:
+			await ctx.send("You want me to roll less than one die? How!?")
+		elif amount > 25:
 			await ctx.send("I can not hold so many dice at one time.")
-		elif sides and sides < 2:
+		elif sides < 2:
 			await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
+		elif sides > 256:
+			await ctx.send("My tiny hands can not handle such large dice. Even if both are virtual.")
 		else:
-			if sides:
-				sides = sides
-			else:
-				sides = 6
-			if not amount:
-				amount = 2
 			embed = discord.Embed(title = "Dice roll", description=f"Rolling {amount} dice, with {sides} sides.")
 			while amount > 0:
 				embed.insert_field_at(0, name=f"Die {amount}", value=random.randint(1, sides), inline=True)
@@ -55,6 +56,21 @@ class Games(commands.Cog):
 				"Ask a question you tease!",
 				"You will die alone.",
 			]
+		elif question.strip().count(" ") == 0:
+			messages = [
+				"What?",
+				"That is not a question",
+				"Can you use more than one word?",
+				"What is the question?",
+				"Sorry?"
+			]
+		elif question.strip()[-1] != "?":
+			messages = [
+				"Did you forget to end with a question mark?",
+				"Is that a statement or question?",
+				"Don't questions usually end with a question mark?",
+				"Don't forget to use punctuation."
+			]
 		else:
 			messages = [
 				"Yes.",
@@ -79,6 +95,6 @@ class Games(commands.Cog):
 				"Ask again later.",
 				"I don't know.",
 				"Unpredictable.",
-				"Unkown",
+				"Unknown",
 			]
 		await ctx.send(random.choice(messages))

+ 2 - 2
bot/local_settings_example.py

@@ -5,11 +5,11 @@ LOG_LEVEL = logging.INFO	# Options: CRITICAL, ERROR, WARNING, INFO, and DEBUG
 
 DATABASE_NAME = ""
 DATABASE_USER = ""
-DATABASE_HOST = "127.0.0.1"
+DATABASE_HOST = ""
 DATABASE_PASSWORD = ""
 
 WEB_HOST = ""
 WEB_SCHEME = "https"
 
 DISCORD_TOKEN = ""
-COMMAND_PREFIX = ""
+COMMAND_PREFIX = "!"

+ 2 - 1
bot/main.py

@@ -16,7 +16,8 @@ def missing_config():
 		logging.error("Settings file not found.")
 		logging.info("Copying local_settings_example.py to local_settings.py")
 		try:
-			os.rename("local_settings_example.py", "local_settings.py")
+			os.system("cp local_settings_example.py local_settings.py")
+			#os.rename("local_settings_example.py", "local_settings.py")
 		except FileNotFoundError:
 			logging.info("local_settings_example.py not found, creating local_settings.py")
 			with open("local_settings.py", "w") as settings_file: