C4undBIER
Member
Hello,
i am trying to build a script which tells me the moon phase and writes an expression in a defined channel. i got my script working, but i want it to refresh/reload every defined time. do i have to build a seperate function to use settimeout?
my script until now is:
registerPlugin({
name: 'Moon',
version: 'IDK anymore',
description: 'MOON!',
author: 'Who cares?',
vars: {
fannel: {
title: 'Channel',
type: 'channel'
}
}
},
function(sinusbot,config) {
var time = new Date();
var day = "DD";
var month = "MM";
var year = "YYYY";
var cname;
var chname;
month =(time.getMonth() + 1);
day = time.getDate();
year = time.getFullYear();
function Moon_phase(year, month, day) {
var g;
var e;
if (month == 1) --day;
else if (month == 2) day += 30;
else // m >= 3
{
day += 28 + (month-2)*3059/100;
// adjust for leap years
if (!(year & 3)) ++day;
if ((year%100) == 0) --day;
}
g = (year-1900)%19 + 1;
e = (11*g + 18) % 30;
if ((e == 25 && g > 11) || e == 24) e++;
return ((((e + day)*6+11)%177)/22 & 7);
}
b = (Moon_phase(year, month, day));
// 0 => New Moon
// 1 => Waxing Crescent Moon
// 2 => Quarter Moon
// 3 => Waxing Gibbous Moon
// 4 => Full Moon
// 5 => Waning Gibbous Moon
// 6 => Last Quarter Moon
// 7 => Waning Crescent Moon
if (b === 4) {
cname = "Howwwwlll!!";
}
else if (b == 3) {
cname = "Arms and legs are getting hairier";
}
else if (b == 5) {
cname = "Back on two feet";
}
else if (b < 3) {
cname = "I swear i am not a werewolf";
}
else if (b> 5) {
cname = "I swear i am not a werewolf";
}
else {
cname = "You are shit at scripting.";
}
chname = "[cspacer]" + cname;
sinusbot.log('Mondphase ist: ' + b);
sinusbot.log("//0/8=New Moon");
sinusbot.log("//4=Full Moon");
sinusbot.log(day + "." + month + "." +year);
var topic = (day + "." + month + "." +year);
sinusbot.channelUpdate((config.fannel), { name: chname , topic: topic});
}
);
thanks for your answers
i am trying to build a script which tells me the moon phase and writes an expression in a defined channel. i got my script working, but i want it to refresh/reload every defined time. do i have to build a seperate function to use settimeout?
my script until now is:
registerPlugin({
name: 'Moon',
version: 'IDK anymore',
description: 'MOON!',
author: 'Who cares?',
vars: {
fannel: {
title: 'Channel',
type: 'channel'
}
}
},
function(sinusbot,config) {
var time = new Date();
var day = "DD";
var month = "MM";
var year = "YYYY";
var cname;
var chname;
month =(time.getMonth() + 1);
day = time.getDate();
year = time.getFullYear();
function Moon_phase(year, month, day) {
var g;
var e;
if (month == 1) --day;
else if (month == 2) day += 30;
else // m >= 3
{
day += 28 + (month-2)*3059/100;
// adjust for leap years
if (!(year & 3)) ++day;
if ((year%100) == 0) --day;
}
g = (year-1900)%19 + 1;
e = (11*g + 18) % 30;
if ((e == 25 && g > 11) || e == 24) e++;
return ((((e + day)*6+11)%177)/22 & 7);
}
b = (Moon_phase(year, month, day));
// 0 => New Moon
// 1 => Waxing Crescent Moon
// 2 => Quarter Moon
// 3 => Waxing Gibbous Moon
// 4 => Full Moon
// 5 => Waning Gibbous Moon
// 6 => Last Quarter Moon
// 7 => Waning Crescent Moon
if (b === 4) {
cname = "Howwwwlll!!";
}
else if (b == 3) {
cname = "Arms and legs are getting hairier";
}
else if (b == 5) {
cname = "Back on two feet";
}
else if (b < 3) {
cname = "I swear i am not a werewolf";
}
else if (b> 5) {
cname = "I swear i am not a werewolf";
}
else {
cname = "You are shit at scripting.";
}
chname = "[cspacer]" + cname;
sinusbot.log('Mondphase ist: ' + b);
sinusbot.log("//0/8=New Moon");
sinusbot.log("//4=Full Moon");
sinusbot.log(day + "." + month + "." +year);
var topic = (day + "." + month + "." +year);
sinusbot.channelUpdate((config.fannel), { name: chname , topic: topic});
}
);
thanks for your answers