(Translated by https://www.hiragana.jp/)
Merge remote-tracking branch 'origin/master' · SerekKiri/BugHunter@1aa94ef · GitHub
Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Wandal1337 committed Aug 15, 2018
2 parents f8a4805 + 65e3ddf commit 1aa94ef
Showing 8 changed files with 2,722 additions and 476 deletions.
2,940 changes: 2,643 additions & 297 deletions javascript/package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -5,13 +5,17 @@
"main": "./src/index.js",
"dependencies": {
"debug": "^3.1.0",
"discord.js": "^11.3.2"
"discord.js": "^11.3.2",
"ramda": "^0.25.0",
"redux": "^4.0.0",
"zeal-redux-utils": "^2.0.0"
},
"devDependencies": {
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jsx-a11y": "^6.0.3"
"eslint-plugin-jsx-a11y": "^6.0.3",
"nodemon": "^1.18.3"
},
"scripts": {
"start": "nodemon src/index.js",
75 changes: 13 additions & 62 deletions javascript/src/commands/server.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,27 @@

function send(message) {
if (message.member.hasPermission('MANAGE_CHANNELS')) {
const fs = require('fs')

const pipe = (...fns) => val => fns.reduce((acc, fn) => fn(acc), val)

const dispatch = action => state => reducer(state, action)
const R = require('ramda');
const { createReducer, createActionTypes } = require('zeal-redux-utils');

function reducer(state, action) {
switch(action.type) {
case 'UPDATE_TIME': {
return {
...state,
time: new Date(),
}
}
case 'ADD_CHANNEL': {
return {
...state,
data: [
...state.data,
action.payload.id
],
}
}
case 'ADD_SERVER': {
return {
...state,
servers: {
...state.servers,
[action.payload.server]: action.payload.channel,
}
}
}
default: return state
}
}
const ActionType = createActionTypes("server", [
"ADD",
]);

const addChannel = (id) => ({
type: 'ADD_CHANNEL',
payload: {
id,
}
const serverReducer = createReducer({}, {
[ActionType.ADD]: (state, { payload }) => R.assoc(payload.server, payload.channel, state),
})

const updateTime = () => ({
type: 'UPDATE_TIME',
});

const addServer = (msg) => ({
type: 'ADD_SERVER',
type: ActionType.ADD,
payload: {
channel: msg.channel.id,
server: msg.guild.id,
}
})

const transformation = pipe(
dispatch(addServer(message)),
)

const updateJsonData = (file, pred) => {
const jsonData = JSON.parse(fs.readFileSync(file, 'utf8'))
fs.writeFileSync(file, JSON.stringify(pred(jsonData), null, 2));
}

// wołaj to kiedy Ci się tam podoba
updateJsonData('./servers.json', transformation)
message.reply('Channel set up successfully!')
} else {
message.reply('You need specific permision to use this command("manage channels").')
module.exports = {
serverReducer,
actions: {
addServer,
}
}

module.exports = send
};
45 changes: 30 additions & 15 deletions javascript/src/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
const Discord = require('discord.js');
const { createStore, applyMiddleware } = require('redux');

// importing files
const config = require('./config.json')
const help = require('./commands/help')
const report = require('./commands/report')
const server = require('./commands/server')

const initialState = require('./initial-state')
const middleware = require('./middleware')
const reducer = require('./reducer')

// variables
let channelsBugs = ['478884266852483073', '478886481281417216']

const client = new Discord.Client();
const store = createStore(reducer, initialState.jsonData, applyMiddleware(middleware.updateData))

client.on('ready', () => {
console.log(`Bug hunter has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds`)
client.user.setPresence({ game: { name: client.users.size + ' bugs hunters', type: 3 } })
})
})

client.on('message', async (message) => {

if (message.content.startsWith(config.prefix + 'bug')) {
report(message)
}

if (message.content.startsWith(config.prefix + 'help')) {
help(message)
}

if (message.content.startsWith('add channel')) {
server(message)
}
})

client.login(config.token)
if (message.content.startsWith(config.prefix + 'bug')) {
report(message)
}

if (message.content.startsWith(config.prefix + 'help')) {
help(message)
}

if (message.content.startsWith('add channel')) {
if (message.member.hasPermission('MANAGE_CHANNELS')) {
store.dispatch(server.actions.addServer(message))
message.reply('Channel set up successfully!')
} else {
message.reply('You need specific permision to use this command("manage channels").')
}
}
})

client.login(config.token)

module.exports = {
store,
}
6 changes: 6 additions & 0 deletions javascript/src/initial-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fs = require('fs');
const jsonData = JSON.parse(fs.readFileSync('./src/servers.json', 'utf8'))

module.exports = {
jsonData,
}
10 changes: 10 additions & 0 deletions javascript/src/middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const fs = require('fs');
const updateData = store => next => action => {
const result = next(action)
fs.writeFileSync("./src/servers.json", JSON.stringify(store.getState(), null, 2));
return result
}

module.exports = {
updateData,
}
9 changes: 9 additions & 0 deletions javascript/src/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { serverReducer } = require('./commands/server')
const { combineReducers } = require('redux');

const reducer = combineReducers({
servers: serverReducer,
lastUpdated: (state = {}) => state,
})

module.exports = reducer
105 changes: 5 additions & 100 deletions javascript/src/servers.json
Original file line number Diff line number Diff line change
@@ -1,103 +1,8 @@
{
"type": "Buffer",
"data": [
123,
34,
116,
121,
112,
101,
34,
58,
34,
66,
117,
102,
102,
101,
114,
34,
44,
34,
100,
97,
116,
97,
34,
58,
91,
49,
50,
51,
44,
51,
52,
44,
49,
49,
54,
44,
49,
48,
53,
44,
49,
48,
57,
44,
49,
48,
49,
44,
51,
52,
44,
53,
56,
44,
51,
52,
44,
51,
52,
44,
49,
50,
53,
93,
125,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
"478886890859134977",
null,
"478886890859134977",
null,
null
],
"time": "2018-08-14T22:48:31.972Z",
"servers": {
"367325058353594378": "478884266852483073",
"382070408226275328": "478886481281417216"
}
"382070408226275328": "478886481281417216",
"475993415809499166": "479243666574016530",
"367325058353594378": "478886890859134977"
},
"lastUpdated": {}
}

0 comments on commit 1aa94ef

Please sign in to comment.