1.0.4 • Published 4 years ago

astoria v1.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Astoria

Build Status

Astoria is a Node.js 4chan board and thread monitor, useful for programatically keeping track of threads on a particular board, or posts in a particular thread, perfect for writing custom bots and scripts. Astoria makes use of, and aims to follow the guidelines of the 4chan API.

Installation :hammer:

Add Astoria to your project by installing via npm.

npm install -S astoria

Usage :coffee:

Create a new instance of Astoria:

let Astoria = require('astoria')

let astoria = new Astoria([options])

Options :wrench:

The Astoria client can be configured by passing an options object into the constructor with any of the following options.

OptionTypeDescriptionDefault
intervalnumberInterval between thread/board polling in seconds. Please be respectful to the server and don't set this below 10 seconds!30
updatesOnlybooleanIf set to true, when listening to a board/thread, only new threads/posts will be sent. Otherwise all current threads/posts will be sent immediately.false
unsubscribeOnNotFoundbooleanWhether to automatically stop listening if/when a board/thread returns 404true
useHttpsbooleanConnect to the 4chan API using HTTPS. Only use this if you're using this with an application that also uses HTTPS.false

Examples :balloon:

  • Check the /tv/ board for any new threads that get posted, every 5 minutes, and log out its id.
let astoria = new Astoria({
	interval: 60 * 5, // 5 mins
	updatesOnly: true // We're only interested in threads posted from now
})

astoria.board('tv')
	.listen((context, threads, err) {
		if (err) {
			return console.log(err)
		}

		threads.forEach(thread => console.log('New thread posted: ', thread.no))
	})
  • Load a /ck/ thread and stop listening once we've loaded all current replies, logging out their id.
let astoria = new Astoria()

let unsubscribe = astoria.board('ck')
	.thread('11444231')
	.listen((context, posts, err) {
		if (err) {
			return console.log(err)
		}

		posts.forEach(thread => console.log('Post: ', post.no))

		// Stop listening
		unsubscribe()
	})

API :link:

The following members exist on the Astoria client.

.options

The currently set options on the client. It is generally not recommended to overwrite these, but this property is available if needed.

.board(boardName): Astoria

Sets the board to listen to. This can be in a format such as /ck/ or ck. A board is required before the listener can begin.

Returns the current instance to allow method chaining.

Examples

astoria.board('/tv/') astoria.board('v')

.thread(threadNumber): Astoria

Sets the thread to listen to. This can either be in the format 12345678 or '12345678'. Additionally, if you wish to use an existing client which currently has a thread set, you can clear the thread by passing in null.

Returns the current instance to allow method chaining.

Examples

astoria.thread(55555555) astoria.thread('11115512')

.listen(function (context, updates, error)): function

Begin listening to the board (and thread) supplied to the client, based on the current options configuration. The listener creates a snapshot of this configuration, so if any of these values change after this method is called, it won't affect the listener.

Whenever new data is retrieved from 4chan, the callback will be invoked with the three arguments context, updates and error (described below).

Returns a function to unsubscribe from the listener. To stop listening to the board/thread, simply invoke the function.

context

context.board

The board the listener is attached to. e.g. /g/, /an/

context.thread

The thread the listener is attached to. e.g. 123512321, undefined

context.options

The options the listener is using. e.g. { interval: 30, useHttps: true, updatesOnly: true, unsubscribeOnNotFound: true }

updates

An array of new threads or posts. No matter what is being subscribed to, the following properties are available (if present) (with one exception). For example, the first post in a thread will also contain information about the thread, such as reply number, etc. (Table taken from 4chan API)

attributevaluedescriptionpossible valuesexample value
nointegerPost number1-99999999999999001
restointegerReply to0 (is a thread OP), 1-99999999999990
stickyintegerStickied thread?0 (no), 1 (yes)1
closedintegerClosed thread?0 (no), 1 (yes)1
archivedintegerArchived thread?0 (no), 1 (yes)1
archived_onintegerTime when archivedUNIX timestamp1344571233
nowstringDate and timeMM\/DD\/YY(Day)HH:MM (:SS on some boards), EST/EDT timezone08\/08\/12(Wed)01:11
timeintegerUNIX timestampUNIX timestamp1344570123
namestringNametextmoot
tripstringTripcodetext (format: !tripcode!!securetripcode)!Ep8pui8Vw2
idstringIDtext (8 characters), Mod, Admin, Manager, Developer, FounderAdmin
capcodestringCapcodenone, mod, admin, admin_highlight, manager, developer, founderadmin
countrystringCountry codetext (2 characters, ISO 3166-1 alpha-2), XX (unknown)XX
country_namestringCountry nametextUnknown
substringSubjecttextThis is a subject
comstringCommenttext (includes escaped HTML)This is a comment
timintegerRenamed filenameUNIX timestamp + milliseconds1344402680740
filenamestringOriginal filenametextOPisa
extstringFile extension.jpg, .png, .gif, .pdf, .swf, .webm.jpg
fsizeintegerFile size0-104857602500
md5stringFile MD5text (24 character, packed base64 MD5 hash)NOetrLVnES3jUn1x5ZPVAg==
wintegerImage width1-10000500
hintegerImage height1-10000500
tn_wintegerThumbnail width1-250250
tn_hintegerThumbnail height1-250250
filedeletedintegerFile deleted?0 (no), 1 (yes)0
spoilerintegerSpoiler image?0 (no), 1 (yes)0
custom_spoilerintegerCustom spoilers?1-993
omitted_postsinteger# replies omitted1-1000033
omitted_imagesinteger# image replies omitted1-1000021
repliesinteger# replies total0-99999231
imagesinteger# images total0-99999132
bumplimitintegerBump limit met?0 (no), 1 (yes)0
imagelimitintegerImage limit met?0 (no), 1 (yes)1
capcode_repliesarrayCapcode user replies?array of capcode type and post IDs{"admin":[1234,1267]}
last_modifiedintegerTime when last modifiedUNIX timestamp1344571233
tagstringThread tagtextLoop
semantic_urlstringThread URL slugtextdaily-programming-thread
since4passintegerYear 4chan Pass bought4 digit year (YYYY)2016

The exception being when subscribing to threads, each thread will have the following last_replies property on it.

attributevaluedescriptionpossible valuesexample value
last_repliesarrayThe latest replies on the threadarray of post objects (see above)[ { "no": 3214132, "com": "Im too big for this table" } ]

error

If an error occurred, this will contain an error object. Errors can include 404, to notify when threads have fallen off the catalog.

Contributing :gift:

This project is open to contributions. Please raise an issue before making a contribution. Additionally, please feel free to raise an issue if you find one. For each addition, please add an appropriate test.

License :zzz:

MIT

Futher reference :book:

Please read the 4chan API documentation for further information.

1.0.4

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago