Example #1
0
        internal async Task AutoJoinAudioAsync(Discord.IGuild srv)
        {
            await Task.Delay(666);

            foreach (Discord.IVoiceChannel c in await srv.GetVoiceChannelsAsync())
            {
                if (c.Name.Equals(MusicChannel, System.StringComparison.OrdinalIgnoreCase))
                {
                    await JoinAudioAsync(c);

                    break;
                }
            }
        }
Example #2
0
        public static async Task <string> ResolveIds(this Discord.IGuild guild, string text)
        {
            var words = text.Split(' ');

            for (var i = 0; i < words.Length; i++)
            {
                var word         = words[i];
                var channelMatch = Regex.Match(word, ChannelIdPattern);
                var userMatch    = Regex.Match(word, UserIdPattern);
                if (channelMatch.Success)
                {
                    var success = ulong.TryParse(channelMatch.Groups[1].Value, out ulong id);
                    if (!success)
                    {
                        continue;
                    }
                    var channel = await guild.GetChannelAsync(id);

                    if (channel != null)
                    {
                        words[i] = $"#{channel.Name}";
                    }
                }
                else if (userMatch.Success)
                {
                    var success = ulong.TryParse(userMatch.Groups[1].Value, out ulong id);
                    if (!success)
                    {
                        continue;
                    }
                    var user = await guild.GetUserAsync(id);

                    if (user != null)
                    {
                        words[i] = user.Nickname ?? user.Username;
                    }
                }
            }

            return(string.Join(' ', words));
        }
Example #3
0
        private string Remote(CultureInfo ci, StringWriter sw, string assembly, string args, Discord.IGuildUser sender, Discord.IGuild server, Discord.ITextChannel channel)
        {
            CultureInfo.DefaultThreadCurrentCulture   = ci;
            CultureInfo.DefaultThreadCurrentUICulture = ci;
            Console.SetOut(sw);
            Console.SetError(sw);
            Assembly      script = Assembly.LoadFrom(assembly);
            MethodInfo    method = script.GetType("DuckBot.Script").GetMethod("Code");
            Task <string> task   = Task.Run(() => (string)method.Invoke(null, new object[] { args, sender, server, channel }));

            return(task.Wait(90000) ? task.GetAwaiter().GetResult() : throw new TargetInvocationException(null));
        }