public async Task SeeLevel([Remainder, Name("유저")] SocketGuildUser user = null) { if (user == null) { user = Context.User as SocketGuildUser; } OliveGuild guild = OliveGuild.Get(Context.Guild.Id); string UserId = user.Id.ToString(); if (!guild.Levels.ContainsKey(UserId)) { guild.Levels.Add(UserId, new OliveGuild.UserLevel()); OliveGuild.Set(Context.Guild.Id, g => g.Levels, guild.Levels); } EmbedBuilder emb = Context.CreateEmbed(title: $"{user.GetName(false)}님의 레벨"); emb.AddField("level", guild.Levels[UserId].Level, true); emb.AddField("xp", guild.Levels[UserId].Xp, true); int totalXp = Utility.GetLevelXp(guild.Levels[UserId].Level); emb.AddField($"레벨업까지 남은 xp: {totalXp - guild.Levels[UserId].Xp}", $"{guild.Levels[UserId].Xp} [{new string(Enumerable.Repeat('■', (int)Math.Round(guild.Levels[UserId].Xp / (float)totalXp * 10)).ToArray())}{new string(Enumerable.Repeat('□', (int)Math.Round((totalXp - guild.Levels[UserId].Xp) / (float)totalXp * 10)).ToArray())}] {totalXp}"); await Context.MsgReplyEmbedAsync(emb.Build()); }
public async Task Disable([Name("카테고리")] string category) { if (!CategoryNames.Contains(category)) { await Context.MsgReplyEmbedAsync($"알 수 없는 카테고리에요\n{string.Join(", ", CategoryNames.Select(c => $"`{c}`"))} 중 하나를 선택할 수 있어요"); return; } OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; CategoryType cat = StringToCategory(category); if (cat == CategoryType.Setting) { await Context.MsgReplyEmbedAsync($"비활성화 할 수 없는 카테고리에요"); return; } if (!setting.EnabledCategories.Contains(cat)) { await Context.MsgReplyEmbedAsync($"이미 비활성화돼있는 카테고리에요"); return; } setting.EnabledCategories.Remove(cat); OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"{category} 카테고리를 비활성화했어요"); }
public async Task SetLevelUpChannel([Remainder, Name("채널")] SocketTextChannel channel) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; setting.LevelUpChannelId = channel.Id; OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"이제 레벨업 메시지가 {channel.Mention} 채널에 보내져요"); }
public async Task SetLogChannel([Remainder, Name("채널")] SocketTextChannel channel) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; setting.LogChannelId = channel.Id; OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"로그 채널을 {channel.Name.으로()} 설정했어요"); }
public async Task AddLevelRole([Name("레벨")] int level, [Remainder, Name("역할")] SocketRole role) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; if (setting.LevelRoles.ContainsKey(level.ToString())) { await Context.MsgReplyEmbedAsync("해당 레벨의 역할이 이미 설정돼있어요"); return; } setting.LevelRoles.Add(level.ToString(), role.Id); OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"이제 {level} 레벨이 되면 {role.Mention} 역할을 얻을 수 있어요"); }
public async Task RemoveNonXpChannel([Name("채널")] SocketTextChannel channel) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; if (!setting.NonXpChannels.Contains(channel.Id)) { await Context.MsgReplyEmbedAsync("해당 채널은 레벨업 불가 채널이 아니에요"); return; } setting.NonXpChannels.Remove(channel.Id); OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"이제 {channel.Mention}에서 메시지를 보내면 xp가 올라요"); }
public async Task AddNonXpChannel([Name("채널")] SocketTextChannel channel) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; if (setting.NonXpChannels.Contains(channel.Id)) { await Context.MsgReplyEmbedAsync("해당 채널은 이미 레벨업 불가 채널이에요"); return; } setting.NonXpChannels.Add(channel.Id); OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"이제 {channel.Mention} 채널에서는 xp가 오르지 않아요"); }
public async Task ResetLevelUpChannel() { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; if (!setting.LevelUpChannelId.HasValue) { await Context.MsgReplyEmbedAsync("레벨업 채널이 설정되지 않아서 초기화 할 수 없어요"); return; } setting.LevelUpChannelId = null; OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"레벨업 채널을 초기화했어요"); }
public async Task RemoveLevelRole([Name("레벨")] int level) { OliveGuild.GuildSetting setting = OliveGuild.Get(Context.Guild.Id).Setting; if (!setting.LevelRoles.ContainsKey(level.ToString())) { await Context.MsgReplyEmbedAsync("해당 레벨에 설정된 역할이 없어요"); return; } setting.LevelRoles.Remove(level.ToString()); OliveGuild.Set(Context.Guild.Id, g => g.Setting, setting); await Context.MsgReplyEmbedAsync($"{level} 레벨의 역할을 제거했어요"); }
public static async Task OnMessageReceived(SocketMessage msg) { if (msg is not SocketUserMessage userMsg || userMsg.Content == null || userMsg.Author.Id == Program.Client.CurrentUser.Id || userMsg.Author.IsBot) { return; } SocketCommandContext context = new SocketCommandContext(Program.Client, userMsg); if (await Games.WordRelay(context)) { return; } if (await Games.TypingGame(context)) { return; } int argPos = 0; if (userMsg.HasStringPrefix(prefix, ref argPos) || userMsg.HasMentionPrefix(Program.Client.CurrentUser, ref argPos)) { await Program.Command.ExecuteAsync(context, argPos, Program.Service); } if (context.IsPrivate) { return; } OliveGuild guild = OliveGuild.Get(context.Guild.Id); if (!guild.Setting.EnabledCategories.Contains(RequireCategoryEnable.CategoryType.Level)) { return; } if (guild.Setting.NonXpChannels.Contains(context.Channel.Id)) { return; } string UserId = context.User.Id.ToString(); if (guild.Levels.ContainsKey(UserId)) { guild.Levels[UserId].Xp++; if (guild.Levels[UserId].Xp >= Utility.GetLevelXp(guild.Levels[UserId].Level)) { guild.Levels[UserId].Level++; guild.Levels[UserId].Xp = 0; string lv = guild.Levels[UserId].Level.ToString(); if (guild.Setting.LevelUpChannelId.HasValue && context.Guild.Channels.Any(c => c.Id == guild.Setting.LevelUpChannelId.Value)) { SocketTextChannel c = context.Guild.GetTextChannel(guild.Setting.LevelUpChannelId.Value); await c.SendMessageAsync($"{context.User.Mention}님, {lv}레벨이 되신걸 축하해요! :tada:"); } else { await context.MsgReplyEmbedAsync($"{context.User.Mention}님, {lv}레벨이 되신걸 축하해요! :tada:", disalbeMention : false); } if (guild.Setting.LevelRoles.ContainsKey(lv) && context.Guild.Roles.Any(r => r.Id == guild.Setting.LevelRoles[lv])) { await(context.User as SocketGuildUser).AddRoleAsync(context.Guild.GetRole(guild.Setting.LevelRoles[lv])); } } } else { guild.Levels.Add(UserId, new OliveGuild.UserLevel()); guild.Levels[UserId].Xp++; } OliveGuild.Set(context.Guild.Id, g => g.Levels, guild.Levels); }