示例#1
0
        private static async Task Discord_Ready(ReadyEventArgs e)
        {
            var guild         = e.Client.Guilds.First().Value;
            var existingUsers = Service.Context.Member.Select(x => x.ID).ToArray();
            var users         = await guild.GetAllMembersAsync();

            var newUsers = users.Where(x => !existingUsers.Contains((long)x.Id));

            Service.Context.Member.InsertDiscordMember(newUsers);
            var channel = await DiscordClient.GetDefaultChannelAsync();

            await DiscordClient.UpdateStatusAsync(DiscordGameExtension.GetRandomActivity());

            //Service.Context.Member.RecalcLevel();
            await channel.SendDisposableMessageAsync($@"{e.Client.CurrentUser.Mention} พร้อมรับใช้ขอรับ");
        }
示例#2
0
        private static async Task Discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            try
            {
                if (e.User.Id == DiscordClient.CurrentUser.Id)
                {
                    return;
                }
                if (e.Channel == null)
                {
                    currentlyOnVoiceChannelUsers.Remove(e.User.Id);
                    var ch = await DiscordClient.GetDefaultChannelAsync();

                    await ch.SendDisposableMessageAsync($"{e.User.Mention} ออกจากห้องแล้ว");
                }
                else if (e.Channel != null && !currentlyOnVoiceChannelUsers.Contains(e.User.Id))
                {
                    currentlyOnVoiceChannelUsers.Add(e.User.Id);
                    var ch = await DiscordClient.GetDefaultChannelAsync();

                    var voiceCh = ch.Guild.Channels.FirstOrDefault(x => x.Value.Type == ChannelType.Voice && x.Value.Id == AppConfiguration.Content.Discord.ActiveVoiceChannelId);
                    if (e.Channel?.Id == voiceCh.Value?.Id)
                    {
                        {
                            await ch.SendDisposableMessageAsync($@"ยินดีต้อนรับกลับมาขอรับ {e.User.Mention}!");
                        }
                    }
                }
                if (currentlyOnVoiceChannelUsers.Count > 0)
                {
                    await DiscordClient.UpdateStatusAsync(new DiscordActivity()
                    {
                        Name = $"กำลังดูแลแขก {currentlyOnVoiceChannelUsers.Count} ท่านในขณะนี้"
                    });;
                }
                else
                {
                    await DiscordClient.UpdateStatusAsync(DiscordGameExtension.GetRandomActivity());
                }
                Console.WriteLine($"[VoiceState] : Trigger by {e.User.Id}");
            }
            catch (Exception ex)
            {
                Service.Context.ExceptionLog.Insert(new Models.ExceptionLog(nameof(Discord_VoiceStateUpdated), ex));
            }
        }