本文整理汇总了C#中Robot.GetConfigVariable方法的典型用法代码示例。如果您正苦于以下问题:C# Robot.GetConfigVariable方法的具体用法?C# Robot.GetConfigVariable怎么用?C# Robot.GetConfigVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robot
的用法示例。
在下文中一共展示了Robot.GetConfigVariable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public override void Initialize(Robot robot)
{
base.Initialize(robot);
_token = robot.GetConfigVariable("MMBOT_SLACK_TOKEN");
_commandTokens = (robot.GetConfigVariable("MMBOT_SLACK_COMMANDTOKENS") ?? string.Empty)
.Split(',')
.Where(s => !string.IsNullOrWhiteSpace(s))
.Select(s => s.Trim())
.ToArray();
_logRooms = (robot.GetConfigVariable("MMBOT_SLACK_LOGROOMS") ?? string.Empty)
.Split(',')
.Where(s => !string.IsNullOrWhiteSpace(s))
.Select(s => s.Trim())
.ToArray();
if (string.IsNullOrWhiteSpace(_token))
{
var helpSb = new StringBuilder();
helpSb.AppendLine("The Slack adapter is not configured correctly and hence will not be enabled.");
helpSb.AppendLine("To configure the Slack adapter, please set the following configuration properties:");
helpSb.AppendLine(" MMBOT_SLACK_TOKEN: This is the service token you are given when you add your Bot to your Team Services.");
helpSb.AppendLine(" MMBOT_SLACK_COMMANDTOKENS: Optional. The comma delimited list of expected command tokens from the Slack commands hook. If none supplied then any token will be accepted.");
helpSb.AppendLine(" MMBOT_SLACK_LOGROOMS: Optional. The comma delimited list of rooms to send log messages to.");
helpSb.AppendLine("More info on these values and how to create the mmbot.ini file can be found at https://github.com/mmbot/mmbot/wiki/Configuring-mmbot");
Logger.Warn(helpSb.ToString());
_isConfigured = false;
return;
}
_isConfigured = true;
Logger.Info("The Slack adapter is connected");
}
示例2: RememberConfiguredAliases
private void RememberConfiguredAliases(Robot robot)
{
var configuredAliases = robot.GetConfigVariable(NuGetPackageAliasesSetting) ?? string.Empty;
foreach (var alias in configuredAliases.Split(new []{','}, StringSplitOptions.RemoveEmptyEntries))
{
AddAlias(alias, robot);
}
}
示例3: RememberConfiguredSources
private void RememberConfiguredSources(Robot robot)
{
var configuredSources = robot.GetConfigVariable(NuGetRepositoriesSetting) ?? string.Empty;
foreach(var source in configuredSources.Split(','))
{
AddSource(source, robot);
}
}
示例4: Initialize
public override void Initialize(Robot robot)
{
base.Initialize(robot);
if (Robot.Router is NullRouter)
{
Logger.Warn("The Slack adapter currently requires a Router to be configured. Please setup a router e.g. MMBot.Nancy.");
return;
}
_team = robot.GetConfigVariable("MMBOT_SLACK_TEAM");
_token = robot.GetConfigVariable("MMBOT_SLACK_TOKEN");
_slackBotName = robot.GetConfigVariable("MMBOT_SLACK_BOTNAME") ?? robot.Name;
_sendViaPostMessageApi = bool.Parse(robot.GetConfigVariable("MMBOT_SLACK_USEPOSTMESSAGE") ?? "false");
_userToken = robot.GetConfigVariable("MMBOT_SLACK_USERTOKEN");
_commandTokens = (robot.GetConfigVariable("MMBOT_SLACK_COMMANDTOKENS") ?? string.Empty).Split(',').Where(s => !string.IsNullOrEmpty(s)).Select(s => s.Trim()).ToArray();
_icon = robot.GetConfigVariable("MMBOT_SLACK_ICON") ?? "https://raw.githubusercontent.com/mmbot/mmbot/master/Docs/Images/mmbot.logo.48x48.png";
Enum.TryParse(robot.GetConfigVariable("MMBOT_SLACK_CHANNELMODE") ?? "blacklist", true, out _channelMode);
_channels = (Robot.GetConfigVariable("MMBOT_SLACK_CHANNELS") ?? string.Empty)
.Trim()
.Split(',')
.Select(s => s.Trim())
.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
_linkNames = bool.Parse(Robot.GetConfigVariable("MMBOT_SLACK_LINK_NAMES") ?? "false");
var invalid = false;
if (_sendViaPostMessageApi && string.IsNullOrEmpty(_userToken))
{
Logger.Error("Slack Adapter - if you enable USEPOSTMESSAGE you must provide a USERTOKEN. Get this from the api documentation page");
invalid = true;
}
if (string.IsNullOrWhiteSpace(_team) || string.IsNullOrWhiteSpace(_token) || invalid)
{
var helpSb = new StringBuilder();
helpSb.AppendLine("The Slack adapter is not configured correctly and hence will not be enabled.");
helpSb.AppendLine("To configure the Slack adapter, please set the following configuration properties:");
helpSb.AppendLine(" MMBOT_SLACK_TEAM: This is your team's Slack subdomain. For example, if your team is https://myteam.slack.com/, you would enter myteam here");
helpSb.AppendLine(" MMBOT_SLACK_TOKEN: This is the service token you are given when you add Hubot to your Team Services.");
helpSb.AppendLine(" MMBOT_SLACK_BOTNAME: Optional. What your mmbot is called on Slack. If you entered slack-hubot here, you would address your bot like slack-hubot: help. Otherwise, defaults to mmbot");
helpSb.AppendLine(" MMBOT_SLACK_USEPOSTMESSAGE: Optional. If true, respond in Slack using the post message api instead of the Hubot adapter. This is more reliable in some ways and works with slack commands etc. Default is false");
helpSb.AppendLine(" MMBOT_SLACK_USERTOKEN: Optional. Required if USEPOSTMESSAGE is enabled. You must get a user token from the API documentation pages");
helpSb.AppendLine(" MMBOT_SLACK_ICON: Optional. The URL of the icon to use when USEPOSTMESSAGE is enabled");
helpSb.AppendLine(" MMBOT_SLACK_COMMANDTOKENS: Optional. The comma delimited list of expected command tokens from the Slack commands hook. If none supplied then any token will be accepted.");
helpSb.AppendLine("More info on these values and how to create the mmbot.ini file can be found at https://github.com/mmbot/mmbot/wiki/Configuring-mmbot");
Logger.Warn(helpSb.ToString());
_isConfigured = false;
return;
}
_isConfigured = true;
Logger.Info("The Slack adapter is connected");
}
示例5: Initialize
public override void Initialize(Robot robot)
{
base.Initialize(robot);
if (Robot.Router is NullRouter)
{
Logger.Warn("The Slack adapter currently requires a Router to be configured. Please setup a router e.g. MMBot.Nancy.");
return;
}
_team = robot.GetConfigVariable("MMBOT_SLACK_TEAM");
_token = robot.GetConfigVariable("MMBOT_SLACK_TOKEN");
_slackBotName = robot.GetConfigVariable("MMBOT_SLACK_BOTNAME") ?? robot.Name;
Enum.TryParse(robot.GetConfigVariable("MMBOT_SLACK_CHANNELMODE") ?? "blacklist", true, out _channelMode);
_channels = (Robot.GetConfigVariable("MMBOT_SLACK_CHANNELS") ?? string.Empty)
.Trim()
.Split(',')
.Select(s => s.Trim())
.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
_linkNames = bool.Parse(Robot.GetConfigVariable("MMBOT_SLACK_LINK_NAMES") ?? "false");
if (string.IsNullOrWhiteSpace(_team) || string.IsNullOrWhiteSpace(_token))
{
var helpSb = new StringBuilder();
helpSb.AppendLine("The Slack adapter is not configured correctly and hence will not be enabled.");
helpSb.AppendLine("To configure the Slack adapter, please set the following configuration properties:");
helpSb.AppendLine(" MMBOT_SLACK_TEAM: This is your team's Slack subdomain. For example, if your team is https://myteam.slack.com/, you would enter myteam here");
helpSb.AppendLine(" MMBOT_SLACK_TOKEN: This is the service token you are given when you add Hubot to your Team Services.");
helpSb.AppendLine(" MMBOT_SLACK_BOTNAME: Optional. What your mmbot is called on Slack. If you entered slack-hubot here, you would address your bot like slack-hubot: help. Otherwise, defaults to mmbot");
helpSb.AppendLine("More info on these values and how to create the mmbot.ini file can be found at https://github.com/mmbot/mmbot/wiki/Configuring-mmbot");
Logger.Warn(helpSb.ToString());
_isConfigured = false;
return;
}
_isConfigured = true;
Logger.Info("The Slack adapter is connected");
}
示例6: Register
public void Register(Robot robot)
{
_username = robot.GetConfigVariable("MMBOT_TEAMCITY_USERNAME");
_password = robot.GetConfigVariable("MMBOT_TEAMCITY_PASSWORD");
_hostname = robot.GetConfigVariable("MMBOT_TEAMCITY_HOSTNAME");
_scheme = robot.GetConfigVariable("MMBOT_TEAMCITY_SCHEME") ?? "http";
_baseUrl = string.Format("{0}://{1}", _scheme, _hostname);
if (_hostname == null)
{
return;
}
//robot.Respond(@"tc what('?s| is) building$", async msg =>
//{
// dynamic res = await msg.Http(string.Format("{0}/httpAuth/app/rest/builds/?locator=running:true", _baseUrl))
// .Headers(GetHeaders())
// .GetJson();
// if (res.count == 0 || res.build == null)
// {
// await msg.Send("No builds are currently running");
// }
// else
// {
// var buildsDescription = new StringBuilder();
// foreach (var build in res.build)
// {
// if (build.percentageComplete < 100)
// {
// buildsDescription.AppendLine(
// string.Format("{0} is currently at {1}% and is so far looking like a {2}",
// build.buildTypeId, build.percentageComplete, build.status));
// }
// else
// {
// buildsDescription.AppendLine(
// string.Format("{0} completed with a status of {1} - {2}", build.buildTypeId, build.status, build.webUrl));
// }
// }
// await msg.Send(buildsDescription.ToString());
// }
//});
//robot.Respond(@"tc list projects", async msg =>
//{
// dynamic res = await msg.Http(string.Format("{0}/httpAuth/app/rest/projects", _baseUrl))
// .Headers(GetHeaders())
// .GetJson();
// if (res.count == 0 || res.project == null)
// {
// await msg.Send("No projects are defined");
// }
// else
// {
// var projectsDescription = new StringBuilder();
// foreach (var project in res.project)
// {
// projectsDescription.AppendLine((string)project.name);
// }
// await msg.Send(projectsDescription.ToString());
// }
//});
robot.Respond("show me builds$", msg => GetCurrentBuilds(robot, msg, null, (err, res, body) =>
{
if (err == null && body["count"].Value<int>() == 0)
{
msg.Send("No builds are currently running");
return;
}
CreateAndPublishBuildMap(body["build"], msg);
}));
robot.Respond(@"tc build start (.*)", msg =>
{
var configuration = msg.Match[1];
var buildName = msg.Match[1];
if (string.IsNullOrWhiteSpace(buildName))
{
msg.Send("Nothing to build. Specify a build");
return;
}
string project = null;
if(_buildTypeRegex.IsMatch(buildName))
{
var buildTypeMatches = _buildTypeRegex.Matches(buildName);
configuration = buildTypeMatches[0].Groups[2].Value;
project = buildTypeMatches[0].Groups[3].Value;
}
MapNameToIdForBuildType(robot, msg, configuration, project, (response, buildType) =>
{
if (buildType == null)
//.........这里部分代码省略.........
示例7: GetApiKey
private static string GetApiKey(Robot robot)
{
return robot.GetConfigVariable("MMBOT_GIPHY_APIKEY") ?? "dc6zaTOxFJmzC";
}
示例8: ConfigureRouter
private static void ConfigureRouter(Robot robot, NuGetPackageAssemblyResolver nugetResolver)
{
var robotEnabledVar = robot.GetConfigVariable("MMBOT_ROUTER_ENABLED");
if (robotEnabledVar != null && robotEnabledVar.ToLower() == "true" || robotEnabledVar == "yes")
{
var routerType = nugetResolver.GetCompiledRouterFromPackages();
if (routerType != null)
{
robot.Logger.Info(string.Format("Loading router '{0}'", routerType.Name));
robot.ConfigureRouter(routerType);
}
else
{
robot.Logger.Warn("The router was enabled but no implementation was found. Make sure you have installed the relevant router package");
}
}
}
示例9: Register
public void Register(Robot robot)
{
_robot = robot;
_player = new SpotifyPlayer(robot);
Observable.FromEventPattern<Track>(e => _player.TrackChanged += e, e => _player.TrackChanged -= e)
.Select(s => Unit.Default)
.Merge(
Observable.FromEventPattern<SpotifyPlayer.PlayerState>(e => _player.StateChanged += e,
e => _player.StateChanged -= e).Select(s => Unit.Default))
.Throttle(TimeSpan.FromMilliseconds(300))
.Subscribe(a => UpdateLoungeTopic());
_player.LoungeRoom = robot.GetConfigVariable("MMBOT_SPOTIFY_LOUNGE");
robot.Respond(@"spotify shuffle( on| off)?", async msg =>
{
var off = msg.Match[1].ToLowerInvariant().Trim() == "off";
if (off)
{
await _player.SetShuffleOff();
}
else
{
await _player.SetShuffleOn();
}
await msg.Send(string.Format("Shuffle is {0}", off ? "OFF" : "ON"));
});
robot.Respond(@"spotify play( album)?( .*)?", async msg =>
{
if(!await Login(msg)) return;
bool isAlbum = !string.IsNullOrEmpty(msg.Match[1]);
string query = msg.Match[2].Trim();
if (string.IsNullOrWhiteSpace(query))
{
await _player.Play();
}
else
{
string message = null;
if (_spotifyLinkRegex.IsMatch(query))
{
// We have a link so process as such
message = await _player.PlayLink(query);
}
else
{
if (string.IsNullOrEmpty(query))
{
await msg.Send("Nothing to search for");
return;
}
if (isAlbum)
{
var album = await _player.SearchForAlbum(query);
if (album != null)
{
message = await _player.PlayAlbum(album);
}
else
{
await msg.Send(string.Format("Could not find any albums matching '{0}'", query));
msg.Message.Done = true;
}
}
else
{
// Search for a matching track
var track = await _player.SearchForTrack(query);
if (track != null)
{
await _player.Play(track);
}
else
{
await msg.Send(string.Format("Could not find any tracks matching '{0}'", query));
msg.Message.Done = true;
}
}
}
// Output the user message from the play request, if any
if (!string.IsNullOrWhiteSpace(message))
{
await msg.Send(message);
}
}
});
robot.Respond(@"spotify (en)?queue( album)? (.*)", async msg =>
{
if (!await Login(msg)) return;
bool isAlbum = !string.IsNullOrEmpty(msg.Match[2]);
//.........这里部分代码省略.........
示例10: RememberConfiguredAutoReset
private void RememberConfiguredAutoReset(Robot robot)
{
var autoReset = robot.GetConfigVariable(NuGetResetAfterUpdateSetting) ?? string.Empty;
bool autoResetValue;
if (!bool.TryParse(autoReset, out autoResetValue))
{
autoResetValue = false;
}
Remember(NuGetResetAfterUpdateSetting, autoResetValue, robot);
}