Skip to content

Commit

Permalink
Adds hostname support for the notes cog
Browse files Browse the repository at this point in the history
  • Loading branch information
Crossedfall committed May 25, 2019
1 parent 4974a0a commit 3ad9f1c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions getnotes/getnotes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Standard Imports
import asyncio
import mysql.connector
import socket
import ipaddress
from typing import Union

Expand Down Expand Up @@ -47,11 +48,10 @@ async def host(self, ctx, db_host: str):
Sets the MySQL host, defaults to localhost (127.0.0.1)
"""
try:
ipaddress.ip_address(db_host) # Confirms that the IP provided is valid. If the IP is not valid, a ValueError is thrown.
await self.config.guild(ctx.guild).mysql_host.set(db_host)
await ctx.send(f"Database host set to: {db_host}")
except(ValueError):
await ctx.send(f"{db_host} is not a valid ip address!")
except (ValueError, KeyError, AttributeError):
await ctx.send("There was an error setting the database's ip/hostname. Please check your entry and try again!")

@setnotes.command()
@checks.is_owner()
Expand Down Expand Up @@ -262,7 +262,7 @@ async def findplayer(self, ctx, *,player: Union[ipaddress.IPv4Address, int, str]
async def query_database(self, ctx, query: str):
# Database options loaded from the config
db = await self.config.guild(ctx.guild).mysql_db()
db_host = await self.config.guild(ctx.guild).mysql_host()
db_host = socket.gethostbyname(await self.config.guild(ctx.guild).mysql_host())
db_port = await self.config.guild(ctx.guild).mysql_port()
db_user = await self.config.guild(ctx.guild).mysql_user()
db_pass = await self.config.guild(ctx.guild).mysql_password()
Expand Down

0 comments on commit 3ad9f1c

Please sign in to comment.