-
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.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
8 changed files
with
2,722 additions
and
476 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,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 | ||
}; |
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,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, | ||
} |
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,6 @@ | ||
const fs = require('fs'); | ||
const jsonData = JSON.parse(fs.readFileSync('./src/servers.json', 'utf8')) | ||
|
||
module.exports = { | ||
jsonData, | ||
} |
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,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, | ||
} |
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,9 @@ | ||
const { serverReducer } = require('./commands/server') | ||
const { combineReducers } = require('redux'); | ||
|
||
const reducer = combineReducers({ | ||
servers: serverReducer, | ||
lastUpdated: (state = {}) => state, | ||
}) | ||
|
||
module.exports = reducer |
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,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": {} | ||
} |