Git Product home page Git Product logo

gtaweather's Introduction

GTA Weather

Version License

Intro

This Node.js module returns information about the in-game time and weather in GTA Online lobbies for any given time. It's intended to be used in Discord bots, but could be used in any Node.js environment.

Special thanks to Pardonias

Usage

Example use in a Discord.js bot with gtaweather.js placed next to the main .js file:

const Discord       = require("discord.js");
const GTAWeather    = require("./gtaweather");
const client        = new Discord.Client();

client.on('message', msg => {
    if (msg.content.toLowerCase() == "!gtaweather") {
        // Getting current weather
        var weather = null;

        try {
            weather = GTAWeather.GetForecast();
        } catch (err) {
            msg.channel.send("An error has occured: " + err.message);
        }

        // Constructing response
        msg.channel.send(
            weather.description + "\n" +
            "In-game time: " + weather.gameTimeStr + "\n" +
            "Current weather: " + weather.currentWeatherDescription + " " + weather.currentWeatherEmoji + "\n" +
            (weather.isRaining ? "Rain is expected to stop in " : "Rain is expected in ") + weather.rainEtaStr
        );
    }
});

client.login('token');

API

function GetForecast(targetDate?: Date): GTAWeatherState

Returns the current in-game time and weather in GTA Online. Can throw an Error object on error.

targetDate is the time the forecast will be given for (if omitted, the current time is used)

See the structure of the returned object below.

Structure of GTAWeatherState

  • description (string) - Describes the time/date the forecast is for
  • thumbnailURL (string) - URL to a thumbnail picture showing the weather
  • gameTimeHrs (number) - In-game time as the number of hours [0.0, 24.0)
  • gameTimeStr (string) - In-game time, formatted as HH:MM (24-hour)
  • currentWeatherEmoji (string) - Emoji showing the weather
  • currentWeatherDescription (string) - Name of the weather condition
  • rainEtaSec (number) - Time until it starts/stops raining, in seconds (see isRaining)
  • rainEtaStr (string) - Time until it starts/stops raining, as a human-readable string (see isRaining)
  • isRaining (boolean) - Shows if it's raining.
    • If true, then rainEtaSec and rainEtaStr show when the rain stops, otherwise they show when it starts

Notes

The description field of GTAWeatherState has Discord-specific formatting such as: Forecast for **24 April 2019 15:18:18 UTC** (now). You can just remove * characters from the string if you don't need that.

Version history

  • v1.0
    • Initial release
  • v1.1
    • Fixed incorrect emojis
  • v1.2
    • Changed sunrise time from 5AM to 6AM
    • Minor code changes and fixes

WTFPL Licensed under WTFPL v2 (see the file COPYING).

gtaweather's People

Contributors

adam10603 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

odnols

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.