| 32 | | if (arg.StartsWith("--interval=")) |
| 33 | | { |
| 34 | | if (!Int32.TryParse(arg.Substring("--interval=".Length), out interval)) |
| 35 | | { |
| 36 | | interval = 60; |
| 37 | | } |
| 38 | | } |
| 39 | | else if (arg.StartsWith("--ignore-watch-error=")) |
| 40 | | { |
| 41 | | if (!Boolean.TryParse(arg.Substring("--ignore-watch-error=".Length), out ignoreWatchError)) |
| 42 | | { |
| 43 | | ignoreWatchError = false; |
| 44 | | } |
| 45 | | } |
| 46 | | else if (arg.StartsWith("--enable-trace=")) |
| 47 | | { |
| 48 | | if (!Boolean.TryParse(arg.Substring("--enable-trace=".Length), out enableTrace)) |
| 49 | | { |
| 50 | | enableTrace = false; |
| 51 | | } |
| 52 | | } |
| 53 | | else if (arg.StartsWith("--enable-replies-check=")) |
| 54 | | { |
| 55 | | if (!Boolean.TryParse(arg.Substring("--enable-replies-check=".Length), out enableRepliesCheck)) |
| 56 | | { |
| 57 | | enableRepliesCheck = false; |
| 58 | | } |
| 59 | | } |
| 60 | | else if (arg.StartsWith("--enable-drop-protection=")) |
| 61 | | { |
| 62 | | if (!Boolean.TryParse(arg.Substring("--enable-drop-protection=".Length), out enableDropProtection)) |
| 63 | | { |
| 64 | | enableDropProtection = true; |
| 65 | | } |
| 66 | | } |
| 67 | | else if (arg.StartsWith("--resolve-tinyurl=")) |
| 68 | | { |
| 69 | | if (!Boolean.TryParse(arg.Substring("--resolve-tinyurl=".Length), out resolveTinyUrl)) |
| 70 | | { |
| 71 | | resolveTinyUrl = true; |
| 72 | | } |
| 73 | | } |
| 74 | | else if (arg.StartsWith("--set-topic-onstatuschanged=")) |
| 75 | | { |
| 76 | | if (!Boolean.TryParse(arg.Substring("--set-topic-onstatuschanged=".Length), out setTopicOnStatusChanged)) |
| 77 | | { |
| 78 | | setTopicOnStatusChanged = false; |
| 79 | | } |
| 80 | | } |
| 81 | | else if (arg.StartsWith("--cookie-login-mode=")) |
| 82 | | { |
| 83 | | if (!Boolean.TryParse(arg.Substring("--cookie-login-mode=".Length), out cookieLoginMode)) |
| 84 | | { |
| 85 | | cookieLoginMode = false; |
| 86 | | } |
| 87 | | } |
| 88 | | else if (arg.StartsWith("--port=")) |
| 89 | | { |
| 90 | | if (!Int32.TryParse(arg.Substring("--port=".Length), out port)) |
| 91 | | { |
| 92 | | port = 16668; |
| 93 | | } |
| 94 | | } |
| 95 | | else if (arg.StartsWith("--bind-address=")) |
| 96 | | { |
| 97 | | if (!IPAddress.TryParse(arg.Substring("--bind-address=".Length), out bindAddress)) |
| 98 | | { |
| 99 | | bindAddress = IPAddress.Loopback; |
| 100 | | } |
| 101 | | } |
| 102 | | else if (arg.StartsWith("--encoding=")) |
| 103 | | { |
| 104 | | String encName = arg.Substring("--encoding=".Length); |
| 105 | | if (String.Compare(encName, "UTF-8", true) == 0) |
| 106 | | encoding = new UTF8Encoding(false); |
| 107 | | else |
| 108 | | encoding = Encoding.GetEncoding(encName); |
| 109 | | } |
| 110 | | else if (arg.StartsWith("--interval-directmessage=")) |
| 111 | | { |
| 112 | | if (!Int32.TryParse(arg.Substring("--interval-directmessage=".Length), out intervalDirectMessage)) |
| 113 | | { |
| 114 | | intervalDirectMessage = 180; |
| 115 | | } |
| 116 | | } |
| 117 | | else if (arg.StartsWith("--channel-name=")) |
| 118 | | { |
| 119 | | String channelNameT = arg.Substring("--channel-name=".Length).Replace(" ", ""); |
| 120 | | if (channelName.Length != 0) |
| 121 | | { |
| 122 | | channelName = "#"+channelNameT; |
| 123 | | } |
| 124 | | } |
| 125 | | else if (arg.StartsWith("--interval-replies=")) |
| 126 | | { |
| 127 | | if (!Int32.TryParse(arg.Substring("--interval-replies=".Length), out intervalReplies)) |
| 128 | | { |
| 129 | | intervalReplies = 300; |
| 130 | | } |
| 131 | | } |
| 132 | | else if (arg.StartsWith("--help")) |
| | 25 | // Encoding |
| | 26 | if (String.Compare(options.Encoding, "UTF-8", true) == 0) |
| | 27 | encoding = new UTF8Encoding(false); |
| | 28 | else |
| | 29 | encoding = Encoding.GetEncoding(options.Encoding); |
| | 30 | |
| | 31 | // Listening IP |
| | 32 | if (!IPAddress.TryParse(options.BindAddress, out bindAddress)) |
| 146 | | _server.SetTopicOnStatusChanged = setTopicOnStatusChanged; |
| 147 | | _server.IntervalDirectMessage = intervalDirectMessage; |
| 148 | | _server.CookieLoginMode = cookieLoginMode; |
| 149 | | _server.ChannelName = channelName; |
| 150 | | _server.EnableRepliesCheck = enableRepliesCheck; |
| 151 | | _server.IntervalReplies = intervalReplies; |
| | 51 | _server.SetTopicOnStatusChanged = options.SetTopicOnstatuschanged; |
| | 52 | _server.IntervalDirectMessage = options.IntervalDirectmessage; |
| | 53 | _server.CookieLoginMode = options.CookieLoginMode; |
| | 54 | _server.ChannelName = "#"+options.ChannelName; |
| | 55 | _server.EnableRepliesCheck = options.EnableRepliesCheck; |
| | 56 | _server.IntervalReplies = options.IntervalReplies; |
| 178 | | Console.WriteLine( |
| 179 | | @" |
| 180 | | Usage: TwitterIrcGateway [--port=<port>] [--bind-address=<bindaddr>] [--interval=<sec>] [--resolve-tinyurl=<true|false>] [--encoding=<encoding-name>] [--ignore-watch-error=<true|false>] [--enable-drop-protection=<true|false>] [--set-topic-onstatuschanged=<true|false>] [--enable-trace=<true|false>] [--interval-directmessage=<sec>] [--cookie-login-mode=<true|false>] [--channel-name=<ChannelName>] [--interval-replies=<sec>] |
| 181 | | |
| 182 | | --port=<port> : IRC server listen port (default: 16668) |
| 183 | | --bind-address=<bindaddr> : IRC server bind IP address (default: 127.0.0.1) |
| 184 | | --interval=<sec> : interval of checking Timeline (default: 90) |
| 185 | | --resolve-tinyurl=<true|false> : enable TinyURL resolver (default: true) |
| 186 | | --encoding=<encoding> : IRC message text character encoding (default: ISO-2022-JP) |
| 187 | | --ignore-watch-error=<true|false> : ignore API error messages (default: false) |
| 188 | | --enable-drop-protection=<true|false> : enable drop protection (default: true) |
| 189 | | --set-topic-onstatuschanged=<true|false> : set status as topic on status changed (default: false) |
| 190 | | --enable-trace=<true|false> : enable trace (default: false) |
| 191 | | --interval-directmessage=<sec> : interval of checking directmessage (default: 180) |
| 192 | | --cookie-login-mode=<true|false> : enable cookie-login mode (default: false) |
| 193 | | --channel-name=<ChannelName> : channel name of Twitter timeline (default: Twitter) |
| 194 | | --enable-replies-check=<true|false> : enable replies check (default: false) |
| 195 | | --interval-replies=<sec> : interval of checking Replies (default: 300) |
| 196 | | "); |
| | 83 | Console.WriteLine(@"Usage:"); |
| | 84 | CommandLineParser.ShowHelp(); |
| | 92 | |
| | 93 | class CommandLineOptions |
| | 94 | { |
| | 95 | [DefaultValue(16668)] |
| | 96 | [Description("IRC server listen port")] |
| | 97 | public Int32 Port { get; set; } |
| | 98 | |
| | 99 | [DefaultValue("127.0.0.1")] |
| | 100 | [Description("IRC server bind IP address")] |
| | 101 | public String BindAddress { get; set; } |
| | 102 | |
| | 103 | [DefaultValue(90)] |
| | 104 | [Description("interval of checking Timeline")] |
| | 105 | public Int32 Interval { get; set; } |
| | 106 | |
| | 107 | [DefaultValue(true)] |
| | 108 | [Description("enable TinyURL resolver")] |
| | 109 | public Boolean ResolveTinyurl { get; set; } |
| | 110 | |
| | 111 | [DefaultValue("ISO-2022-JP")] |
| | 112 | [Description("IRC message text character encoding")] |
| | 113 | public String Encoding { get; set; } |
| | 114 | |
| | 115 | [DefaultValue(false)] |
| | 116 | [Description("ignore API error messages")] |
| | 117 | public Boolean IgnoreWatchError { get; set; } |
| | 118 | |
| | 119 | [DefaultValue(true)] |
| | 120 | [Description("enable drop protection")] |
| | 121 | public Boolean EnableDropProtection { get; set; } |
| | 122 | |
| | 123 | [DefaultValue(false)] |
| | 124 | [Description("set status as topic on status changed")] |
| | 125 | public Boolean SetTopicOnstatuschanged { get; set; } |
| | 126 | |
| | 127 | [DefaultValue(false)] |
| | 128 | [Description("enable trace")] |
| | 129 | public Boolean EnableTrace { get; set; } |
| | 130 | |
| | 131 | [DefaultValue(180)] |
| | 132 | [Description("interval of checking directmessage")] |
| | 133 | public Int32 IntervalDirectmessage { get; set; } |
| | 134 | |
| | 135 | [DefaultValue(false)] |
| | 136 | [Description("enable cookie-login mode")] |
| | 137 | public Boolean CookieLoginMode { get; set; } |
| | 138 | |
| | 139 | [DefaultValue("Twitter")] |
| | 140 | [Description("channel name of Twitter timeline")] |
| | 141 | public String ChannelName { get; set; } |
| | 142 | |
| | 143 | [DefaultValue(false)] |
| | 144 | [Description("enable replies check")] |
| | 145 | public Boolean EnableRepliesCheck { get; set; } |
| | 146 | |
| | 147 | [DefaultValue(300)] |
| | 148 | [Description("interval of checking Replies")] |
| | 149 | public Int32 IntervalReplies { get; set; } |
| | 150 | } |