Compare commits
10 Commits
912ba3b711
...
master
Author | SHA1 | Date | |
---|---|---|---|
373c883027 | |||
3a38d8e589 | |||
de4d35d213 | |||
47b8e0e9c0 | |||
bc20396a26 | |||
31877e5b53 | |||
660e850a72 | |||
e0ced417fb | |||
b4368eb8e0 | |||
0dccf16727 |
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"language": {
|
|
||||||
"javascript": {
|
|
||||||
"linting.prefer": "JSHint",
|
|
||||||
"linting.usePreferredOnly": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"jwolfe.file-tree-exclude.list": [
|
|
||||||
"node_modules",
|
|
||||||
"bower_components",
|
|
||||||
".git",
|
|
||||||
"dist",
|
|
||||||
"vendor",
|
|
||||||
"deploy",
|
|
||||||
".hg",
|
|
||||||
"build"
|
|
||||||
]
|
|
||||||
}
|
|
1
.hgignore → .gitignore
vendored
1
.hgignore → .gitignore
vendored
|
@ -13,3 +13,4 @@ backup/
|
||||||
config.js
|
config.js
|
||||||
.swp
|
.swp
|
||||||
.orig
|
.orig
|
||||||
|
log/
|
14
Dockerfile
Normal file
14
Dockerfile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
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" ]
|
|
@ -28,6 +28,13 @@ npm install
|
||||||
npm run start
|
npm run start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker build -t kulmapaikka-ircbot .
|
||||||
|
docker run -v $(pwd)/config.js:/app/config.js kulmapaikka-ircbot
|
||||||
|
```
|
||||||
|
|
||||||
## Tekijä
|
## Tekijä
|
||||||
|
|
||||||
Jukka Lankinen <jukka.lankinen@gmail.com>
|
Jukka Susivainio <jukka.susivainio@posteo.fi>
|
||||||
|
|
8
app.js
8
app.js
|
@ -4,7 +4,7 @@ const path = require('path')
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
const config = require('./config')
|
const config = require('./config')
|
||||||
const cron = require('node-cron')
|
const CronJob = require('cron').CronJob
|
||||||
|
|
||||||
// Load new plugins
|
// Load new plugins
|
||||||
const PluginManager = require('./plugins/pluginManager.js')
|
const PluginManager = require('./plugins/pluginManager.js')
|
||||||
|
@ -118,11 +118,13 @@ client.addListener('names', function (channel, nicks) {
|
||||||
|
|
||||||
for (let i = 0; i < config.cron.length; i++) {
|
for (let i = 0; i < config.cron.length; i++) {
|
||||||
let row = config.cron[i]
|
let row = config.cron[i]
|
||||||
cron.schedule(row.cron, () => {
|
logger.info('starting cron with ' + row.cron)
|
||||||
|
const job = new CronJob(row.cron, () => {
|
||||||
|
logger.info('cron triggered. Running command ' + row.command)
|
||||||
if (client.conn !== null) {
|
if (client.conn !== null) {
|
||||||
for (let c = 0; c < config.irc.channels.length; c++) {
|
for (let c = 0; c < config.irc.channels.length; c++) {
|
||||||
handleMessage('BOT', config.irc.channels[c], row.command)
|
handleMessage('BOT', config.irc.channels[c], row.command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}, null, true, 'Europe/Helsinki');
|
||||||
}
|
}
|
||||||
|
|
7082
package-lock.json
generated
7082
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -19,14 +19,14 @@
|
||||||
"cron": "=1.7.1",
|
"cron": "=1.7.1",
|
||||||
"file-stream-rotator": "=0.4.1",
|
"file-stream-rotator": "=0.4.1",
|
||||||
"finalhandler": "=1.1.2",
|
"finalhandler": "=1.1.2",
|
||||||
"googleapis": "=42.0.0",
|
"googleapis": "^91.0.0",
|
||||||
"html-to-text": "=5.1.1",
|
"html-to-text": "=5.1.1",
|
||||||
"irc": "=0.5.2",
|
"irc": "=0.5.2",
|
||||||
"lokijs": "=1.5.7",
|
"lokijs": "=1.5.7",
|
||||||
"mkdirp": "=0.5.1",
|
"mkdirp": "=0.5.5",
|
||||||
"morgan": "=1.9.1",
|
"morgan": "=1.9.1",
|
||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"node-dev": "=4.0.0",
|
"node-dev": "^7.1.0",
|
||||||
"node-uuid": "=1.4.8",
|
"node-uuid": "=1.4.8",
|
||||||
"promise": "=8.0.3",
|
"promise": "=8.0.3",
|
||||||
"request": "=2.88.0",
|
"request": "=2.88.0",
|
||||||
|
@ -36,6 +36,6 @@
|
||||||
"winston-daily-rotate-file": "^3.10.0"
|
"winston-daily-rotate-file": "^3.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^1.18.5"
|
"nodemon": "^2.0.15"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,7 @@ class Pwm extends BasePlugin {
|
||||||
|
|
||||||
today () {
|
today () {
|
||||||
var today = new Date()
|
var today = new Date()
|
||||||
var month = today.getMonth() + 1
|
return (new Intl.DateTimeFormat('fi-FI', {day: 'numeric', month: 'numeric', timeZone: 'Europe/Helsinki'}).format(today))
|
||||||
var day = today.getDate()
|
|
||||||
var dateString = day + '.' + month + '.'
|
|
||||||
return dateString
|
|
||||||
}
|
}
|
||||||
getWeather (city, code) {
|
getWeather (city, code) {
|
||||||
var language = 'fi'
|
var language = 'fi'
|
||||||
|
@ -78,8 +75,8 @@ class Pwm extends BasePlugin {
|
||||||
|
|
||||||
let sunriseDate = new Date(Number(weather.sys.sunrise) * 1000)
|
let sunriseDate = new Date(Number(weather.sys.sunrise) * 1000)
|
||||||
let sunsetDate = new Date(Number(weather.sys.sunset) * 1000)
|
let sunsetDate = new Date(Number(weather.sys.sunset) * 1000)
|
||||||
let sunrise = sunriseDate.getHours() + '.' + sunriseDate.getMinutes()
|
let sunrise = new Intl.DateTimeFormat('fi-FI', {hour: 'numeric', minute: 'numeric', timeZone: 'Europe/Helsinki'}).format(sunriseDate)
|
||||||
let sunset = sunsetDate.getHours() + '.' + sunsetDate.getMinutes()
|
let sunset = new Intl.DateTimeFormat('fi-FI', {hour: 'numeric', minute: 'numeric', timeZone: 'Europe/Helsinki'}).format(sunsetDate)
|
||||||
|
|
||||||
const $ = cheerio.load(data[0])
|
const $ = cheerio.load(data[0])
|
||||||
let names = []
|
let names = []
|
||||||
|
|
|
@ -4,7 +4,7 @@ var BasePlugin = require('./base.js')
|
||||||
const logger = require('../logger')
|
const logger = require('../logger')
|
||||||
|
|
||||||
class Weather extends BasePlugin {
|
class Weather extends BasePlugin {
|
||||||
constructor (config) {
|
constructor(config) {
|
||||||
super(config)
|
super(config)
|
||||||
this.name = 'Weather'
|
this.name = 'Weather'
|
||||||
|
|
||||||
|
@ -31,19 +31,19 @@ class Weather extends BasePlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
help () {
|
help() {
|
||||||
// | Command | Description
|
// | Command | Description
|
||||||
return '.saa <kaupunki> Antaa sään maapallon tärkeimmistä sijainneista'
|
return '.saa <kaupunki> Antaa sään maapallon tärkeimmistä sijainneista'
|
||||||
}
|
}
|
||||||
|
|
||||||
test (input) {
|
test(input) {
|
||||||
if (input.match(/^\.saa(.*)/i)) {
|
if (input.match(/^\.saa(.*)/i)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
getTemperature (city, code) {
|
getTemperature(city, code) {
|
||||||
var language = 'fi'
|
var language = 'fi'
|
||||||
|
|
||||||
var urlArgs = {
|
var urlArgs = {
|
||||||
|
@ -57,7 +57,7 @@ class Weather extends BasePlugin {
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
getTemperatures (cities, code) {
|
getTemperatures(cities, code) {
|
||||||
logger.info('getting temperatures ', cities, code)
|
logger.info('getting temperatures ', cities, code)
|
||||||
if (typeof code === 'undefined') {
|
if (typeof code === 'undefined') {
|
||||||
code = 'fi'
|
code = 'fi'
|
||||||
|
@ -76,11 +76,13 @@ class Weather extends BasePlugin {
|
||||||
'APPID': this.apikey
|
'APPID': this.apikey
|
||||||
}
|
}
|
||||||
var url = 'http://api.openweathermap.org/data/2.5/group'
|
var url = 'http://api.openweathermap.org/data/2.5/group'
|
||||||
var promise = requestPromise(url, urlArgs)
|
var promise = requestPromise(url, urlArgs).catch(e => {
|
||||||
|
logger.error('Failed to retrieve openweathermap data')
|
||||||
|
})
|
||||||
|
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
getPenaTemperatures (start, stop, limit) {
|
getPenaTemperatures(start, stop, limit) {
|
||||||
logger.info('getting pena', start, stop, limit)
|
logger.info('getting pena', start, stop, limit)
|
||||||
var urlArgs = {}
|
var urlArgs = {}
|
||||||
|
|
||||||
|
@ -96,13 +98,15 @@ class Weather extends BasePlugin {
|
||||||
urlArgs.stop = stop
|
urlArgs.stop = stop
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = 'http://masa.dy.fi/api/temperature.php'
|
var url = 'https://masa.dy.fi/api/temperature.php'
|
||||||
|
|
||||||
var promise = requestPromise(url, urlArgs)
|
var promise = requestPromise(url, urlArgs).catch(e => {
|
||||||
|
logger.error('Failed to retrieve pena temperatures data')
|
||||||
|
})
|
||||||
|
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
getTemperatureString (owmCityIds) {
|
getTemperatureString(owmCityIds) {
|
||||||
let that = this
|
let that = this
|
||||||
var promise = new Promise(function (resolve, reject) {
|
var promise = new Promise(function (resolve, reject) {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
@ -111,26 +115,30 @@ class Weather extends BasePlugin {
|
||||||
]).then(function (results) {
|
]).then(function (results) {
|
||||||
var resultString = ''
|
var resultString = ''
|
||||||
// OWM
|
// OWM
|
||||||
results[0].list.forEach(function (data) {
|
let weatherData = []
|
||||||
var city = data.name
|
if (results[0] !== undefined) {
|
||||||
var temp = (data.main.temp - 273.15).toFixed(1)
|
results[0].list.forEach((data) => {
|
||||||
var code = data.weather[0].icon
|
var city = data.name
|
||||||
|
var temp = (data.main.temp - 273.15).toFixed(1)
|
||||||
|
var code = data.weather[0].icon
|
||||||
|
|
||||||
resultString += '' + city + ' (' + temp + ' °C, ' + that.iconCodeToText[code] + '), '
|
weatherData.push(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)
|
resolve(resultString)
|
||||||
}, (str) => reject(str))
|
}, (str) => reject(str))
|
||||||
})
|
})
|
||||||
return promise
|
return promise
|
||||||
}
|
}
|
||||||
|
|
||||||
result (input) {
|
result(input) {
|
||||||
// Different cases
|
// Different cases
|
||||||
let that = this
|
let that = this
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ class Youtube extends BasePlugin {
|
||||||
resultString += result.title
|
resultString += result.title
|
||||||
resultString += ', esittäjänä ' + result.channelTitle
|
resultString += ', esittäjänä ' + result.channelTitle
|
||||||
if (typeof result.statistics !== 'undefined') {
|
if (typeof result.statistics !== 'undefined') {
|
||||||
var rotten = (Number(result.statistics.likeCount) / (Number(result.statistics.likeCount) + Number(result.statistics.dislikeCount))).toFixed(2)
|
var likeCount = Number(result.statistics.likeCount)
|
||||||
resultString += ' (' + result.duration + ', ' + result.statistics.viewCount + ' katselukertaa, ' + rotten * 100 + '% tykätty, ' + result.url + ' )'
|
resultString += ' (' + result.duration + ', ' + result.statistics.viewCount + ' katselukertaa, ' + likeCount + ' 👍)'
|
||||||
}
|
}
|
||||||
resolve(resultString)
|
resolve(resultString)
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user