Changeset 405 for TwitterIrcGateway
- Timestamp:
- 08/31/08 02:56:36 (3 months ago)
- Location:
- TwitterIrcGateway/trunk/TwitterIrcGatewayCore
- Files:
-
- 1 added
- 4 modified
-
Config.cs (modified) (2 diffs)
-
Session.cs (modified) (10 diffs)
-
TwitterIrcGatewayCore.csproj (modified) (3 diffs)
-
TwitterService.cs (modified) (1 diff)
-
TypableMap.cs (added)
Legend:
- Unmodified
- Added
- Removed
-
TwitterIrcGateway/trunk/TwitterIrcGatewayCore/Config.cs
r399 r405 16 16 public String IMUserName { get; set; } 17 17 public String IMEncryptoPassword { get; set; } 18 19 public Boolean EnableTypableMap { get; set; } 20 public Int32 TypableMapKeyColorNumber { get; set; } 18 21 19 22 public String GetIMPassword(String key) … … 36 39 } 37 40 IMEncryptoPassword = Convert.ToBase64String(Encoding.UTF8.GetBytes(sb.ToString())); 41 } 42 43 public Config() 44 { 45 EnableTypableMap = false; 46 TypableMapKeyColorNumber = 14; 38 47 } 39 48 -
TwitterIrcGateway/trunk/TwitterIrcGatewayCore/Session.cs
r399 r405 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.ComponentModel; 3 4 using System.Diagnostics; 4 5 using System.Globalization; … … 13 14 using System.Xml; 14 15 16 using TypableMap; 15 17 using Misuzilla.Net.Irc; 16 18 using Misuzilla.Applications.TwitterIrcGateway.Filter; … … 32 34 private Filters _filter; 33 35 private Config _config; 36 private TypableMap<Int32> _typableMap; 34 37 35 38 private List<String> _nickNames = new List<string>(); … … 67 70 MessageReceived += new EventHandler<MessageReceivedEventArgs>(MessageReceived_TIGIMENABLE); 68 71 MessageReceived += new EventHandler<MessageReceivedEventArgs>(MessageReceived_TIGIMDISABLE); 72 MessageReceived += new EventHandler<MessageReceivedEventArgs>(MessageReceived_TIGCONFIG); 69 73 70 74 _groups = new Groups(); 71 75 _filter = new Filters(); 72 76 _config = new Config(); 77 _typableMap = new TypableMap<Int32>(); 73 78 74 79 _server = server; … … 611 616 PrivMsgMessage message = e.Message as PrivMsgMessage; 612 617 if (message == null) return; 618 619 // fav コマンド? 620 if (_config.EnableTypableMap) 621 { 622 Match m = Regex.Match(message.Content, @"^\s*(unfav|fav)\s+([a-zA-Z0-9_]+)\s*$", RegexOptions.IgnoreCase); 623 if (m.Success) 624 { 625 Int32 id; 626 if (_typableMap.TryGetValue(m.Groups[2].Value, out id)) 627 { 628 // TypableMap にある 629 Boolean isUnfav = (String.Compare(m.Groups[1].Value, "unfav", true) == 0); 630 Status favStatus = (isUnfav ? _twitter.DestroyFavorite(id) : _twitter.CreateFavorite(id)); 631 Send(new NoticeMessage 632 { 633 Sender = _clientHost, 634 Receiver = message.Receiver, 635 Content = 636 String.Format("ユーザ {0} のステータス \"{1}\"をFavorites{2}しました。", 637 favStatus.User.ScreenName, favStatus.Text, 638 (isUnfav ? "から削除" : "に追加")) 639 }); 640 } 641 return; 642 } 643 } 613 644 614 645 Boolean isRetry = false; … … 879 910 DisconnectToIMService(false); 880 911 } 881 912 913 void MessageReceived_TIGCONFIG(object sender, MessageReceivedEventArgs e) 914 { 915 if (String.Compare(e.Message.Command, "TIGCONFIG", true) != 0) return; 916 917 Type t = typeof(Config); 918 919 // プロパティ一覧を作る 920 if (String.IsNullOrEmpty(e.Message.CommandParams[0])) 921 { 922 //SendTwitterGatewayServerMessage("TIGCONFIG コマンドは1つまたは2つの引数(ConfigName, Value)が必要です。"); 923 foreach (var pi in t.GetProperties(BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.SetProperty)) 924 { 925 SendTwitterGatewayServerMessage( 926 String.Format("{0} ({1}) = {2}", pi.Name, pi.PropertyType.FullName, pi.GetValue(_config, null))); 927 } 928 return; 929 } 930 931 // プロパティを探す 932 String propName = e.Message.CommandParams[0]; 933 PropertyInfo propInfo = t.GetProperty(propName, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.SetProperty); 934 if (propInfo == null) 935 { 936 SendTwitterGatewayServerMessage(String.Format("設定項目 \"{0}\" は存在しません。", propName)); 937 return; 938 } 939 940 // 2つめの引数があるときは値を設定する。 941 if (!String.IsNullOrEmpty(e.Message.CommandParams[1])) 942 { 943 TypeConverter tConv = TypeDescriptor.GetConverter(propInfo.PropertyType); 944 if (!tConv.CanConvertFrom(typeof (String))) 945 { 946 SendTwitterGatewayServerMessage( 947 String.Format("設定項目 \"{0}\" の型 \"{1}\" には適切な TypeConverter がないため、このコマンドで設定することはできません。", propName, 948 propInfo.PropertyType.FullName)); 949 return; 950 } 951 952 try 953 { 954 Object value = tConv.ConvertFromString(e.Message.CommandParams[1]); 955 propInfo.SetValue(_config, value, null); 956 } 957 catch (Exception ex) 958 { 959 SendTwitterGatewayServerMessage(String.Format( 960 "設定項目 \"{0}\" の型 \"{1}\" に値を変換し設定する際にエラーが発生しました({2})。", propName, 961 propInfo.PropertyType.FullName, ex.GetType().Name)); 962 foreach (var line in ex.Message.Split('\n')) 963 SendTwitterGatewayServerMessage(line); 964 } 965 966 SaveConfig(); 967 } 968 969 SendTwitterGatewayServerMessage( 970 String.Format("{0} ({1}) = {2}", propName, propInfo.PropertyType.FullName, propInfo.GetValue(_config, null))); 971 972 } 973 882 974 private void ConnectToIMService(Boolean initialConnect) 883 975 { … … 1054 1146 /// サーバメッセージ系 1055 1147 /// </summary> 1056 /// <param name="m sg"></param>1148 /// <param name="message"></param> 1057 1149 public void SendTwitterGatewayServerMessage(String message) 1058 1150 { … … 1112 1204 { 1113 1205 User[] friends = _twitter.GetFriends(); 1114 _nickNames = new List<string>(Array.ConvertAll<User, String>(friends, delegate(User u) 1115 { 1116 return u.ScreenName; 1117 })); 1206 _nickNames = new List<string>(Array.ConvertAll<User, String>(friends, u => u.ScreenName)); 1118 1207 1119 1208 SendNumericReply(NumericReply.RPL_NAMREPLY, "=", _server.ChannelName, String.Join(" ", _nickNames.ToArray())); … … 1144 1233 { 1145 1234 User[] friends = _twitter.GetFriends(); 1146 List<String> screenNames = new List<string>(Array.ConvertAll<User, String>(friends, delegate(User u) 1147 { 1148 return u.ScreenName; 1149 })); 1235 List<String> screenNames = new List<string>(Array.ConvertAll<User, String>(friends, u => u.ScreenName)); 1150 1236 1151 1237 // てきとうに。 … … 1207 1293 String text = (_server.ResolveTinyUrl) ? Utility.ResolveTinyUrlInMessage(filterArgs.Content) : filterArgs.Content; 1208 1294 1295 // TypableMap 1296 if (_config.EnableTypableMap) 1297 { 1298 String typableMapId = _typableMap.Add(status.Id); 1299 text = String.Format("{0} \x0003{1}({2})", text, _config.TypableMapKeyColorNumber, typableMapId); 1300 } 1301 1209 1302 String[] lines = text.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); 1210 1303 foreach (String line in lines) -
TwitterIrcGateway/trunk/TwitterIrcGatewayCore/TwitterIrcGatewayCore.csproj
r399 r405 3 3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 4 4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 5 <ProductVersion>9.0. 21022</ProductVersion>5 <ProductVersion>9.0.30729</ProductVersion> 6 6 <SchemaVersion>2.0</SchemaVersion> 7 7 <ProjectGuid>{8A256703-BDC7-4E96-8AC3-89A56A2AFB86}</ProjectGuid> … … 33 33 <WarningLevel>4</WarningLevel> 34 34 <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> 35 <DocumentationFile> 36 </DocumentationFile> 35 37 </PropertyGroup> 36 38 <ItemGroup> … … 59 61 <Compile Include="TwitterService.cs"> 60 62 </Compile> 63 <Compile Include="TypableMap.cs" /> 61 64 <Compile Include="Utility.cs" /> 62 65 </ItemGroup> -
TwitterIrcGateway/trunk/TwitterIrcGatewayCore/TwitterService.cs
r399 r405 340 340 341 341 return directMessages; 342 }); 343 } 344 345 /// <summary> 346 /// ���b�Z�[�W��orites�ɒlj���܂��B 347 /// </summary> 348 /// <param name="id"></param> 349 /// <returns></returns> 350 public Status CreateFavorite(Int32 id) 351 { 352 return ExecuteRequest<Status>(() => 353 { 354 String responseBody = POST(String.Format("/favorites/create/{0}.xml", id), new byte[0]); 355 Status status; 356 if (NilClasses.CanDeserialize(responseBody)) 357 { 358 return null; 359 } 360 else 361 { 362 status = Status.Serializer.Deserialize(new StringReader(responseBody)) as Status; 363 return status; 364 } 365 }); 366 } 367 368 /// <summary> 369 /// ���b�Z�[�W��orites���������܂��B 370 /// </summary> 371 /// <param name="id"></param> 372 /// <returns></returns> 373 public Status DestroyFavorite(Int32 id) 374 { 375 return ExecuteRequest<Status>(() => 376 { 377 String responseBody = POST(String.Format("/favorites/destroy/{0}.xml", id), new byte[0]); 378 Status status; 379 if (NilClasses.CanDeserialize(responseBody)) 380 { 381 return null; 382 } 383 else 384 { 385 status = Status.Serializer.Deserialize(new StringReader(responseBody)) as Status; 386 return status; 387 } 342 388 }); 343 389 }
