-
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.
- Loading branch information
1 parent
3378eff
commit 591b511
Showing
12 changed files
with
291 additions
and
11 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
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,100 @@ | ||
import { bots } from "." | ||
|
||
interface UserData { | ||
email: string, | ||
location: string, | ||
website: string, | ||
hobby: string, | ||
intro: string, | ||
background: string, | ||
music: string, | ||
lastLoginTime: Date, | ||
visits: string, | ||
title: string, | ||
rooms: string[], | ||
tags: string, | ||
regTime: Date, | ||
online: string, | ||
credit: string, | ||
life: { | ||
image: string, | ||
time: Date, | ||
desc: string | ||
}[], | ||
mate: { | ||
username: string | null, | ||
avatar: string | null, | ||
color: string | null | ||
}, | ||
money: { | ||
hold: string, | ||
bank: string | ||
}, | ||
like: { | ||
times: number, | ||
users: string[] | ||
} | ||
} | ||
|
||
class User { | ||
public data?: UserData | ||
public uid?: string | ||
public username?: string | ||
constructor({ uid, username }: { uid?: string, username?: string }) { | ||
this.uid = uid | ||
this.username = username | ||
|
||
if (!uid && !username) { | ||
throw new Error("uid or username must be provided") | ||
} | ||
} | ||
} | ||
|
||
class GlobalUserCache { | ||
private users: User[] = [] | ||
|
||
public get({ uid, username }: { uid?: string, username?: string }) { | ||
const user = this.users.find(user => user.uid === uid || user.username === username) | ||
return user | ||
} | ||
|
||
public set({ uid, username }: { uid?: string, username?: string }) { | ||
const user = new User({ uid, username }) | ||
this.users.push(user) | ||
return user | ||
} | ||
|
||
public update({ uid, username }: { uid?: string, username?: string }) { | ||
const user = this.get({ uid, username }) | ||
if (user) { | ||
user.uid = uid | ||
user.username = username | ||
|
||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
public async syncAllData({ uid, username }: { uid?: string, username?: string }) { | ||
const user = this.get({ uid, username }) | ||
if (!user || !user.username) throw new Error("user not found") | ||
|
||
const bot = bots.find(bot => bot.online) | ||
|
||
if (!bot) throw new Error("all bots offline") | ||
|
||
const profile = await bot.getUserProfile(user.username) | ||
if (!profile) throw new Error("user not found") | ||
|
||
user.data = profile | ||
|
||
return user | ||
} | ||
|
||
public getAll() { | ||
return this.users | ||
} | ||
} | ||
|
||
export default new GlobalUserCache() |
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
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
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,81 @@ | ||
export interface UserProfileCallback { | ||
email:string, | ||
location:string, | ||
website:string, | ||
hobby:string, | ||
intro:string, | ||
background: string, | ||
music: string, | ||
lastLoginTime: Date, | ||
visits: string, | ||
title: string, | ||
rooms: string[], | ||
tags: string, | ||
regTime: Date, | ||
online: string, | ||
credit: string, | ||
life: { | ||
image: string, | ||
time: Date, | ||
desc: string | ||
}[], | ||
mate: { | ||
username: string | null, | ||
avatar: string | null, | ||
color: string | null | ||
}, | ||
money: { | ||
hold: string, | ||
bank: string | ||
}, | ||
like: { | ||
times: number, | ||
users: string[] | ||
} | ||
} | ||
|
||
export default (message: string) => { | ||
if (message.substring(0, 2) === '+1') { | ||
const tmp = message.substring(2).split('>') | ||
const msg: UserProfileCallback = { | ||
email: tmp[0], | ||
location: tmp[4], | ||
website: tmp[5], | ||
hobby: tmp[6], | ||
intro: tmp[8], | ||
background: tmp[9], | ||
music: tmp[11], | ||
lastLoginTime: new Date(Number(tmp[12]) * 1e3), | ||
visits: tmp[13], | ||
title: tmp[14], | ||
rooms: tmp[21].split('"'), | ||
tags: tmp[22], | ||
regTime: new Date(Number(tmp[24]) * 1e3), | ||
online: tmp[25], | ||
credit: tmp[32], | ||
life: tmp[31].split('<').map(e => { | ||
const data = { | ||
image: `http${e.split(' ')[0]}`, | ||
time: new Date(Number(e.split(' ')[1]) * 1e3), | ||
desc: e.split(' ').splice(2).join(' ') | ||
} | ||
return data | ||
}), | ||
mate: { | ||
username: tmp[23] ? tmp[23].split('<')[0] : null, | ||
avatar: tmp[23] ? tmp[23].split('<')[1] : null, | ||
color: tmp[23] ? tmp[23].split('<')[2] : null | ||
}, | ||
money: { | ||
hold: tmp[17], | ||
bank: tmp[33] | ||
}, | ||
like: { | ||
times: Number(tmp[16].split('"')[0]), | ||
users: tmp[16].split('"')[1].split("'") | ||
} | ||
} | ||
|
||
return [['UserProfileCallback', msg]] | ||
} | ||
} |
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,3 @@ | ||
export default (username: string) => { | ||
return `+-${username}` | ||
} |
Oops, something went wrong.