Discussions

Various notes and code regarding Discussions

Requires a web browser capable of running javascript in your browser console.

 const CATEGORY\_ID = "xxxxxx";

 const POST\_TITLE = `xxxxxx`;
 const POST\_CONTENTS = `xxxxxx`;

 const POLL\_TITLE = `xxxxxx`;
 const POLL\_OPTIONS = [
 { text: `Option 1`, position: 0 },
 { text: `Option 2`, position: 1 },
 ];

 // Don't edit anything below this line
 const response = await fetch(`https://${SITE\_URL}/wikia.php?controller=DiscussionThread&method=create&forumId=${CATEGORY\_ID}`, {
 method: "POST",
 headers: { "content-type": "application/json;charset=utf-8" },
 body: JSON.stringify({
 siteId: SITE\_ID,
 forumId: CATEGORY\_ID,
 title: POST\_TITLE,
 jsonModel: POST\_CONTENTS,
 poll: { question: POLL\_TITLE, answers: POLL\_OPTIONS },
 }),
 });

 const data = await response.json();

 console.log(`Your post is available at: https://${SITE\_URL}/f/p/${data.id}`, data);
})();

```

### Instructions

* `SITE_ID`: Go to Special:Version and search for `city_id`. Copy the associated number and replace `xxxxxx` with it. This is usually the same as your wiki's General category in Discussions, so don't worry if they end up being identical.
* `SITE_URL`: Copy the wiki's url and replace `xxxxxx.fandom.com` with it.
* `CATEGORY_ID`: Go to your wiki's discussions and then to the category you want to post in. Copy the number after `catId=` and replace `xxxxxx` with it. If you're posting in the general category it will probably be the same as the `SITE_ID`.
* `POST_TITLE`: The post's title in plain text form.
* `POST_CONTENTS`: To get the post's contents:
	1. Go to prosemirror.net and type the contents of your post into the editor
	2. Open your browser console. and run the following code:
	```
	console.log(JSON.stringify(view.state.doc.toJSON()))

	```
	3. Copy the resulting text and replace `xxxxxx` with it.
* `POLL_TITLE`: The poll's title in plain text form.
* `POLL_OPTIONS`: The options available in the poll. To add a new option:
	1. Copy
	```
	 { text: `xxxxxx`, position: 0 },

	```
	 and add it right beneath existing options.
	2. Change `xxxxxx` to what you want the poll option to read. Change the number after `position:` to be one more than the previous poll option. (e.g. if the previous poll option has a position of `1`, set the new poll option's position to `2`)

### Example

This example will create a post on this wiki's general board similar to this one.

```
(async () => {
 const SITE\_ID = "1376759";
 const SITE\_URL = "wingsoffirefanon-testing.fandom.com";

 const CATEGORY\_ID = "1376759";

 const POST\_TITLE = `Example Post`;
 const POST\_CONTENTS = `{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"This is an example post for "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https://wingsoffirefanon-testing.fandom.com/wiki/Discussions#Creating\_text\_posts\_with\_polls","title":""}}],"text":"the guide"},{"type":"text","text":" on how to post Discussions text posts with polls."}]}]}`;

 const POLL\_TITLE = `Were you able to use the guide?`;
 const POLL\_OPTIONS = [
 { text: `Yes, I was`, position: 0 },
 { text: `No, I wasn't`, position: 1 },
 ];

 // Don't edit anything below this line
 const response = await fetch(`https://${SITE\_URL}/wikia.php?controller=DiscussionThread&method=create&forumId=${CATEGORY\_ID}`, {
 method: "POST",
 headers: { "content-type": "application/json;charset=utf-8" },
 body: JSON.stringify({
 siteId: SITE\_ID,
 forumId: CATEGORY\_ID,
 title: POST\_TITLE,
 jsonModel: POST\_CONTENTS,
 poll: { question: POLL\_TITLE, answers: POLL\_OPTIONS },
 }),
 });

 const data = await response.json();

 console.log(`Your post is available at: https://${SITE\_URL}/f/p/${data.id}`, data);
})();

```