-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new scripts and update existing files
- Loading branch information
Patsagorn
committed
Nov 27, 2023
1 parent
7b11381
commit 05c6af5
Showing
29 changed files
with
2,572 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
#! /bin/bash | ||
# This script is used to build the project on Toolforge server only! | ||
cd ~/bot | ||
npm install | ||
npm run build | ||
|
||
cd web | ||
npm install | ||
npm run build | ||
rm -rf node_modules/ | ||
# used locally | ||
# store current directory | ||
CDIR=$(pwd) | ||
echo -e ">> ${BLUE}Current directory: ${NC}" | ||
echo $CDIR | ||
# color | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
YELLOW='\033[0;33m' | ||
BLUE='\033[1;34m' # Light Blue | ||
NC='\033[0m' # No Color | ||
|
||
|
||
# build web app | ||
echo -e ">> ${BLUE}Building web app...${NC}" | ||
cd $CDIR/web | ||
|
||
# install dependencies | ||
pnpm i | ||
pnpm format | ||
pnpm build | ||
|
||
echo -e ">> ${GREEN}Web app build complete${NC}" | ||
echo -e ">> ${BLUE}Building server and bot script...${NC}" | ||
|
||
cd $CDIR | ||
pnpm i | ||
pnpm build | ||
|
||
echo -e ">> ${GREEN}Server and bot script build complete${NC}" | ||
|
||
# update git | ||
echo -e ">> ${BLUE}Updating git...${NC}" | ||
git add . | ||
|
||
# ask for commit message | ||
echo -e ">> ${YELLOW}Enter commit message:${NC}" | ||
read commitMessage | ||
git commit -m "$commitMessage" | ||
git push origin | ||
git push github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import bot from './bot.js'; | ||
import log from './logger.js'; | ||
/** | ||
* Get page transcluding. | ||
* @param {string} page Pages to get transcludings. | ||
* @param {string} [options.tiprop] Which properties to get | ||
* @param {string} [options.tinamespace] Only include pages in these namespaces. | ||
* @param {'redirect' | '!redirect'} [options.tishow] Show only items that meet these criteria. | ||
* @param {('max' | 'number')} [options.tilimit="max"] How may to return. | ||
* @returns {Promise<string[]> | Promise<[]>} array of page that the page has been transcluded in. | ||
*/ | ||
export async function getPageTranscluding(page, options = {}) { | ||
if (typeof page !== 'string' || page.split('').includes('|')) { | ||
log.log( | ||
'apierror', | ||
'page must be a string and not contain pipe character.', | ||
{ from: 'internal:bot#getPageTranscluding', id: 'invalid-page' } | ||
); | ||
return []; | ||
} | ||
let results = []; | ||
try { | ||
for await (let json of bot.continuedQueryGen({ | ||
action: 'query', | ||
prop: 'transcludedin', | ||
titles: page, | ||
tilimit: 'max', | ||
...options, | ||
formatversion: '2', | ||
})) { | ||
results = results.concat( | ||
json.query.pages[0].transcludedin.map((page) => page.title) | ||
); | ||
} | ||
} catch (err) { | ||
log.log('apierror', err, { | ||
from: 'internal:bot#getPageTranscluding', | ||
id: 'query-error', | ||
}); | ||
} | ||
log.log('debug', `getPageTranscluding: ${results.length} results.`, { | ||
from: 'internal:bot#getPageTranscluding', | ||
id: 'query-success', | ||
}); | ||
return results; | ||
} | ||
/** | ||
* Get pages in category. | ||
* @param {string} category Category to get pages. | ||
* @param {string} [options.cmtype] Only include pages in these types. | ||
* @param {string} [options.cmlimit="max"] How may to return. | ||
* @returns {Promise<string[]> | Promise<[]>} array of page that the category has. | ||
*/ | ||
export async function getCategoryMembers(category, options = {}) { | ||
if (typeof category !== 'string' || category.split('').includes('|')) { | ||
log.log( | ||
'apierror', | ||
'category must be a string and not contain pipe character.', | ||
{ from: 'internal:bot#getCategoryMembers', id: 'invalid-category' } | ||
); | ||
return []; | ||
} | ||
let results = []; | ||
try { | ||
for await (let json of bot.continuedQueryGen({ | ||
action: 'query', | ||
list: 'categorymembers', | ||
cmlimit: 'max', | ||
cmtitle: category, | ||
...options, | ||
formatversion: '2', | ||
})) { | ||
results = results.concat( | ||
json.query.categorymembers.map((page) => page.title) | ||
); | ||
} | ||
} catch (err) { | ||
log.log('apierror', err, { | ||
from: 'internal:bot#getCategoryMembers', | ||
id: 'query-error', | ||
}); | ||
} | ||
log.log('debug', `getCategoryMembers: ${results.length} results.`, { | ||
from: 'internal:bot#getCategoryMembers', | ||
id: 'query-success', | ||
}); | ||
return results; | ||
} | ||
/** | ||
* get list of object from list | ||
* @param {string} list used in `action=query&list=${list}` | ||
* @param {any} options additional options to pass to `action=query&list=${list}` | ||
* @returns list of objects, ripped of json.query.${list} parts. | ||
*/ | ||
export async function getApiQueryLists(list, options = {}) { | ||
if (typeof list !== 'string' || list.split('').includes('|')) { | ||
log.log( | ||
'apierror', | ||
'list must be a string and not contain pipe character.', | ||
{ from: 'internal:bot#getApiQueryLists', id: 'invalid-list' } | ||
); | ||
return []; | ||
} | ||
let results = []; | ||
try { | ||
for await (let json of bot.continuedQueryGen({ | ||
action: 'query', | ||
list, | ||
...options, | ||
formatversion: '2', | ||
})) { | ||
results = results.concat(json.query[list]); | ||
} | ||
} catch (err) { | ||
log.log('apierror', err, { | ||
from: 'internal:bot#getApiQueryLists', | ||
id: 'query-error', | ||
}); | ||
} | ||
log.log('debug', `getApiQueryLists: ${results.length} results.`, { | ||
from: 'internal:bot#getApiQueryLists', | ||
id: 'query-success', | ||
}); | ||
return results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2021 Patsagorn Y. | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
import { mwnVersion, version } from './version.js'; | ||
import { site, user } from './config.js'; | ||
import { mwn } from 'mwn'; | ||
const bot = new mwn({ | ||
apiUrl: site.siteUrl, | ||
OAuthCredentials: { | ||
...user.OAuthCredentials, | ||
}, | ||
// Set your user agent (required for WMF wikis, see https://meta.wikimedia.org/wiki/User-Agent_policy): | ||
userAgent: `PatsaBot/${version} ([[m:User:Patsagorn Y.]]) mwn/${mwnVersion}`, | ||
defaultParams: { | ||
assert: 'user', // ensure we're logged in | ||
}, | ||
}); | ||
await bot.initOAuth(); | ||
await bot.getTokensAndSiteInfo(); | ||
export default bot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { resolveRelativePath, parseJsonFile } from './utils.js'; | ||
// these are bad idea, but I will fix it as I now how ('=-=) | ||
export let credentials = parseJsonFile( | ||
resolveRelativePath(import.meta.url, '../../credentials.json') | ||
); | ||
export let config = parseJsonFile( | ||
resolveRelativePath(import.meta.url, '../../config.json') | ||
); | ||
/** | ||
* processing current user informations | ||
*/ | ||
export const loggerDir = resolveRelativePath(import.meta.url, '../../logs/'); | ||
export const user = { | ||
username: credentials.username, | ||
password: credentials.password, | ||
OAuthCredentials: { | ||
consumerToken: credentials.consumerToken, | ||
consumerSecret: credentials.consumerSecret, | ||
accessToken: credentials.accessToken, | ||
accessSecret: credentials.accessSecret, | ||
}, | ||
}; | ||
export const site = { | ||
siteUrl: config.config.siteUrl ?? 'https://th.wikipedia.org/w/api.php', | ||
}; | ||
export const ircConfig = { | ||
/** | ||
* IRC server address | ||
* @type {String} | ||
*/ | ||
server: credentials?.irc?.server ?? 'irc.libera.chat', | ||
/** | ||
* IRC server port | ||
* @type {Number} | ||
* @default 6667 | ||
* @example 6667 | ||
*/ | ||
port: credentials?.irc?.port ?? 6667, | ||
/** | ||
* IRC user's username | ||
* @type {String} | ||
*/ | ||
userName: credentials?.irc?.username, | ||
/** | ||
* IRC user's password | ||
* @type {String} | ||
* @default '' | ||
*/ | ||
password: credentials?.irc?.password ?? '', | ||
/** | ||
* IRC user's real name | ||
* @type {String} | ||
* @example 'PatsaBot by Patsagorn Y. (link to github)' | ||
*/ | ||
realName: credentials?.irc?.realName, | ||
/** | ||
* IRC user's nickname | ||
* @type {String} | ||
*/ | ||
nickName: credentials?.irc?.nickName, | ||
}; | ||
export const replicaCredentials = { | ||
/** database table username for autherization */ | ||
username: credentials?.replica?.username, | ||
/** database table password for autherization */ | ||
password: credentials?.replica?.password, | ||
}; | ||
export const replicaConfig = { | ||
/** | ||
* database table host | ||
* @type {String} | ||
* @default '127.0.0.1' | ||
*/ | ||
dbHost: config?.replica?.host ?? '127.0.0.1', | ||
/** | ||
* database table port | ||
* @type {Number} | ||
* @default 3306 | ||
*/ | ||
dbPort: config?.replica?.port ?? 3306, | ||
/** | ||
* database name | ||
* @type {String} | ||
* @default 'thwiki_p' | ||
*/ | ||
dbName: config?.replica?.database ?? 'thwiki_p', | ||
/** | ||
* database provider | ||
* @type {String} | ||
* @default 'mysql' | ||
*/ | ||
dbProvider: config?.replica?.provider ?? 'mysql', | ||
/** | ||
* database url for connection | ||
* @type {String} | ||
*/ | ||
dbURL: `${config?.replica?.provider ?? 'mysql'}://${ | ||
replicaCredentials.username | ||
}:${replicaCredentials.password}@${config?.replica?.host ?? '127.0.0.1'}:${ | ||
config?.replica?.port ?? 3306 | ||
}/${config?.replica?.database ?? 'thwiki_p'}`, | ||
}; | ||
export const schedule = parseJsonFile( | ||
resolveRelativePath(import.meta.url, '../../schedule.json') | ||
); |
Oops, something went wrong.