Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prefix = "!";
- const botname = "NonoAI playing: !help";
- const help = "__NonoAI Commands__\n!help, !say {TEXT}, !joke, !fact, !image {URL}, !weather {LOCATION}, !clock, !search {QUERY}, !youtube {URL}, !nicovideo {URL}";
- function sendMsg(msg) {
- setTimeout(() => {
- socket.emit("talk", { text: msg });
- }, 1100);
- }
- setTimeout(() => {
- socket.emit("command", { list: ["name", "NonoAI playing: !help"] });
- }, 1000);
- setTimeout(() => {
- socket.emit("command", { list: ["name", "NonoAI playing: !help"] });
- }, 2100);
- setTimeout(() => {
- sendMsg("NonoAI is online. Type " + prefix + "help to see commands. If you want to check my YouTube channel, visit https://www.youtube.com/channel/UC7a3K0C_eHvKu-pdDAqpHyg");
- setInterval(() => {
- sendMsg("NonoAI is online. Type " + prefix + "help to see commands. If you want to check my YouTube channel, visit https://www.youtube.com/channel/UC7a3K0C_eHvKu-pdDAqpHyg");
- }, 60000);
- }, 3200);
- socket.on("talk", function (message) {
- if (message.text === prefix + "help") {
- sendMsg(help);
- } else if (message.text.startsWith(prefix + "say")) {
- sendMsg(message.text.substring(prefix.length + 3));
- } else if (message.text === prefix + "joke") {
- setTimeout(() => {
- socket.emit("command", { list: ["joke"] });
- }, 1100);
- } else if (message.text === prefix + "fact") {
- setTimeout(() => {
- socket.emit("command", { list: ["fact"] });
- }, 1100);
- } else if (message.text.startsWith(prefix + "image")) {
- const imageUrl = message.text.substring(prefix.length + 6).trim();
- if (imageUrl !== "") {
- sendImage(imageUrl);
- } else {
- sendMsg("Please provide a valid image URL after the command. Example: `!image https://example.com/image.jpg`");
- }
- } else if (message.text.startsWith(prefix + "weather")) {
- const location = message.text.substring(prefix.length + 8).trim();
- setTimeout(() => {
- getWeather(location);
- }, 1100);
- } else if (message.text === prefix + "clock") {
- const currentTime = new Date().toLocaleTimeString();
- sendMsg(`The current time is: ${currentTime}`);
- } else if (message.text.startsWith(prefix + "search")) {
- const query = message.text.substring(prefix.length + 7).trim();
- if (query !== "") {
- search(query);
- } else {
- sendMsg("Please provide a query after the command. Example: `!search cats`");
- }
- } else if (message.text.startsWith(prefix + "youtube")) {
- const videoUrl = message.text.substring(prefix.length + 8).trim();
- if (videoUrl !== "") {
- playYoutubeVideo(videoUrl);
- } else {
- sendMsg("Please provide a valid YouTube video URL after the command. Example: `!youtube https://www.youtube.com/watch?v=VIDEO_ID`");
- }
- } else if (message.text.startsWith(prefix + "nicovideo")) {
- const videoUrl = message.text.substring(prefix.length + 10).trim();
- if (videoUrl !== "") {
- playNicoVideo(videoUrl);
- } else {
- sendMsg("Please provide a valid NicoVideo URL after the command. Example: `!nicovideo https://www.nicovideo.jp/watch/sm9`");
- }
- } else {
- if (message.text.startsWith(prefix)) {
- sendMsg("Sorry, I don't understand that command. Type " + prefix + "help to see the list of available commands.");
- }
- }
- });
- function sendImage(imageUrl) {
- setTimeout(() => {
- socket.emit("command", { list: ["image", imageUrl] });
- }, 1100);
- }
- function getWeather(location) {
- const apiKey = "dcc6b2a3fa3d4fe58d9193316232905";
- const apiUrl = `https://api.weatherapi.com/v1/current.json?key=${apiKey}&q=${encodeURIComponent(location)}`;
- fetch(apiUrl)
- .then(response => response.json())
- .then(data => {
- if (data.error) {
- sendMsg("Unable to retrieve weather information. Please check the location.");
- } else {
- const weather = data.current;
- const weatherInfo = `Weather in ${data.location.name}, ${data.location.country}:\nCondition: ${weather.condition.text}\nTemperature: ${weather.temp_c}°C\nHumidity: ${weather.humidity}%\nWind Speed: ${weather.wind_kph} km/h\n`;
- sendMsg(weatherInfo);
- }
- })
- .catch(error => {
- console.error("Error:", error);
- sendMsg("An error occurred while retrieving weather information.");
- });
- }
- function search(query) {
- const apiKey = "4a4725a769msh10c74bc91185a85p182f25jsn9a1a93fbbb77";
- const apiUrl = `https://contextualwebsearch-websearch-v1.p.rapidapi.com/api/search/NewsSearchAPI?q=${encodeURIComponent(query)}&pageSize=1`;
- fetch(apiUrl, {
- headers: {
- "X-RapidAPI-Key": apiKey,
- "X-RapidAPI-Host": "contextualwebsearch-websearch-v1.p.rapidapi.com"
- }
- })
- .then(response => response.json())
- .then(data => {
- if (data.value && data.value.length > 0) {
- const searchResults = data.value.map(result => ({
- title: result.title,
- description: result.description.length > 50 ? result.description.substring(0, 50) + "..." : result.description,
- url: result.url
- }));
- sendMsg(formatSearchResults(searchResults));
- } else {
- sendMsg("No search results found.");
- }
- })
- .catch(error => {
- console.error("Error:", error);
- sendMsg("An error occurred while performing the search.");
- });
- }
- function formatSearchResults(results) {
- let message = "Search Results:\n";
- results.forEach((result, index) => {
- message += `\n${index + 1}. ${result.title}\nDescription: ${result.description}\nURL: ${result.url}\n`;
- });
- return message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement