commit 5dd0b410e9f6558b839edee20b5823f1fa064670 Author: Patrick Ulrich Date: Wed Jan 29 10:37:42 2025 -0500 Initial Deployment diff --git a/GoodMorningBitcoin.cs b/GoodMorningBitcoin.cs new file mode 100644 index 0000000..544aada --- /dev/null +++ b/GoodMorningBitcoin.cs @@ -0,0 +1,87 @@ +using Oxide.Core.Libraries.Covalence; +using Oxide.Core; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace Oxide.Plugins +{ + [Info("GoodMorningBitcoin", "RustySats", "0.1.0")] + [Description("Plugin to display 'now playing' information from Good Morning Bitcoin radio.")] + public class GoodMorningBitcoin : CovalencePlugin + { + private string apiEndpoint; + private string cachedNowPlaying; + private DateTime cacheExpiry = DateTime.MinValue; + + private void Init() + { + // Load the API endpoint from the plugin configuration + apiEndpoint = Config["ApiEndpoint"]?.ToString() ?? "https://radio.goodmorningbitcoin.com/api/nowplaying"; + } + + protected override void LoadDefaultConfig() + { + Config["ApiEndpoint"] = "https://radio.goodmorningbitcoin.com/api/nowplaying"; + SaveConfig(); + } + + [Command("goodmorningbitcoin")] + private void GoodMorningBitcoinCommand(IPlayer player, string command, string[] args) + { + if (DateTime.UtcNow < cacheExpiry && !string.IsNullOrEmpty(cachedNowPlaying)) + { + player.Reply($"Now Playing: {cachedNowPlaying}"); + return; + } + + webrequest.EnqueueGet(apiEndpoint, (code, response) => + { + if (code != 200 || string.IsNullOrEmpty(response)) + { + player.Reply("Unable to retrieve now playing information at the moment. Please try again later."); + return; + } + + try + { + // Deserialize the JSON response as a list + var parsedData = JsonConvert.DeserializeObject>(response); + var nowPlaying = parsedData?[0]?.NowPlaying?.Song?.Text; // Access the first element in the array + + if (!string.IsNullOrEmpty(nowPlaying)) + { + cachedNowPlaying = nowPlaying; + cacheExpiry = DateTime.UtcNow.AddSeconds(30); // Cache for 30 seconds + player.Reply($"Now Playing: {nowPlaying}"); + } + else + { + player.Reply("No song information available."); + } + } + catch (Exception ex) + { + LogError($"GoodMorningBitcoin: Error processing response - {ex.Message}"); + player.Reply("Error processing the now playing information."); + } + }, this); + } + + private class NowPlayingResponse + { + [JsonProperty("now_playing")] + public NowPlayingDetails NowPlaying { get; set; } + } + + private class NowPlayingDetails + { + public SongInfo Song { get; set; } + } + + private class SongInfo + { + public string Text { get; set; } + } + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7583a00 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 RustySats + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c89195 --- /dev/null +++ b/README.md @@ -0,0 +1,58 @@ +# GoodMorningBitcoin Plugin + +![Plugin Version](https://img.shields.io/badge/version-0.1.5-blue.svg) +![License](https://img.shields.io/badge/license-MIT-green.svg) +![Platform](https://img.shields.io/badge/platform-Oxide%20Plugin%20for%20Rust-orange.svg) + +GoodMorningBitcoin is an Oxide plugin for Rust that displays "Now Playing" information from a configured radio API, providing players with the latest music being played on a designated radio station. + +## Features +- Fetches and displays the "Now Playing" song from a specified radio API. +- Simple configuration for API endpoint setup. +- Caches responses to limit API calls and optimize performance. +- Easy-to-use command for players to see what's currently playing. + +## Installation + +1. **Download the Plugin**: Download `GoodMorningBitcoin.cs` and place it in your server's `oxide/plugins` directory. +2. **Reload the Plugin**: Use the command `oxide.reload GoodMorningBitcoin` in the server console or in-game to load the plugin. +3. **Configuration**: A default configuration file will be created in `oxide/config` on the first run. + +## Configuration +The configuration file is simple and includes the following: + +```json +{ + "ApiEndpoint": "https://radio.goodmorningbitcoin.com/api/nowplaying" +} +``` + +- **ApiEndpoint**: The URL of the radio API to fetch the "Now Playing" information. + +## Commands + +### `/goodmorningbitcoin` +- **Description**: Displays the current song playing on the configured radio station. +- **Usage**: Players can type `/goodmorningbitcoin` in the chat to receive the current "Now Playing" song information. + +## Example Output +When a player types `/goodmorningbitcoin`, they may receive a response like: +``` +Now Playing: Song Title - Artist Name +``` + +## Error Handling +If the plugin encounters an issue retrieving or processing the data, it will log the error and display a user-friendly message: +``` +Unable to retrieve now playing information at the moment. Please try again later. +``` + +## Requirements +- **Oxide Mod**: Ensure your server has Oxide installed to run this plugin. +- **Rust Server**: A working Rust server with plugin capabilities. + +## License +This plugin is open-source and licensed under the [MIT License](LICENSE). + +## Contributing +Contributions are welcome! Feel free to submit issues or pull requests.