Skip to content

Commit

Permalink
πŸš€ RELEASE: πŸ“– DOC: 1.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bombitmanbomb committed Jan 20, 2021
1 parent ccec257 commit f204b4b
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 119 deletions.
235 changes: 119 additions & 116 deletions Examples/Using-neosjs-commands.js
Original file line number Diff line number Diff line change
@@ -1,161 +1,164 @@
const NEOS = require("@bombitmanbomb/neosjs");
const {CommandManager} = require("neosjs-commands");
const { CommandManager } = require("neosjs-commands");
const process = require("process");
const Neos = new NEOS({
Update: true,
OnlineState: "Online",
OAuth: false,
StatusInterval: 120
Update: true,
OnlineState: "Online",
OAuth: false,
StatusInterval: 120,
});

// Create Command Module
const Commands = CommandManager.CreateCommands(Neos, "Invalid Command, Try <br>/commands <page>")
const Commands = CommandManager.CreateCommands(
Neos,
"Invalid Command, Try <br>/commands <page>"
);
const Admins = ["U-bombitmanbomb"]; // Admin Whitelist

Neos.on("login", obj => {
console.log(__dirname, "Logged in as " + Neos.CurrentUser.Username);
Neos.on("login", () => {
console.log(__dirname, "Logged in as " + Neos.CurrentUser.Username);
});

// Handle incoming friend requests
Neos.on("friendAdded", friend => {
if (friend.FriendStatus == "Requested") { // Add friend if incoming request
Neos.AddFriend(friend.FriendUserId);
}
Neos.on("friendAdded", (friend) => {
if (friend.FriendStatus == "Requested") {
// Add friend if incoming request
Neos.AddFriend(friend.FriendUserId);
}
});

// Handle incoming messages
Neos.on("messageReceived", m => {
switch (m.MessageType) {
case "Text":
return Commands.Run(m);
default:
Neos.SendTextMessage(
m.SenderId,
"Only Text Messages are supported at this time."
);
}
Neos.on("messageReceived", (m) => {
switch (m.MessageType) {
case "Text":
return Commands.Run(m);
default:
Neos.SendTextMessage(
m.SenderId,
"Only Text Messages are supported at this time."
);
}
});

// Custom Session List
Neos.on("statusUpdate", () => {
fetch("https://www.neosvr-api.com/api/sessions")
.then(d => d.json())
.then(sessions => {
let sessionList = [];
for (let session of sessions) {
// Add sessions by PolyLogiX, running a world, that are not Empty
if (
session.correspondingWorldId &&
session.correspondingWorldId.ownerId == "G-PolyLogiX" &&
session.activeUsers > 0
)
sessionList.push(new Neos.CloudX.Shared.SessionInfo(session));
}
Neos.Status.ActiveSessions = sessionList;
});
fetch("https://www.neosvr-api.com/api/sessions")
.then((d) => d.json())
.then((sessions) => {
let sessionList = [];
for (let session of sessions) {
// Add sessions by PolyLogiX, running a world, that are not Empty
if (
session.correspondingWorldId &&
session.correspondingWorldId.ownerId == "G-PolyLogiX" &&
session.activeUsers > 0
)
sessionList.push(new Neos.CloudX.Shared.SessionInfo(session));
}
Neos.Status.ActiveSessions = sessionList;
});
});


/**
* Setup Command Handles
*/

//Ping Pong!
Commands.Add("ping", Handler => Handler.Reply("pong!"), "Ping Pong!");
Commands.Add("ping", (Handler) => Handler.Reply("pong!"), "Ping Pong!");

// Return how long the process has been running
Commands.Add(
"uptime",
Handler => {
var uptime = process.uptime();
const date = new Date(uptime * 1000);
const days = date.getUTCDate() - 1,
hours = date.getUTCHours(),
minutes = date.getUTCMinutes(),
seconds = date.getUTCSeconds()
let segments = [];
if (days > 0) segments.push(days + " day" + (days == 1 ? "" : "s"));
if (hours > 0) segments.push(hours + " hour" + (hours == 1 ? "" : "s"));
if (minutes > 0)
segments.push(minutes + " minute" + (minutes == 1 ? "" : "s"));
if (seconds > 0)
segments.push(seconds + " second" + (seconds == 1 ? "" : "s"));
const dateString = segments.join(", ");
Handler.Reply(dateString);
},
"Get the bot uptime"
"uptime",
(Handler) => {
var uptime = process.uptime();
const date = new Date(uptime * 1000);
const days = date.getUTCDate() - 1,
hours = date.getUTCHours(),
minutes = date.getUTCMinutes(),
seconds = date.getUTCSeconds();
let segments = [];
if (days > 0) segments.push(days + " day" + (days == 1 ? "" : "s"));
if (hours > 0) segments.push(hours + " hour" + (hours == 1 ? "" : "s"));
if (minutes > 0)
segments.push(minutes + " minute" + (minutes == 1 ? "" : "s"));
if (seconds > 0)
segments.push(seconds + " second" + (seconds == 1 ? "" : "s"));
const dateString = segments.join(", ");
Handler.Reply(dateString);
},
"Get the bot uptime"
);

// Commands work in Async
Commands.Add(
"joke",
(Handler) => {
fetch("https://official-joke-api.appspot.com/jokes/random") // Fetch a joke
.then(d => d.json())
.then(joke => {
console.log(joke);
Handler.Reply(joke.setup);
setTimeout(() => Handler.Reply(joke.punchline), 2000);
// Responses must be a minimum 1100ms apart to send in the correct order
}).catch((err)=>{
console.log(err)
Handler.Reply("Something went Wrong!")
})
},
{
index: "Tell me a Joke",
categories: args => {
return "This function would return help info programaically";
},
usage: "/joke [category]"
}
"joke",
(Handler) => {
fetch("https://official-joke-api.appspot.com/jokes/random") // Fetch a joke
.then((d) => d.json())
.then((joke) => {
console.log(joke);
Handler.Reply(joke.setup);
setTimeout(() => Handler.Reply(joke.punchline), 2000);
// Responses must be a minimum 1100ms apart to send in the correct order
})
.catch((err) => {
console.log(err);
Handler.Reply("Something went Wrong!");
});
},
{
index: "Tell me a Joke",
categories: () => {
return "This function would return help info programaically";
},
usage: "/joke [category]",
}
);

// Relay Command
Commands.Add(
"send",
(Handler, SenderId, Arguments) => {
Neos.SendTextMessage(Arguments.shift(), Arguments.join(" ")).then(d => {
if (d.State == 200) {
Handler.Reply("Message Sent!");
} else {
Handler.Reply("Message Failed!");
}
});
},
{
index: "[Owner Command]<br>Relay a Message",
please: "No",
usage: "/send U-ID Message"
},
Admins // Whitelist to Admin Array
"send",
(Handler, SenderId, Arguments) => {
Neos.SendTextMessage(Arguments.shift(), Arguments.join(" ")).then((d) => {
if (d.State == 200) {
Handler.Reply("Message Sent!");
} else {
Handler.Reply("Message Failed!");
}
});
},
{
index: "[Owner Command]<br>Relay a Message",
please: "No",
usage: "/send U-ID Message",
},
Admins // Whitelist to Admin Array
);

// Usage Function example
Commands.Add(
"subscribe",
(h, s, a = []) => {
if (a.length != 1) {
return h.Usage();
}
h.Reply("You succeeded! Command not implimented yet");
},
{
index: function(args = [], self) {
// You can also use a Function in the help index!
// Self refers to the this scope of the current command object and can refrence or call other indexes
if (args.length === 0)
return "Usage: " + self.usage
return args.join(" ")
},
usage: Commands.Options.Prefix + "subscribe <channel>"
}
"subscribe",
(h, s, a = []) => {
if (a.length != 1) {
return h.Usage();
}
h.Reply("You succeeded! Command not implimented yet");
},
{
index: function (args = [], self) {
// You can also use a Function in the help index!
// Self refers to the this scope of the current command object and can refrence or call other indexes
if (args.length === 0) return "Usage: " + self.usage;
return args.join(" ");
},
usage: Commands.Options.Prefix + "subscribe <channel>",
}
);

//Login
Neos.Login(
process.env.Login,
process.env.Password,
undefined, // Session Token can be used instead of Password if available
"RandomUUIDv4"
process.env.Login,
process.env.Password,
undefined, // Session Token can be used instead of Password if available
"RandomUUIDv4"
);
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@bombitmanbomb/neosjs 1.11.0 | Documentation</title>
<title>@bombitmanbomb/neosjs 1.11.1 | Documentation</title>
<meta name="description" content="Neos API" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link href="assets/bass.css" rel="stylesheet" />
Expand All @@ -15,7 +15,7 @@
<div id="split-left" class="overflow-auto fs0 height-viewport-100">
<div class="py1 px2">
<h3 class="mb0 no-anchor">@bombitmanbomb/neosjs</h3>
<div class="mb1"><code>1.11.0</code></div>
<div class="mb1"><code>1.11.1</code></div>
<input
placeholder="Filter"
id="filter-input"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bombitmanbomb/neosjs",
"version": "1.11.0",
"version": "1.11.1",
"description": "Neos API",
"main": "Neos.js",
"scripts": {
Expand Down

0 comments on commit f204b4b

Please sign in to comment.