Move SinusBotService to backend
This commit is contained in:
@@ -16,23 +16,7 @@ export default class App extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
fetch('https://sinusbot.humenius.me/api/v1/bot/i/51314e26-13a1-4779-b2ac-e36d493687d4/event/tunakill_rank_all_user')
|
||||
.then(res => res.json())
|
||||
.then((data) => SinusBotService.consumeTunakillResponse(data))
|
||||
.then(
|
||||
(result) => {
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
users: result
|
||||
});
|
||||
},
|
||||
(error) => {
|
||||
this.setState({
|
||||
isLoaded: true,
|
||||
error: error
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import TableEntry from "../models/TableEntry";
|
||||
import TunaKillUser from "../models/TunaKillUser";
|
||||
|
||||
class SinusBotService {
|
||||
public static consumeTunakillResponse(data: any): TableEntry[] | undefined {
|
||||
if (!(data !== null || data[0] !== null || data[0].data !== null)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const response = data[0].data;
|
||||
if (!(response.length > 0)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return response
|
||||
.map((user: TunaKillUser) => {
|
||||
if (user.name === "Server Query Admin") { return null; }
|
||||
return {
|
||||
name: user.name,
|
||||
rawTime: user.time,
|
||||
onlineTime: new Date(user.time * 1000)
|
||||
.toISOString()
|
||||
.substr(11, 8)
|
||||
};
|
||||
})
|
||||
.sort((a: any, b: any) => {
|
||||
if (a.rawTime < b.rawTime) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a.rawTime > b.rawTime) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default SinusBotService;
|
||||
Reference in New Issue
Block a user