diff --git a/sticker/lib/matrix.py b/sticker/lib/matrix.py index e506e83..03e00ac 100644 --- a/sticker/lib/matrix.py +++ b/sticker/lib/matrix.py @@ -55,10 +55,12 @@ async def load_config(path: str) -> None: config = json.load(config_file) homeserver_url = config["homeserver"] access_token = config["access_token"] + giphy_api_key = config["giphy_api_key"] except FileNotFoundError: - print("Matrix config file not found. Please enter your homeserver and access token.") + print("Matrix config file not found. Please enter your homeserver and access token. Enter the Giphy API token if required, leave blank to disable the gif picker.") homeserver_url = input("Homeserver URL: ") access_token = input("Access token: ") + giphy_api_key = input("Giphy API key: ") whoami_url = URL(homeserver_url) / "_matrix" / "client" / "r0" / "account" / "whoami" if whoami_url.scheme not in ("https", "http"): whoami_url = whoami_url.with_scheme("https") @@ -67,7 +69,8 @@ async def load_config(path: str) -> None: json.dump({ "homeserver": homeserver_url, "user_id": user_id, - "access_token": access_token + "access_token": access_token, + "giphy_api_key": giphy_api_key }, config_file) print(f"Wrote config to {path}") diff --git a/web/src/index.js b/web/src/index.js index be7b3df..2b594a5 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -31,6 +31,7 @@ if (params.has('config')) { } // This is updated from packs/index.json let HOMESERVER_URL = "https://matrix-client.matrix.org" +let GIPHY_API_KEY = "" const makeThumbnailURL = mxc => `${HOMESERVER_URL}/_matrix/media/r0/thumbnail/${mxc.substr(6)}?height=128&width=128&method=scale` @@ -66,7 +67,8 @@ class GiphySearchTab extends Component { async searchGifs() { this.setState({ loading: true }); try { - const apiKey = "Gc7131jiJuvI7IdN0HZ1D7nh0ow5BU6g"; + // const apiKey = "Gc7131jiJuvI7IdN0HZ1D7nh0ow5BU6g"; + const apiKey = GIPHY_API_KEY; const url = `https://api.giphy.com/v1/gifs/search?q=${this.state.searchTerm}&api_key=${apiKey}`; this.setState({ loading: true }); const response = await fetch(url); @@ -131,7 +133,7 @@ class GiphySearchTab extends Component {