From 6d035af9785fdf69975a36ec3befb346783bb0b1 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 25 Jan 2026 18:02:52 -0500 Subject: [PATCH] feat(discord)!: remove discord widgetbot --- examples/jekyll/_config.yml | 2 -- src/js/discord.js | 57 ------------------------------------- tests/discord.test.js | 56 ------------------------------------ webpack.config.js | 1 - 4 files changed, 116 deletions(-) delete mode 100644 src/js/discord.js delete mode 100644 tests/discord.test.js diff --git a/examples/jekyll/_config.yml b/examples/jekyll/_config.yml index 3f78b15..898cc24 100644 --- a/examples/jekyll/_config.yml +++ b/examples/jekyll/_config.yml @@ -27,9 +27,7 @@ site-css: - "../dist/crowdin-bootstrap-css.css" site-js: - "../dist/crowdin.js" - - "../dist/discord.js" - "/assets/js/crowdin-init.js" - - "/assets/js/discord-init.js" # Advanced settings timezone: "America/New_York" diff --git a/src/js/discord.js b/src/js/discord.js deleted file mode 100644 index ef25380..0000000 --- a/src/js/discord.js +++ /dev/null @@ -1,57 +0,0 @@ -/* global Crate */ -// Crate is not defined... can we use npm version? -// https://github.com/widgetbot-io/crate/issues/26 - -const loadScript = require('./load-script'); -const { fetchRandomQuote } = require('./random-quote'); - -/** - * Notify the user with a random quote. - * @param {Object} quote - The quote object. - * @param {Crate} crate - The Crate object. - */ -function randomQuote(quote, crate) { - let the_quote = quote['quote_safe'] || quote['quote']; - crate.notify(the_quote); -} - -/** - * Initialize the Discord widget. - */ -function initDiscord() { - loadScript('https://cdn.jsdelivr.net/npm/@widgetbot/crate@3', function() { - let widgetbot = new Crate({ - server: '804382334370578482', - channel: '804383092822900797', - defer: false, - }); - - // Apply CSS position change directly in JavaScript - const style = document.createElement('style'); - style.innerHTML = ` - widgetbot-crate { - position: fixed !important; - } - `; - document.head.appendChild(style); - - // get random video game quotes and notify the user on Widgetbot after 7 minutes - fetchRandomQuote().then(quote => { - setTimeout(() => { - if (widgetbot) { - randomQuote(quote, widgetbot); - } - }, 7 * 60 * 1000); - }); - }); -} - -// Expose to the global scope -if (typeof window !== 'undefined') { - window.initDiscord = initDiscord; -} - -module.exports = { - initDiscord, - randomQuote, -}; diff --git a/tests/discord.test.js b/tests/discord.test.js deleted file mode 100644 index 66528cd..0000000 --- a/tests/discord.test.js +++ /dev/null @@ -1,56 +0,0 @@ -import { - describe, - expect, - it, - jest, -} from '@jest/globals'; - -const { initDiscord, randomQuote } = require('../src/js/discord'); -const loadScript = require('../src/js/load-script'); -const { fetchRandomQuote } = require('../src/js/random-quote'); - -jest.mock('../src/js/load-script'); -jest.mock('../src/js/random-quote'); - -describe('initDiscord', () => { - it('should load the script and get a random quote', () => { - jest.useFakeTimers(); - const mockCrate = { - notify: jest.fn() - }; - global.Crate = jest.fn(() => mockCrate); - - loadScript.mockImplementation((url, callback) => { - callback(); - }); - - fetchRandomQuote.mockResolvedValue({ - quote: 'Test quote', - quote_safe: 'Test quote safe' - }); - - initDiscord(); - - expect(global.Crate).toHaveBeenCalledWith({ - server: '804382334370578482', - channel: '804383092822900797', - defer: false, - }); - - // advance timers - jest.advanceTimersByTime(7 * 60 * 1000); - - expect(fetchRandomQuote).toHaveBeenCalled(); - }); -}); - -describe('randomQuote', () => { - it('should notify the user with the quote', () => { - const mockCrate = { - notify: jest.fn() - }; - - randomQuote({quote_safe: 'Test quote'}, mockCrate); - expect(mockCrate.notify).toHaveBeenCalledWith('Test quote'); - }); -}); diff --git a/webpack.config.js b/webpack.config.js index e063322..8b5397c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,7 +11,6 @@ let config = { 'crowdin-clean-jsdoc-css': './src/js/crowdin-clean-jsdoc-css', 'crowdin-doxygen-css': './src/js/crowdin-doxygen-css', 'crowdin-furo-css': './src/js/crowdin-furo-css', - 'discord': './src/js/discord', 'format-number': './src/js/format-number', 'levenshtein-distance': './src/js/levenshtein-distance', 'lizardbyte-css': './src/js/lizardbyte-css',