public static async Task LevelsClient_VoiceStateUpdated(DiscordClient sender, VoiceStateUpdateEventArgs voiceStateUpdateEventArgs) { if (voiceStateUpdateEventArgs.User.IsBot) { return; } var oldChannel = voiceStateUpdateEventArgs.Before; var newChannel = voiceStateUpdateEventArgs.After; var now = DateTime.UtcNow.ToString("yyyy-MM-dd hh:mm"); if (oldChannel == null && newChannel != null) { Level.Logger.LogDebug($"{voiceStateUpdateEventArgs.User.Id} has joined VC {voiceStateUpdateEventArgs.Channel.Name}[{voiceStateUpdateEventArgs.Channel.Id}]"); await DatabaseActions.SetUserInCall(voiceStateUpdateEventArgs.User.Id.ToString(), now, true); return; } if (oldChannel != null && newChannel.Channel == null) { Level.Logger.LogDebug($"{voiceStateUpdateEventArgs.User.Id} is no longer in a voice channel"); var user = await DatabaseActions.GetUserExp(voiceStateUpdateEventArgs.User.Id, true); await DatabaseActions.SetUserInCall(voiceStateUpdateEventArgs.User.Id.ToString(), now, false); var diff = Convert.ToInt32((DateTime.Parse(now) - DateTime.Parse(user.Rows[0]["voice_last_join"].ToString() !)).TotalMinutes); decimal expToAdd = diff * LevelOptions.ExpPerVoiceMin; await DatabaseActions.GiveExp(voiceStateUpdateEventArgs.User.Id.ToString(), true, expToAdd); return; } Level.Logger.LogDebug($"{voiceStateUpdateEventArgs.User.Id} is still in VC, doing nothing"); return; }
public async Task GetUserVoiceLevel(CommandContext ctx) { var user = DatabaseActions.GetUserExp(ctx.User.Id, true).Result; if (user == null) { return; } var args = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("Level", user.Rows[0]["level"].ToString()), new KeyValuePair <string, string>("Exp", user.Rows[0]["voice_exp"].ToString()) }; var avatar = ctx.Member.AvatarUrl; if (user.Rows[0]["badgeImageUrl"] != DBNull.Value) { avatar = user.Rows[0]["badgeImageUrl"].ToString(); } DiscordEmbed embed = LevelTasks.BuildEmbedTask("Voice Exp!", "Levels!", ctx.Guild.IconUrl, args, avatar); await ctx.RespondAsync(embed : embed); }