wrzucamy śmietnik :DDDD

This commit is contained in:
Szprink 2025-08-12 18:39:05 +02:00
parent 6d3524eed5
commit cded4e036a
10 changed files with 2296 additions and 0 deletions

2
.gitignore vendored
View file

@ -130,3 +130,5 @@ dist
.yarn/install-state.gz
.pnp.*
# config file (template provided manually)
config.json

16
commands/dcstatus.js Normal file
View file

@ -0,0 +1,16 @@
module.exports = {
data: {
"name": 'dcstatus',
"usage": '',
"description": 'Check if Discord is working.'
},
async execute(event, bot) {
const response = await fetch('https://discordstatus.com/api/v2/status.json');
if (!response.ok) {
event.reply("Failed to download status!")
} else {
const json = await response.json()
event.reply(`${json.status.description}: ${json.page.url}`)
}
}
}

39
commands/slavista.js Normal file
View file

@ -0,0 +1,39 @@
const sanitizeHtml = require('sanitize-html')
module.exports = {
data: {
"name": 'slavista',
"usage": '',
"description": 'Sends latest fediverse post made by slavistapl.'
},
async execute(event, bot) {
const response = await fetch('https://500plus.slavistapl.eu.org/api/v1/accounts/AajrBXKHPBH47ggKFU/statuses?exclude_replies=false&with_muted=true');
if (!response.ok) {
event.reply("Couldn't fetch posts...")
} else {
const json = await response.json()
let i = 0
let done = false
do {
if (i > json.length) {
event.reply("Couldn't fetch posts...")
done = true
} else {
if (json[i].content == "" && json[i].media_attachments.length == 0) {
i++
} else {
let str = sanitizeHtml(`${json[i].content.toString()} | ${json[i].uri}`, {
allowedTags: ['a'],
allowedAttributes: {
'a': ['href']
}
})
event.reply(str)
done = true
}
}
} while (!done)
}
}
}

14
commands/twojastara.js Normal file
View file

@ -0,0 +1,14 @@
const fs = require('node:fs')
const twojaStara = fs.readFileSync('./twojastara.txt').toString().split('\n')
module.exports = {
data: {
"name": 'twojastara',
"usage": '',
"description": 'Sends a random "Twoja Stara" (Yo Mamma) joke.'
},
async execute(event, bot) {
let num = Math.floor(Math.random() * twojaStara.length)
event.reply(twojaStara[num])
}
}

49
commands/wpedia.js Normal file
View file

@ -0,0 +1,49 @@
const wikijs = require('wikijs').default
module.exports = {
data: {
"name": 'wpedia',
"usage": '<language code> <query>',
"description": 'Search for Wikipedia articles.'
},
async execute(event, bot) {
let query = event.message.split(`${bot.prefix}wpedia `)[1].toString().split(' ')
if (!query) {
event.reply(`Usage: ${bot.prefix}wpedia <language code> <query>`)
} else {
let lang = query.shift()
if (!query) { // since query can be empty now, we need to check again
event.reply(`Usage: ${bot.prefix}wpedia <language code> <query>`)
} else {
try {
let okToContinue = false
try {
let connTest = await fetch(`https://${lang}.wikipedia.org/w/api.php`)
console.log(connTest)
okToContinue = true
} catch (err) {
okToContinue = false
event.reply(`Oops, something went wrong... Is the language code correct?`)
}
if (okToContinue) {
let wiki = wikijs({
apiUrl: `https://${lang}.wikipedia.org/w/api.php`
})
query = query.join(' ')
wiki.search(query).then(async res => {
if (!res['results'][0]) return event.reply("Sorry, couldn't find anything...")
wiki.page(res['results'][0]).then(async page => {
let info = await page.summary()
event.reply(`${info.split('\n')[0]} https://${lang}.wikipedia.org/wiki/${res['results'][0].replace(/ /g, "_")}`)
})
})
}
} catch (err) {
event.reply(`Oops, something went wrong... Is the language code correct?`)
console.error(err)
}
}
}
}
}

23
commands/yt.js Normal file
View file

@ -0,0 +1,23 @@
const config = require('../config.json')
const YouTube = require('simple-youtube-api')
const youtube = new YouTube(config.youtube.token)
module.exports = {
data: {
"name": 'yt',
"usage": '<query>',
"description": 'Search for YouTube videos.'
},
async execute(event, bot) {
let query = event.message.split(`${bot.prefix}yt `)[1]
if (!query) {
event.reply(`Usage: ${bot.prefix}yt <query>`)
} else {
youtube.searchVideos(query, 1)
.then(results => {
if (!results[0]) return event.reply("Sorry, couldn't find anything...")
event.reply(results[0].url)
})
}
}
}

47
index.js Normal file
View file

@ -0,0 +1,47 @@
const config = require('./config.json')
const IRC = require('irc-framework')
const fs = require('node:fs')
const bot = new IRC.Client()
// for convinience's sake
bot.config = config
bot.prefix = config.bot.prefix
bot.commands = []
const commandsFolder = fs.readdirSync('./commands/')
for (const file of commandsFolder) {
const command = require(`./commands/${file}`)
if ('data' in command && 'execute' in command) {
bot.commands[command.data.name] = command
console.log(`loaded command: ${command.data.name}`)
} else {
console.log(`failed to load file ${file}, it's missing "data" or "execute" property`)
}
}
bot.connect({
host: config.irc.server,
port: config.irc.port,
nick: config.irc.nick,
password: config.irc.password
})
bot.on('registered', function() {
console.log('connected ok!')
bot.join(config.irc.channel)
})
bot.on('message', async function(event) {
if (event.message.toString().startsWith(bot.prefix)) {
let sentCommand = event.message.toString().split(bot.prefix)[1].toString().split(' ')[0]
if (bot.commands[sentCommand]) {
try {
await bot.commands[sentCommand].execute(event, bot)
console.log(event)
} catch (err) {
event.reply('Oops, something went horribly wrong when executing this command...')
console.error(err)
}
}
}
})

1016
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

18
package.json Normal file
View file

@ -0,0 +1,18 @@
{
"name": "ircbot",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "commonjs",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"irc-framework": "^4.14.0",
"sanitize-html": "^2.17.0",
"simple-youtube-api": "^5.2.1",
"wikijs": "^6.4.1"
}
}

1072
twojastara.txt Normal file

File diff suppressed because it is too large Load diff