Compare commits

..

No commits in common. "master" and "912ba3b711144e66a9f0ee073d3cd75ea86a78ab" have entirely different histories.

10 changed files with 2759 additions and 4458 deletions

18
.brackets.json Executable file
View File

@ -0,0 +1,18 @@
{
"language": {
"javascript": {
"linting.prefer": "JSHint",
"linting.usePreferredOnly": true
}
},
"jwolfe.file-tree-exclude.list": [
"node_modules",
"bower_components",
".git",
"dist",
"vendor",
"deploy",
".hg",
"build"
]
}

View File

@ -13,4 +13,3 @@ backup/
config.js
.swp
.orig
log/

View File

@ -1,14 +0,0 @@
FROM node:alpine
# Setup
WORKDIR /app
COPY package*.json ./
RUN npm install
# Copy code
COPY app.js .
COPY appTest.js .
COPY logger.js .
COPY plugins/ ./plugins/
CMD [ "node", "app.js" ]

View File

@ -28,13 +28,6 @@ npm install
npm run start
```
## Docker
```sh
docker build -t kulmapaikka-ircbot .
docker run -v $(pwd)/config.js:/app/config.js kulmapaikka-ircbot
```
## Tekijä
Jukka Susivainio <jukka.susivainio@posteo.fi>
Jukka Lankinen <jukka.lankinen@gmail.com>

8
app.js
View File

@ -4,7 +4,7 @@ const path = require('path')
// Load config
const config = require('./config')
const CronJob = require('cron').CronJob
const cron = require('node-cron')
// Load new plugins
const PluginManager = require('./plugins/pluginManager.js')
@ -118,13 +118,11 @@ client.addListener('names', function (channel, nicks) {
for (let i = 0; i < config.cron.length; i++) {
let row = config.cron[i]
logger.info('starting cron with ' + row.cron)
const job = new CronJob(row.cron, () => {
logger.info('cron triggered. Running command ' + row.command)
cron.schedule(row.cron, () => {
if (client.conn !== null) {
for (let c = 0; c < config.irc.channels.length; c++) {
handleMessage('BOT', config.irc.channels[c], row.command)
}
}
}, null, true, 'Europe/Helsinki');
})
}

7094
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,14 +19,14 @@
"cron": "=1.7.1",
"file-stream-rotator": "=0.4.1",
"finalhandler": "=1.1.2",
"googleapis": "^91.0.0",
"googleapis": "=42.0.0",
"html-to-text": "=5.1.1",
"irc": "=0.5.2",
"lokijs": "=1.5.7",
"mkdirp": "=0.5.5",
"mkdirp": "=0.5.1",
"morgan": "=1.9.1",
"node-cron": "^2.0.3",
"node-dev": "^7.1.0",
"node-dev": "=4.0.0",
"node-uuid": "=1.4.8",
"promise": "=8.0.3",
"request": "=2.88.0",
@ -36,6 +36,6 @@
"winston-daily-rotate-file": "^3.10.0"
},
"devDependencies": {
"nodemon": "^2.0.15"
"nodemon": "^1.18.5"
}
}

View File

@ -25,7 +25,10 @@ class Pwm extends BasePlugin {
today () {
var today = new Date()
return (new Intl.DateTimeFormat('fi-FI', {day: 'numeric', month: 'numeric', timeZone: 'Europe/Helsinki'}).format(today))
var month = today.getMonth() + 1
var day = today.getDate()
var dateString = day + '.' + month + '.'
return dateString
}
getWeather (city, code) {
var language = 'fi'
@ -75,8 +78,8 @@ class Pwm extends BasePlugin {
let sunriseDate = new Date(Number(weather.sys.sunrise) * 1000)
let sunsetDate = new Date(Number(weather.sys.sunset) * 1000)
let sunrise = new Intl.DateTimeFormat('fi-FI', {hour: 'numeric', minute: 'numeric', timeZone: 'Europe/Helsinki'}).format(sunriseDate)
let sunset = new Intl.DateTimeFormat('fi-FI', {hour: 'numeric', minute: 'numeric', timeZone: 'Europe/Helsinki'}).format(sunsetDate)
let sunrise = sunriseDate.getHours() + '.' + sunriseDate.getMinutes()
let sunset = sunsetDate.getHours() + '.' + sunsetDate.getMinutes()
const $ = cheerio.load(data[0])
let names = []

View File

@ -4,7 +4,7 @@ var BasePlugin = require('./base.js')
const logger = require('../logger')
class Weather extends BasePlugin {
constructor(config) {
constructor (config) {
super(config)
this.name = 'Weather'
@ -31,19 +31,19 @@ class Weather extends BasePlugin {
}
}
help() {
help () {
// | Command | Description
return '.saa <kaupunki> Antaa sään maapallon tärkeimmistä sijainneista'
}
test(input) {
test (input) {
if (input.match(/^\.saa(.*)/i)) {
return true
}
return false
}
getTemperature(city, code) {
getTemperature (city, code) {
var language = 'fi'
var urlArgs = {
@ -57,7 +57,7 @@ class Weather extends BasePlugin {
return promise
}
getTemperatures(cities, code) {
getTemperatures (cities, code) {
logger.info('getting temperatures ', cities, code)
if (typeof code === 'undefined') {
code = 'fi'
@ -76,13 +76,11 @@ class Weather extends BasePlugin {
'APPID': this.apikey
}
var url = 'http://api.openweathermap.org/data/2.5/group'
var promise = requestPromise(url, urlArgs).catch(e => {
logger.error('Failed to retrieve openweathermap data')
})
var promise = requestPromise(url, urlArgs)
return promise
}
getPenaTemperatures(start, stop, limit) {
getPenaTemperatures (start, stop, limit) {
logger.info('getting pena', start, stop, limit)
var urlArgs = {}
@ -98,15 +96,13 @@ class Weather extends BasePlugin {
urlArgs.stop = stop
}
var url = 'https://masa.dy.fi/api/temperature.php'
var url = 'http://masa.dy.fi/api/temperature.php'
var promise = requestPromise(url, urlArgs).catch(e => {
logger.error('Failed to retrieve pena temperatures data')
})
var promise = requestPromise(url, urlArgs)
return promise
}
getTemperatureString(owmCityIds) {
getTemperatureString (owmCityIds) {
let that = this
var promise = new Promise(function (resolve, reject) {
Promise.all([
@ -115,30 +111,26 @@ class Weather extends BasePlugin {
]).then(function (results) {
var resultString = ''
// OWM
let weatherData = []
if (results[0] !== undefined) {
results[0].list.forEach((data) => {
var city = data.name
var temp = (data.main.temp - 273.15).toFixed(1)
var code = data.weather[0].icon
results[0].list.forEach(function (data) {
var city = data.name
var temp = (data.main.temp - 273.15).toFixed(1)
var code = data.weather[0].icon
weatherData.push(city + ' (' + temp + ' °C, ' + that.iconCodeToText[code] + ')')
})
resultString += '' + city + ' (' + temp + ' °C, ' + that.iconCodeToText[code] + '), '
})
if (results[1].length > 0) {
var temp = Number(results[1][0].temp).toFixed(1)
resultString += 'Aura (' + temp + ' °C)'
}
if (results[1] !== undefined) {
if (results[1].length > 0) {
var temp = Number(results[1][0].temp).toFixed(1)
weatherData.push('Aura (' + temp + ' °C)')
}
}
resultString = weatherData.join(', ')
resolve(resultString)
}, (str) => reject(str))
})
return promise
}
result(input) {
result (input) {
// Different cases
let that = this

View File

@ -25,8 +25,8 @@ class Youtube extends BasePlugin {
resultString += result.title
resultString += ', esittäjänä ' + result.channelTitle
if (typeof result.statistics !== 'undefined') {
var likeCount = Number(result.statistics.likeCount)
resultString += ' (' + result.duration + ', ' + result.statistics.viewCount + ' katselukertaa, ' + likeCount + ' 👍)'
var rotten = (Number(result.statistics.likeCount) / (Number(result.statistics.likeCount) + Number(result.statistics.dislikeCount))).toFixed(2)
resultString += ' (' + result.duration + ', ' + result.statistics.viewCount + ' katselukertaa, ' + rotten * 100 + '% tykätty, ' + result.url + ' )'
}
resolve(resultString)
}, function (err) {