-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from nanoeray/feature/voiceStatistics
Feature/voice statistics
- Loading branch information
Showing
7 changed files
with
114 additions
and
22 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
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,44 @@ | ||
import { GuildMemberVoiceModel } from "../models/GuildMemberVoiceModel"; | ||
import { VoiceState } from "discord.js"; | ||
|
||
const VoiceStateUpdateEvent: SlashLevel.IEvent = { | ||
name: "voiceStateUpdate", | ||
execute: async (client,oldState:VoiceState, newState:VoiceState) => { | ||
const member = oldState.member || newState.member; | ||
if (!member) return; | ||
|
||
if (!newState.channel && oldState.channel) { | ||
const joinedTimestamp = client.voiceUsers.get(member.id); | ||
if (!joinedTimestamp) return; | ||
const totalTime = new Date().getTime() - joinedTimestamp; | ||
const dateObj = new Date(); | ||
const month = dateObj.getUTCMonth() + 1; | ||
const year = dateObj.getUTCFullYear(); | ||
const newDate = `${year}/${month}`; | ||
let voiceModel = await GuildMemberVoiceModel.findOne({ | ||
guildID: member.guild.id, | ||
userID: member.id, | ||
month: newDate | ||
}); | ||
if (!voiceModel) { | ||
voiceModel = await GuildMemberVoiceModel.create({ | ||
guildID: member.guild.id, | ||
userID: member.user.id, | ||
time: totalTime, | ||
month: newDate | ||
}); | ||
} else { | ||
voiceModel.time = voiceModel.time + totalTime; | ||
} | ||
await voiceModel.save(); | ||
|
||
} else if (!oldState.channel && newState.channel) { | ||
|
||
const time = new Date().getTime(); | ||
client.voiceUsers.set(member.id, time); | ||
} else { | ||
} | ||
} | ||
}; | ||
|
||
export default VoiceStateUpdateEvent; |
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,35 @@ | ||
import {Schema, model, Document} from "mongoose"; | ||
|
||
export interface IGuildMemberVoiceModel extends Document { | ||
guildID: string; | ||
userID: string; | ||
time: number; | ||
month: string; | ||
} | ||
|
||
export const GuildMemberVoiceSchema = new Schema<IGuildMemberVoiceModel>({ | ||
guildID: { | ||
type: String, | ||
required: true, | ||
}, | ||
userID: { | ||
type: String, | ||
required: true, | ||
}, | ||
time: { | ||
type: Number, | ||
required: true, | ||
default: 0, | ||
}, | ||
month: { | ||
type: String, | ||
required: true, | ||
default: '0', | ||
}, | ||
}); | ||
|
||
export const GuildMemberVoiceModel = model<IGuildMemberVoiceModel>( | ||
"guildMemberVoiceModel", | ||
GuildMemberVoiceSchema, | ||
"GUILD_MEMBER_VOICE_COLLECTION", | ||
); |
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