Example #1
0
        public async Task DisplayAsync()
        {
            if (Context != null)
            {
                Message = await Context.Channel.SendMessageAsync(_actioner.Content, embed : _actioner.Embed).ConfigureAwait(false);
            }
            else if (TextChannel != null)
            {
                Message = await TextChannel.SendMessageAsync(_actioner.Content, embed : _actioner.Embed).ConfigureAwait(false);
            }
            else
            {
                Message = await Client.GetGuild(GuildId).GetTextChannel(ChannelId).SendMessageAsync(_actioner.Content, embed: _actioner.Embed).ConfigureAwait(false);
            }

            ExtendedInteractive.AddReactionCallback(Message, this);
            ExtendedInteractive.AddReactionRemovedCallback(Message, this);

            _ = Task.Run(async() =>
            {
                foreach (var emoteAction in _actioner.EmoteActions)
                {
                    await Message.AddReactionAsync(emoteAction.Emote);
                }
            });

            if (Timeout.HasValue)
            {
                _ = Task.Delay(Timeout.Value).ContinueWith(_ =>
                {
                    ExtendedInteractive.RemoveReactionCallback(Message);
                    _ = Message.DeleteAsync();
                });
            }
        }
Example #2
0
        private async Task SendMessage(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }

            using (var releaser = await _MessageUpdateLock.LockAsync())
            {
                try
                {
                    NowSendingMessage.Value = true;
                    var userMessage = await TextChannel.SendMessageAsync(message);

                    SendMessageText.Value = "";
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.ToString());
                }
                finally
                {
                    NowSendingMessage.Value = false;
                }
            }
        }
Example #3
0
        static async Task Main(string[] args)
        {
            if (args.Length == 4)
            {
                guildId        = ulong.Parse(args[0]);
                voiceChannelId = ulong.Parse(args[1]);
                textChannelId  = ulong.Parse(args[2]);

                MediaFoundationApi.Startup();
                Config conf = JsonConvert.DeserializeObject <Config>(File.ReadAllText(args[3]));
                conf.AdditionalPluginDirectories.Clear();
                conf.AdditionalPluginDirectories.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

                BotContext context = new BotContext(conf, true)
                {
                    SingleGuild = guildId
                };
                context.LogMessage            += Context_LogMessage;
                context.DSharpPlusLogMessage  += Context_DSharpPlusLogMessage;
                context.Client.GuildAvailable += Client_GuildAvailable;
                await context.ConnectAsync().ConfigureAwait(false);

                while (!ready)
                {
                    await Task.Delay(1000);
                }

                VoiceExtension = context.Client.UseVoiceNext(new VoiceNextConfiguration()
                {
                    VoiceApplication = VoiceApplication.Music, EnableIncoming = true
                });

                Guild = await context.Client.GetGuildAsync(guildId);

                Console.WriteLine(Guild);

                VoiceChannel = Guild.Channels.FirstOrDefault(c => c.Id == voiceChannelId);
                Console.WriteLine(VoiceChannel);
                TextChannel = Guild.Channels.FirstOrDefault(c => c.Id == textChannelId);
                Console.WriteLine(TextChannel);

                var connection = await VoiceExtension.ConnectAsync(VoiceChannel).ConfigureAwait(false);

                ConnectionModel = new ConnectionModel(connection);
                await TextChannel.SendMessageAsync($"Connected to {VoiceChannel.Name}!");

                await MusicPlayLoop(TextChannel, ConnectionModel);
            }
            else
            {
                Console.WriteLine("This is an internal tool to be used by WamBot's music commands. Use outside will cause unexpected results and is not recommended.");
                Console.Write("Press any key to exit...");
                Console.ReadKey(true);
                Environment.Exit(0);
            }
        }