当前位置: 首页>>代码示例>>C#>>正文


C# DiscordClient.GetService方法代码示例

本文整理汇总了C#中Discord.DiscordClient.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# DiscordClient.GetService方法的具体用法?C# DiscordClient.GetService怎么用?C# DiscordClient.GetService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Discord.DiscordClient的用法示例。


在下文中一共展示了DiscordClient.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

		void IModule.Install(ModuleManager manager)
		{
			_manager = manager;
			_client = manager.Client;
			_http = _client.GetService<HttpService>();
			_settings = _client.GetService<SettingsService>()
				.AddModule<StatusModule, Settings>(manager);

			manager.CreateCommands("status", group =>
			{
				group.MinPermissions((int)PermissionLevel.BotOwner);

				group.CreateCommand("enable")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        Channel channel;
                        if (e.Args[0] != "")
                            channel = await _client.FindChannel(e, e.Args[0], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        settings.Channel = channel.Id;
                        await _settings.Save(e.Server, settings);

						await _client.Reply(e, $"Enabled status reports in {channel.Name}");
					});
                group.CreateCommand("disable")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        settings.Channel = null;
                        await _settings.Save(e.Server, settings);

                        await _client.Reply(e, "Disabled status reports on this server.");
                    });
			});

			_client.Ready += (s, e) =>
			{
				if (!_isRunning)
				{
					Task.Run(Run);
					_isRunning = true;
				}
			};
		}
开发者ID:RogueException,项目名称:DiscordBot,代码行数:51,代码来源:StatusModule.cs

示例2: Create

        public static async Task<BttvChannelEmoteSource> Create(DiscordClient client, string channel)
        {
            try
            {
                if (!ChannelNameValidatorRegex.IsMatch(channel))
                    return null;

                HttpContent content =
                    await client.GetService<HttpService>().Send(HttpMethod.Get, $"{DataSource}{channel}");
                JObject result = JObject.Parse(await content.ReadAsStringAsync());

                if (result.GetValue("status").ToObject<int>() != 200)
                    return null;

                return new BttvChannelEmoteSource(channel, result);
            }
            catch (HttpException)
            {
            }
            return null;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:21,代码来源:BttvChannelEmoteSource.cs

示例3: ShowDialog

        public override async void ShowDialog()
        {
            LoginDialog dialog = new LoginDialog();

            if (dialog.ShowDialog() == true)
            {
                _client = new DiscordClient();
                _client.UsingAudio(x =>
                {
                    x.Mode = AudioMode.Outgoing;
                    x.Bitrate = null;
                    x.Channels = 2;
                });

                await _client.Connect(dialog.Username, dialog.Password);
                var voiceChannel = CurrentServer.VoiceChannels.FirstOrDefault(d => d.Name == "Bot Test");

                _voiceClient = await _client.GetService<AudioService>()
                    .Join(voiceChannel);
            }
        }
开发者ID:jmazouri,项目名称:Picofy,代码行数:21,代码来源:PicofyDiscord.cs

示例4: InvalidOperationException

        void IModule.Install(ModuleManager manager)
        {
            _client = manager.Client;
            _moduleService = _client.GetService<ModuleService>();

            manager.CreateDynCommands("module", PermissionLevel.ServerAdmin, group =>
            {
                group.AddCheck((cmd, usr, chnl) => !chnl.IsPrivate);

                group.CreateCommand("channel enable")
                    .Description("Enables a module on the current channel.")
                    .Parameter("module", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        ModuleManager module = await VerifyFindModule(e.GetArg("module"), e.Channel);
                        if (module == null) return;

                        if (!await CanChangeModuleStateInServer(module, ModuleFilter.ChannelWhitelist, e))
                            return;

                        Channel channel = e.Channel;

                        if (!module.EnableChannel(channel))
                        {
                            await
                                e.Channel.SafeSendMessage(
                                    $"Module `{module.Id}` was already enabled for channel `{channel.Name}`.");
                            return;
                        }
                        _channelModulesDictionary.AddModuleToSave(module.Id, e.Channel.Id);
                        await
                            e.Channel.SafeSendMessage($"Module `{module.Id}` was enabled for channel `{channel.Name}`.");
                    });

                group.CreateCommand("channel disable")
                    .Description("Disable a module on the current channel.")
                    .Parameter("module", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        ModuleManager module = await VerifyFindModule(e.GetArg("module"), e.Channel);
                        if (module == null) return;

                        if (!await CanChangeModuleStateInServer(module, ModuleFilter.ChannelWhitelist, e, false))
                            return;

                        Channel channel = e.Channel;

                        if (!module.DisableChannel(channel))
                        {
                            await
                                e.Channel.SafeSendMessage(
                                    $"Module `{module.Id}` was not enabled for channel `{channel.Name}`.");
                            return;
                        }
                        _channelModulesDictionary.DeleteModuleFromSave(module.Id, e.Channel.Id);
                        await
                            e.Channel.SafeSendMessage($"Module `{module.Id}` was disabled for channel `{channel.Name}`.");
                    });

                group.CreateCommand("server enable")
                    .Description("Enables a module on the current server.")
                    .Parameter("module", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        ModuleManager module = await VerifyFindModule(e.GetArg("module"), e.Channel);
                        if (module == null) return;

                        if (!await CanChangeModuleStateInServer(module, ModuleFilter.ServerWhitelist, e))
                            return;

                        Server server = e.Server;

                        if (!module.EnableServer(server))
                        {
                            await
                                e.Channel.SafeSendMessage(
                                    $"Module `{module.Id}` was already enabled for server `{server.Name}`.");
                            return;
                        }
                        _serverModulesDictionary.AddModuleToSave(module.Id, e.Server.Id);
                        await e.Channel.SafeSendMessage($"Module `{module.Id}` was enabled for server `{server.Name}`.");
                    });
                group.CreateCommand("server disable")
                    .Description("Disables a module for the current server.")
                    .Parameter("module", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        ModuleManager module = await VerifyFindModule(e.GetArg("module"), e.Channel);
                        if (module == null) return;

                        if (!await CanChangeModuleStateInServer(module, ModuleFilter.ServerWhitelist, e, false))
                            return;

                        Server server = e.Server;

                        if (!module.DisableServer(server))
                        {
                            await
                                e.Channel.SafeSendMessage(
                                    $"Module `{module.Id}` was not enabled for server `{server.Name}`.");
//.........这里部分代码省略.........
开发者ID:SSStormy,项目名称:Stormbot,代码行数:101,代码来源:ModulesModule.cs

示例5: foreach

        void IModule.Install(ModuleManager manager)
        {
            _client = manager.Client;
            _http = _client.GetService<HttpService>();

            Task.Run(async () =>
            {
                foreach (EmoteSourceBase source in _emoteSources)
                {
                    try
                    {
                        await source.DownloadData(_http);
                    }
                    catch (Exception ex)
                    {
                        Logger.FormattedWrite(
                            GetType().Name,
                            $"Failed loading emotes for {source.GetType().Name}. Exception: {ex}");
                    }
                }
                GC.Collect();
            });

            manager.CreateDynCommands("bttv", PermissionLevel.User, group =>
            {
                group.CreateCommand("")
                    .Parameter("channel")
                    .Description("Add a BTTV channel to the emote sources.")
                    .Do(async e =>
                    {
                        string channel = e.GetArg("channel");

                        if (_bttvChannelEmoteSources.FirstOrDefault(s => s.Channel == channel) != null)
                        {
                            await e.Channel.SendMessage("This channel is already in the emote source list.");
                            return;
                        }

                        BttvChannelEmoteSource source = await BttvChannelEmoteSource.Create(_client, channel);
                        if (source == null)
                        {
                            await e.Channel.SafeSendMessage("Failed getting emote data.");
                            return;
                        }

                        _bttvChannelEmoteSources.Add(source);
                        await e.Channel.SafeSendMessage($"Added channel {channel} to the emote source.");
                    });
            });

            manager.CreateDynCommands("emote", PermissionLevel.User, group =>
            {
                group.CreateCommand("")
                    .Parameter("emote", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        string emotePath = await ResolveEmoteDir(e.GetArg("emote"));

                        if (!File.Exists(emotePath))
                            return; // todo : lower case == upper case in this case. KAPPA = Kappa

                        await e.Channel.SafeSendFile(emotePath);
                    });
            });
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:65,代码来源:TwitchEmoteModule.cs

示例6: CommandExists

        public static bool CommandExists(DiscordClient client, string query)
        {
            query = query.ToLowerInvariant();

            foreach (Command cmd in client.GetService<CommandService>().AllCommands)
            {
                if (cmd.Text.ToLowerInvariant().StartsWith(query))
                    return true;

                foreach (string alias in cmd.Aliases)
                    if (alias.ToLowerInvariant().StartsWith(query))
                        return true;
            }
            return false;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:15,代码来源:Utils.cs

示例7: Start

        public void Start()
        {
            Console.WriteLine("Initializing...");
            _client = new DiscordClient();

            _client.UsingAudio(x => // Opens an AudioConfigBuilder so we can configure our AudioService
            { x.Mode = AudioMode.Outgoing; // Tells the AudioService that we will only be sending audio
            });

            // _vClient = _client.GetService<AudioService>();

            _client.MessageReceived += async (s, e) =>
            {
                if (!e.Message.IsAuthor)
                {
                    Console.WriteLine(e.Message.User.Name + "> " + e.Message.Text);
                    if (e.Message.Text.StartsWith("!!"))
                    {
                        string command = e.Message.Text.Replace("!!", "");
                        //   if (command.Equals(""))
                        //      {
                        //                 await e.Channel.SendMessage("I am Jukebot. Do !!info for more details.");
                        //
                        //          }
                        string[] words = command.Split(' ');
                        switch (words[0])
                        {
                            case "info":
                                await
                                    e.Channel.SendMessage(
                                        "```diff\n!====== [Jukebot] ======!" +
                                        "\nA shitty ass music bot made by Ratismal (stupid cat)" +
                                        "\nIt plays music. lol what did u expect" +
                                        "\n!== [Features] ==!" +
                                        "\n+ a shitty looking unintuitive piece of shit GUI that only the host can see (lol)" +
                                        "\n+ plays music" +
                                        "\n!== [Commands] ==!" +
                                        "\n+ !!info - shows this" +
                                        "\n+ !!summon - summons bot to current voice channel" +
                                        "\n+ !!banish - tells the bot to piss off" +
                                        "\n+ !!volume - shows the current volume" +
                                        "\n+ !!volume <amount> - set the volume" +
                                        "\n+ !!volume +-<amount> - add/subtract the volume" +
                                        "\n!== [Conclusi] ==!" +
                                        "\n+ '-on' cut off from title for consistancy spacing sake" +
                                        "\n+ fuck my life" +
                                        "\n+ you want to play something? GOOD LUCK WITH THAT LOL ONLY I CAN" +
                                        "\n- This is red text!" +
                                        "\n- its really late i should go to bed lol fml smfh lmao kms" +
                                        "\n```");
                                break;
                            case "summon":
                                Console.WriteLine("Joining a voice channel");
                                await e.Channel.SendMessage("Joining channel");
                                var voiceChannel = e.User.VoiceChannel;
                                _vClient = await _client.GetService<AudioService>().Join(voiceChannel);
                                //await _vClient.Join(voiceChannel);
                                break;
                            case "banish":
                                Console.WriteLine("Leaving a voice channel");

                                await e.Channel.SendMessage("Leaving channel");
                                await _client.GetService<AudioService>().Leave(e.Server);
                                break;
                            case "volume":
                                if (words.Length == 1)
                                {
                                    e.Channel.SendMessage("Current volume: " + MainWindow.volume);
                                }
                                else
                                {
                                    //  string goodstuff;
                                    if (words[1].StartsWith("+") || words[1].StartsWith("-"))
                                    {
                                        int addVolume = Int32.Parse(words[1]);
                                        MainWindow.volume += addVolume;
                                        e.Channel.SendMessage("New volume: " + MainWindow.volume);
                                    }
                                    else
                                    {
                                        MainWindow.volume = Int32.Parse(words[1]);
                                        e.Channel.SendMessage("New volume: " + MainWindow.volume);
                                    }
                                }

                                break;
                            default:
                                await e.Channel.SendMessage("I am Jukebot. Do !!info for more details.");
                                break;
                        }
                    }
                }
            };

            _client.ExecuteAndWait(async () =>
            {
                await
                    _client.Connect(token
                        );
            });
//.........这里部分代码省略.........
开发者ID:Ratismal,项目名称:jukebot,代码行数:101,代码来源:MainWindow.xaml.cs

示例8: StringBuilder

        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            _http = _client.GetService<HttpService>();
            _settings = _client.GetService<SettingsService>()
                .AddModule<TwitchModule, Settings>(manager);

            manager.CreateCommands("streams", group =>
            {
                group.MinPermissions((int)PermissionLevel.BotOwner);

                group.CreateCommand("list")
                    .Do(async e =>
                    {
                        StringBuilder builder = new StringBuilder();
                        var settings = _settings.Load(e.Server);
                        foreach (var channel in settings.Channels)
                            builder.AppendLine($"{_client.GetChannel(channel.Key)}:\n   {string.Join(", ", channel.Value.Streams.Select(x => x.Key))}");
                        await _client.Reply(e, "Linked Streams", builder.ToString());
                    });

                group.CreateCommand("add")
                    .Parameter("twitchuser")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);

                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        var channelSettings = settings.GetOrAddChannel(channel.Id);
                        if (channelSettings.AddStream(e.Args[0]))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Linked stream {e.Args[0]} to {channel.Name}.");
                        }
                        else
                            await _client.Reply(e, $"Stream {e.Args[0]} is already linked to {channel.Name}.");
                    });

                group.CreateCommand("remove")
                    .Parameter("twitchuser")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        var channelSettings = settings.GetOrAddChannel(channel.Id);
                        if (channelSettings.RemoveStream(e.Args[0]))
                        {
                            await _settings.Save(e.Server.Id, settings);
                            await _client.Reply(e, $"Unlinked stream {e.Args[0]} from {channel.Name}.");
                        }
                        else
                            await _client.Reply(e, $"Stream {e.Args[0]} is not currently linked to {channel.Name}.");
                    });

                group.CreateGroup("set", set =>
                {
                    set.CreateCommand("sticky")
                        .Parameter("value")
                        .Parameter("channel", ParameterType.Optional)
                        .Do(async e =>
                        {
                            bool value = false;
                            bool.TryParse(e.Args[0], out value);

                            Channel channel;
                            if (e.Args[1] != "")
                                channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                            else
                                channel = e.Channel;
                            if (channel == null) return;

                            var settings = _settings.Load(e.Server);
                            var channelSettings = settings.GetOrAddChannel(channel.Id);
                            if (channelSettings.UseSticky && !value && channelSettings.StickyMessageId != null)
                            {
                                var msg = channel.GetMessage(channelSettings.StickyMessageId.Value);
                                try { await msg.Delete(); }
                                catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
                            }
                            channelSettings.UseSticky = value;
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Stream sticky for {channel.Name} set to {value}.");
                        });
                });
            });
//.........这里部分代码省略.........
开发者ID:RogueException,项目名称:DiscordBot,代码行数:101,代码来源:TwitchModule.cs

示例9: BlacklistChecker

 internal BlacklistChecker(DiscordClient client)
 {
     _service = client.GetService<BlacklistService>(true);
 }
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:4,代码来源:BlacklistChecker.cs

示例10: Start

        public void Start()
        {

            _client = new DiscordClient(x=> {
                x.AppName = "CancerBot";
                x.MessageCacheSize = 10;
                x.EnablePreUpdateEvents = true;
            });
            _client.UsingPermissionLevels((u,c)=>  (int)CheckPermLevel(u,c));
            _client.UsingCommands(x => {
                x.PrefixChar = '>';
                x.HelpMode = HelpMode.Public;
                x.ErrorHandler += HandleError;
                x.AllowMentionPrefix = false;
            });

            var doc = new XmlDocument();
            try
            {
                doc.Load("commands.xml");
            }
            catch (FileNotFoundException e)
            {
                StreamWriter stream = new StreamWriter("commands.xml");
                XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>));
                xml1.Serialize(stream, new List<CustomCommand>());
                stream.Close();
            }

            catch (XmlException e)
            {

                StreamWriter stream = new StreamWriter("commands.xml");
                XmlSerializer xml1 = new XmlSerializer(typeof(List<CustomCommand>));
                xml1.Serialize(stream, new List<CustomCommand>());
                stream.Close();
            }
            CommandService commandService = _client.GetService<CommandService>();
            List<CustomCommand> commands = new List<CustomCommand>();
            XmlSerializer xml = new XmlSerializer(typeof(List<CustomCommand>));

            FileStream file = new FileStream("commands.xml", FileMode.OpenOrCreate);

            List<CustomCommand> list = (List<CustomCommand>)xml.Deserialize(file);
            file.Close();
            foreach(CustomCommand x in list)
            {
                if (forbodens.Contains<string>(x.Name)) { continue; }
                CommandBuilder b = _client.GetService<CommandService>().CreateCommand(x.Name.ToLower()). Description(x.Contents).Parameter("Cuntents", ParameterType.Unparsed); b.Do(async e =>
                {
                    
                    double deltatime = 5;
                    if (LastCommandTime.ContainsKey(e.User.Id))
                    {
                        deltatime = (DateTime.Now.Second - LastCommandTime[e.User.Id]);
                    }
                    if (deltatime >= 5)
                    {
                        await e.Channel.SendMessage(x.Contents);
                       
                    }
                    if (LastCommandTime.ContainsKey(e.User.Id))
                    {
                        LastCommandTime[e.User.Id] = DateTime.Now.Second;
                    }
                    else
                    {
                        LastCommandTime[e.User.Id] = DateTime.Now.Second;
                    }
                });
                try
                {
                    b._command.IsCustom = true;
                    commandBuilders.Add(x.Name.ToLower(), b);

                }

                catch { Console.WriteLine($"Command with name {x.Name} already exists!"); };
            }
            _client.GetService<CommandService>().CreateCommand("test23").Description("Test Command").Do(async e =>
            {
                await e.Channel.SendMessage("test");
            });
            //_client.Ready += (s, e) =>
            //{
            //    _client.FindServers("Discord Bots").First().FindChannels("testing-aloha").First().SendMessage("I'm alive!");
            //};
            commandService.CreateCommand("changename").Description("Changes Name").Parameter("Name", ParameterType.Unparsed).MinPermissions((int)PermissionLevel.ServerOwner)
            .Do(async e =>
            {

                await _client.CurrentUser.Edit("", e.GetArg("Name"));
                
            });
            
           // _client.UserBanned += async (s, e) =>
           // {

                //await e.Server.DefaultChannel.SendMessage(e.User.Name + " was banned forever LUUL");
            //};
//.........这里部分代码省略.........
开发者ID:thedanieldude1,项目名称:DanielCode,代码行数:101,代码来源:Program.cs

示例11:

        void IModule.Install(ModuleManager manager)
        {
            _manager = manager;
            _client = manager.Client;
            _http = _client.GetService<HttpService>();
            _settings = _client.GetService<SettingsService>()
                .AddModule<FeedModule, Settings>(manager);

            manager.CreateCommands("feeds", group =>
            {
                group.MinPermissions((int)PermissionLevel.BotOwner);

                group.CreateCommand("list")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        var response = settings.Feeds
                            .OrderBy(x => x.Key)
                            .Select(x => $"{x.Key} => {_client.GetChannel(x.Value.ChannelId)?.Name ?? "Unknown"}");
                        await _client.Reply(e, "Linked Feeds", response);
                    });

                group.CreateCommand("add")
                    .Parameter("url")
                    .Parameter("channel", ParameterType.Optional)
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        Channel channel;
                        if (e.Args[1] != "")
                            channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
                        else
                            channel = e.Channel;
                        if (channel == null) return;

                        if (settings.AddFeed(e.Args[0], channel.Id))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Linked feed {e.Args[0]} to {channel.Name}");
                        }
                        else
                            await _client.Reply(e, $"Feed {e.Args[0]} is already linked to a channel.");
                    });

                group.CreateCommand("remove")
                    .Parameter("url")
                    .Do(async e =>
                    {
                        var settings = _settings.Load(e.Server);
                        if (settings.RemoveFeed(e.Args[0]))
                        {
                            await _settings.Save(e.Server, settings);
                            await _client.Reply(e, $"Unlinked feed {e.Args[0]}.");
                        }
                        else
                            await _client.Reply(e, $"Feed {e.Args[0]} is not currently linked to a channel.");
                    });
            });

            _client.Ready += (s, e) =>
            {
                if (!_isRunning)
                {
                    Task.Run(Run);
                    _isRunning = true;
                }
            };
        }
开发者ID:RogueException,项目名称:DiscordBot,代码行数:68,代码来源:FeedModule.cs

示例12: Install

        public void Install(ModuleManager manager)
        {
            Nullcheck(Config.PastebinPassword, Config.PastebinUsername, Config.PastebinApiKey);

            _client = manager.Client;
            _dynPerms = _client.GetService<DynamicPermissionService>();
            _pastebin = _client.GetService<PastebinService>();

            manager.CreateCommands("dynperm", group =>
            {
                group.MinPermissions((int) PermissionLevel.ServerAdmin);

                group.AddCheck((cmd, usr, chnl) => !chnl.IsPrivate);

                group.CreateCommand("set")
                    .Description(
                        "Sets the dynamic permissions for this server.**Pastebin links are supported.**Use the dynperm help command for more info.")
                    .Parameter("perms", ParameterType.Unparsed)
                    .Do(async e =>
                    {
                        string input = e.GetArg("perms");
                        string error;

                        if (input.StartsWith(PastebinIdentifier))
                        {
                            string rawUrl = input.Insert(PastebinIdentifier.Length, RawPath);
                            input = await Utils.AsyncDownloadRaw(rawUrl);
                        }

                        DynPermFullData perms = _dynPerms.SetDynPermFullData(e.Server.Id, input, out error);

                        if (!string.IsNullOrEmpty(error))
                        {
                            await e.Channel.SendMessage($"Failed parsing Dynamic Permissions. {error}");
                            return;
                        }

                        await e.Channel.SendMessage($"Parsed Dynamic Permissions:\r\n```" +
                                                    $"- Role Rules: {perms.Perms.RolePerms.Count}\r\n" +
                                                    $"- User Rules: {perms.Perms.UserPerms.Count}```");
                    });

                // commands which can only be executed if the caller server has dynperms.
                group.CreateGroup("", existsGroup =>
                {
                    existsGroup.AddCheck((cmd, usr, chnl) => _dynPerms.GetPerms(chnl.Server.Id) != null);

                    existsGroup.CreateCommand("show")
                        .Description("Shows the Dynamic Permissions for this server.")
                        .Do(async e =>
                        {
                            DynPermFullData data = _dynPerms.GetPerms(e.Server.Id);

                            if (string.IsNullOrEmpty(data.PastebinUrl) || data.IsDirty)
                            {
                                if (!_pastebin.IsLoggedIn)
                                    await _pastebin.Login(Config.PastebinUsername, Config.PastebinPassword);

                                data.PastebinUrl = await _pastebin.Paste(new PastebinService.PasteBinEntry
                                {
                                    Expiration = PastebinService.PasteBinExpiration.Never,
                                    Format = "json",
                                    Private = true,
                                    Text = JsonConvert.SerializeObject(data.Perms),
                                    Title = $"{e.Server.Name}@{DateTime.Now}"
                                });
                            }

                            await e.Channel.SendMessage($"Paste: {data.PastebinUrl}");
                        });

                    existsGroup.CreateCommand("clear")
                        .Description(
                            "Clears the Dynamic Permissions. This cannot be undone. Pass yes as an argument for this to work.")
                        .Parameter("areyousure")
                        .Do(async e =>
                        {
                            string input = e.GetArg("areyousure").ToLowerInvariant();
                            if (input == "yes" ||
                                input == "y")
                            {
                                _dynPerms.DestroyServerPerms(e.Server.Id);
                                await e.Channel.SendMessage("Dynamic Permissions have been wiped.");
                            }
                        });
                });

                group.CreateCommand("help")
                    .Description("help")
                    .Do(
                        async e =>
                            await
                                e.Channel.SendMessage("https://github.com/SSStormy/Stormbot/blob/master/docs/dynperm.md"));
            });
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:95,代码来源:DynamicPermissionModule.cs

示例13: WhitelistChecker

 internal WhitelistChecker(DiscordClient client)
 {
     _service = client.GetService<WhitelistService>(true);
 }
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:4,代码来源:WhitelistChecker.cs

示例14: DynamicPermissionChecker

 public DynamicPermissionChecker(DiscordClient client, int defaultPerms)
 {
     DynPerms = client.GetService<DynamicPermissionService>();
     DefaultPermChecker = client.GetService<PermissionLevelService>();
     DefaultPermissionLevel = defaultPerms;
 }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:6,代码来源:DynamicPermissionChecker.cs

示例15: StringBuilder

		void IModule.Install(ModuleManager manager)
		{
			_manager = manager;
			_client = manager.Client;
			_http = _client.GetService<HttpService>();
			_settings = _client.GetService<SettingsService>()
				.AddModule<GithubModule, Settings>(manager);

			manager.CreateCommands("repos", group =>
			{
				group.MinPermissions((int)PermissionLevel.BotOwner);

				group.CreateCommand("list")
					.Do(async e =>
					{
						StringBuilder builder = new StringBuilder();
						var settings = _settings.Load(e.Server);
						foreach (var repo in settings.Repos.OrderBy(x => x.Key))
							builder.AppendLine($"{repo.Key} [{string.Join(",", repo.Value.Branches)}] => {_client.GetChannel(repo.Value.ChannelId)?.Name ?? "Unknown"}");
						await _client.Reply(e, "Linked Repos", builder.ToString());
					});

				group.CreateCommand("add")
					.Parameter("githubrepo")
					.Parameter("channel", ParameterType.Optional)
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						Channel channel;
						if (e.Args[1] != "")
							channel = await _client.FindChannel(e, e.Args[1], ChannelType.Text);
						else
							channel = e.Channel;
						if (channel == null) return;

						string url = FilterUrl(e.Args[0]);
						if (settings.AddRepo(url, channel.Id))
						{
							await _settings.Save(e.Server.Id, settings);
							await _client.Reply(e, $"Linked repo {url} to {channel.Name}.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is already being watched.");
					});

				group.CreateCommand("remove")
					.Parameter("githubrepo")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						if (settings.RemoveRepo(url))
						{
							await _settings.Save(e.Server.Id, settings);
							await _client.Reply(e, $"Unlinked repo {url}.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
					});

				group.CreateCommand("addbranch")
					.Parameter("githubrepo")
					.Parameter("branch")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						var repo = settings.Repos[url];
						if (repo != null)
						{
							if (repo.AddBranch(e.Args[1]))
							{
								await _settings.Save(e.Server.Id, settings);
								await _client.Reply(e, $"Added branch {url}/{e.Args[1]}.");
							}
							else
								await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is already being watched.");
						}
						else
							await _client.Reply(e, $"Error: Repo {url} is not currently being watched.");
					});

				group.CreateCommand("removebranch")
					.Parameter("githubrepo")
					.Parameter("branch")
					.Do(async e =>
					{
						var settings = _settings.Load(e.Server);
						string url = FilterUrl(e.Args[0]);
						var repo = settings.Repos[url];
						if (repo != null)
						{
							if (repo.RemoveBranch(e.Args[1]))
							{
								await _settings.Save(e.Server.Id, settings);
								await _client.Reply(e, $"Removed branch {url}/{e.Args[1]}.");
							}
							else
								await _client.Reply(e, $"Error: Branch {url}/{e.Args[1]} is not being watched.");
						}
//.........这里部分代码省略.........
开发者ID:RogueException,项目名称:DiscordBot,代码行数:101,代码来源:GithubModule.cs


注:本文中的Discord.DiscordClient.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。