fork(1) download
  1. using System;
  2. using Codeplex.Data;
  3.  
  4. namespace GaoLib.Twitter.Streaming
  5. {
  6.  
  7. public class StreamEvents
  8. {
  9. private EventType eventTypeIns;
  10. public delegate void StreamEventHandler(Auth auth, dynamic json);
  11.  
  12. private enum EventType
  13. {
  14. UNKNOWN,
  15. ERROR,
  16. FRIEND_ID_LIST,
  17. I_TWEETED,
  18. YOU_TWEETED,
  19. I_REPLIED_TO_YOU,
  20. I_REPLIED_TO_ME,
  21. YOU_REPLIED_TO_ANOTHER,
  22. YOU_REPLIED_TO_ME,
  23. I_FAVORITED_YOU,
  24. I_FAVORITED_ME,
  25. YOU_FAVORITED_ME,
  26. DELETED_I_FAVORITED_YOU,
  27. DELETED_I_FAVORITED_ME,
  28. DELETED_YOU_FAVORITED_ME,
  29. I_RETWEETED_YOU,
  30. YOU_RETWEETED_YOU,
  31. YOU_RETWEETED_ME,
  32. DELETED_I_TWEETED_OR_REPLIED_OR_RETWEETED,
  33. DELETED_YOU_TWEETED_OR_REPLIED_OR_RETWEETED,
  34. I_SENDED_DIRECT_MESSAGE_TO_YOU,
  35. YOU_SENDED_DIRECT_MESSAGE_TO_ME,
  36. DELETED_I_SENDED_DIRECT_MESSAGE_TO_YOU,
  37. I_FOLLOWED_YOU,
  38. YOU_FOLLOWED_ME,
  39. I_REMOVED_YOU,
  40. I_BLOCKED_YOU,
  41. DELETED_I_BLOCKED_YOU,
  42. I_UPDATED_MY_PROFILE,
  43. I_REVOKED_APPLET_ACCESS,
  44. DELETED_I_REVOKED_APPLET_ACCESS,
  45. DELETED_MY_SCRUB_GEO,
  46. DELETED_YOUR_SCRUB_GEO,
  47. I_CREATED_MY_PUBLIC_LIST,
  48. I_UPDATED_MY_PUBLIC_LIST,
  49. I_ADDED_YOU_TO_MY_PUBLIC_LIST,
  50. I_ADDED_ME_TO_MY_PUBLIC_LIST,
  51. YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST,
  52. I_SAVED_YOUR_PUBLIC_LIST,
  53. YOU_SAVED_MY_PUBLIC_LIST,
  54. DELETED_I_CREATED_MY_PUBLIC_LIST,
  55. DELETED_I_ADDED_YOU_TO_MY_PUBLIC_LIST,
  56. DELETED_I_ADDED_ME_TO_MY_PUBLIC_LIST,
  57. DELETED_YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST,
  58. DELETED_I_SAVED_YOUR_PUBLIC_LIST,
  59. DELETED_YOU_SAVED_MY_PUBLIC_LIST,
  60. };
  61.  
  62. public StreamEventHandler RawJSONOutput;
  63. public StreamEventHandler IncludeURL;
  64.  
  65. public StreamEventHandler FriendIdList;
  66.  
  67. public StreamEventHandler ITweeted;
  68. public StreamEventHandler YouTweeted;
  69. public StreamEventHandler IRepliedToYou;
  70. public StreamEventHandler IRepliedToMe;
  71. public StreamEventHandler YouRepliedToAnother;
  72. public StreamEventHandler YouRepliedToMe;
  73.  
  74. public StreamEventHandler IFavoritedYou;
  75. public StreamEventHandler IFavoritedMe;
  76. public StreamEventHandler YouFavoritedMe;
  77. public StreamEventHandler DeletedIFavoritedYou;
  78. public StreamEventHandler DeletedIFavoritedMe;
  79. public StreamEventHandler DeletedYouFavoritedMe;
  80.  
  81. public StreamEventHandler IRetweetedYou;
  82. public StreamEventHandler YouRetweetedAnother;
  83. public StreamEventHandler YouRetweetedMe;
  84. public StreamEventHandler DeletedITweetedOrRepliedOrRetweeted;
  85. public StreamEventHandler DeletedYouTweetedOrRepliedOrRetweeted;
  86.  
  87. public StreamEventHandler ISendedDirectMessageToYou;
  88. public StreamEventHandler YouSendedDirectMessageToMe;
  89. public StreamEventHandler DeletedISendedDirectMessageToYou;
  90.  
  91. public StreamEventHandler IFollowedYou;
  92. public StreamEventHandler YouFollowedMe;
  93. public StreamEventHandler IRemovedYou;
  94. public StreamEventHandler IBlockedYou;
  95. public StreamEventHandler DeletedIBlockedYou;
  96.  
  97. public StreamEventHandler IUpdatedMyProfile;
  98. public StreamEventHandler IRevokedAppletAccess;
  99. public StreamEventHandler DeletedIRevokedAppletAccess;
  100. public StreamEventHandler DeletedMyScrubGeo;
  101. public StreamEventHandler DeletedYourScrubGeo;
  102.  
  103. public StreamEventHandler ICreatedMyPublicList;
  104. public StreamEventHandler IUpdatedMyPublicList;
  105. public StreamEventHandler IAddedYouToMyPublicList;
  106. public StreamEventHandler IAddedMeToMyPublicList;
  107. public StreamEventHandler YouAddedMeToYourPublicList;
  108. public StreamEventHandler ISavedYourPublicList;
  109. public StreamEventHandler YouSavedMyPublicList;
  110. public StreamEventHandler DeletedICreatedMyPublicList;
  111. public StreamEventHandler DeletedIAddedYouToMyPublicList;
  112. public StreamEventHandler DeletedIAddedMeToMyPublicList;
  113. public StreamEventHandler DeletedYouAddedMeToYourPublicList;
  114. public StreamEventHandler DeletedISavedYourPublicList;
  115. public StreamEventHandler DeletedYouSavedMyPublicList;
  116.  
  117. public StreamEvents()
  118. {
  119. eventTypeIns = new EventType();
  120.  
  121. //もっとスマートな初期化方法ないのかな?
  122. RawJSONOutput = (a, b) => { };
  123. IncludeURL = (a, b) => { };
  124. FriendIdList = (a, b) => { };
  125. ITweeted = (a, b) => { };
  126. YouTweeted = (a, b) => { };
  127. DeletedMyScrubGeo = (a, b) => { };
  128. DeletedYourScrubGeo = (a, b) => { };
  129. IFavoritedYou = (a, b) => { };
  130. IFavoritedMe = (a, b) => { };
  131. YouFavoritedMe = (a, b) => { };
  132. IRetweetedYou = (a, b) => { };
  133. YouRetweetedAnother = (a, b) => { };
  134. YouRetweetedMe = (a, b) => { };
  135. DeletedITweetedOrRepliedOrRetweeted = (a, b) => { };
  136. DeletedYouTweetedOrRepliedOrRetweeted = (a, b) => { };
  137. IRepliedToYou = (a, b) => { };
  138. IRepliedToMe = (a, b) => { };
  139. YouRepliedToAnother = (a, b) => { };
  140. YouRepliedToMe = (a, b) => { };
  141. ISendedDirectMessageToYou = (a, b) => { };
  142. YouSendedDirectMessageToMe = (a, b) => { };
  143. IFollowedYou = (a, b) => { };
  144. YouFollowedMe = (a, b) => { };
  145. IUpdatedMyProfile = (a, b) => { };
  146. DeletedIFavoritedYou = (a, b) => { };
  147. DeletedIFavoritedMe = (a, b) => { };
  148. DeletedYouFavoritedMe = (a, b) => { };
  149. DeletedISendedDirectMessageToYou = (a, b) => { };
  150. IRemovedYou = (a, b) => { };
  151. IBlockedYou = (a, b) => { };
  152. DeletedIBlockedYou = (a, b) => { };
  153. ICreatedMyPublicList = (a, b) => { };
  154. DeletedICreatedMyPublicList = (a, b) => { };
  155. IUpdatedMyPublicList = (a, b) => { };
  156. IAddedYouToMyPublicList = (a, b) => { };
  157. IAddedMeToMyPublicList = (a, b) => { };
  158. DeletedIAddedYouToMyPublicList = (a, b) => { };
  159. DeletedIAddedMeToMyPublicList = (a, b) => { };
  160. YouAddedMeToYourPublicList = (a, b) => { };
  161. DeletedYouAddedMeToYourPublicList = (a, b) => { };
  162. ISavedYourPublicList = (a, b) => { };
  163. DeletedISavedYourPublicList = (a, b) => { };
  164. YouSavedMyPublicList = (a, b) => { };
  165. DeletedYouSavedMyPublicList = (a, b) => { };
  166. IRevokedAppletAccess = (a, b) => { };
  167. DeletedIRevokedAppletAccess = (a, b) => { };
  168. }
  169.  
  170. public void CheckOnEvent(Auth auth,dynamic json){
  171. try
  172. {
  173. eventTypeIns = GetEventType(auth, json);
  174. }
  175. catch (Exception error)
  176. {
  177. Console.WriteLine(error.Source + " : " + error.Message);
  178. eventTypeIns = EventType.ERROR;
  179. }
  180.  
  181. switch (eventTypeIns)
  182. {
  183. case EventType.FRIEND_ID_LIST:
  184. FriendIdList(auth,json);
  185. break;
  186. case EventType.I_TWEETED:
  187. ITweeted(auth, json);
  188. break;
  189. case EventType.YOU_TWEETED:
  190. YouTweeted(auth, json);
  191. break;
  192. case EventType.I_FAVORITED_YOU:
  193. IFavoritedYou(auth,json);
  194. break;
  195. case EventType.I_FAVORITED_ME:
  196. IFavoritedMe(auth,json);
  197. break;
  198. case EventType.YOU_FAVORITED_ME:
  199. YouFavoritedMe(auth,json);
  200. break;
  201. case EventType.I_RETWEETED_YOU:
  202. IRetweetedYou(auth,json);
  203. break;
  204. case EventType.YOU_RETWEETED_YOU:
  205. YouRetweetedAnother(auth,json);
  206. break;
  207. case EventType.YOU_RETWEETED_ME:
  208. YouRetweetedMe(auth,json);
  209. break;
  210. case EventType.DELETED_I_TWEETED_OR_REPLIED_OR_RETWEETED:
  211. DeletedITweetedOrRepliedOrRetweeted(auth,json);
  212. break;
  213. case EventType.DELETED_YOU_TWEETED_OR_REPLIED_OR_RETWEETED:
  214. DeletedYouTweetedOrRepliedOrRetweeted(auth,json);
  215. break;
  216. case EventType.I_REPLIED_TO_YOU:
  217. IRepliedToYou(auth,json);
  218. break;
  219. case EventType.I_REPLIED_TO_ME:
  220. IRepliedToMe(auth,json);
  221. break;
  222. case EventType.YOU_REPLIED_TO_ANOTHER:
  223. YouRepliedToAnother(auth,json);
  224. break;
  225. case EventType.YOU_REPLIED_TO_ME:
  226. YouRepliedToMe(auth,json);
  227. break;
  228. case EventType.I_SENDED_DIRECT_MESSAGE_TO_YOU:
  229. ISendedDirectMessageToYou(auth,json);
  230. break;
  231. case EventType.YOU_SENDED_DIRECT_MESSAGE_TO_ME:
  232. YouSendedDirectMessageToMe(auth,json);
  233. break;
  234. case EventType.I_FOLLOWED_YOU:
  235. IFollowedYou(auth,json);
  236. break;
  237. case EventType.YOU_FOLLOWED_ME:
  238. YouFollowedMe(auth,json);
  239. break;
  240. case EventType.I_UPDATED_MY_PROFILE:
  241. IUpdatedMyProfile(auth,json);
  242. break;
  243. case EventType.DELETED_I_FAVORITED_YOU:
  244. DeletedIFavoritedYou(auth,json);
  245. break;
  246. case EventType.DELETED_I_FAVORITED_ME:
  247. DeletedIFavoritedMe(auth,json);
  248. break;
  249. case EventType.DELETED_YOU_FAVORITED_ME:
  250. DeletedYouFavoritedMe(auth,json);
  251. break;
  252. case EventType.DELETED_I_SENDED_DIRECT_MESSAGE_TO_YOU:
  253. DeletedISendedDirectMessageToYou(auth,json);
  254. break;
  255. case EventType.I_REMOVED_YOU:
  256. IRemovedYou(auth,json);
  257. break;
  258. case EventType.I_BLOCKED_YOU:
  259. IBlockedYou(auth,json);
  260. break;
  261. case EventType.DELETED_I_BLOCKED_YOU:
  262. DeletedIBlockedYou(auth,json);
  263. break;
  264. case EventType.I_CREATED_MY_PUBLIC_LIST:
  265. ICreatedMyPublicList(auth,json);
  266. break;
  267. case EventType.DELETED_I_CREATED_MY_PUBLIC_LIST:
  268. DeletedICreatedMyPublicList(auth,json);
  269. break;
  270. case EventType.I_UPDATED_MY_PUBLIC_LIST:
  271. IUpdatedMyPublicList(auth,json);
  272. break;
  273. case EventType.I_ADDED_YOU_TO_MY_PUBLIC_LIST:
  274. IAddedYouToMyPublicList(auth,json);
  275. break;
  276. case EventType.I_ADDED_ME_TO_MY_PUBLIC_LIST:
  277. IAddedMeToMyPublicList(auth,json);
  278. break;
  279. case EventType.DELETED_I_ADDED_YOU_TO_MY_PUBLIC_LIST:
  280. DeletedIAddedYouToMyPublicList(auth,json);
  281. break;
  282. case EventType.DELETED_I_ADDED_ME_TO_MY_PUBLIC_LIST:
  283. DeletedIAddedMeToMyPublicList(auth,json);
  284. break;
  285. case EventType.YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST:
  286. YouAddedMeToYourPublicList(auth,json);
  287. break;
  288. case EventType.DELETED_YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST:
  289. DeletedYouAddedMeToYourPublicList(auth,json);
  290. break;
  291. case EventType.I_SAVED_YOUR_PUBLIC_LIST:
  292. ISavedYourPublicList(auth,json);
  293. break;
  294. case EventType.DELETED_I_SAVED_YOUR_PUBLIC_LIST:
  295. DeletedISavedYourPublicList(auth,json);
  296. break;
  297. case EventType.YOU_SAVED_MY_PUBLIC_LIST:
  298. YouSavedMyPublicList(auth,json);
  299. break;
  300. case EventType.DELETED_YOU_SAVED_MY_PUBLIC_LIST:
  301. DeletedYouSavedMyPublicList(auth,json);
  302. break;
  303. case EventType.I_REVOKED_APPLET_ACCESS:
  304. IRevokedAppletAccess(auth,json);
  305. break;
  306. case EventType.DELETED_I_REVOKED_APPLET_ACCESS:
  307. DeletedIRevokedAppletAccess(auth,json);
  308. break;
  309. case EventType.DELETED_MY_SCRUB_GEO:
  310. DeletedMyScrubGeo(auth, json);
  311. break;
  312. case EventType.DELETED_YOUR_SCRUB_GEO:
  313. DeletedMyScrubGeo(auth, json);
  314. break;
  315. //わからないものは、触れないことにする。
  316. case EventType.UNKNOWN:
  317. Console.WriteLine("EventType.UNKNOWNだったのでスルーしました");
  318. break;
  319. //エラー吐いても、スルーして次へ
  320. case EventType.ERROR:
  321. Console.WriteLine("EventType.ERRORだったけどStreamingを一応続けるね");
  322. break;
  323. default:
  324. throw new Exception("不明なEventTypeでした。(EventType : "+eventTypeIns.ToString());
  325. }
  326. if (json.IsDefined("entities") && json["entities"].IsDefined("urls") && json["entities"]["urls"] != null)
  327. {
  328. //URL付きツイート
  329. IncludeURL(auth,json);
  330. }
  331. RawJSONOutput(auth, json);
  332. Console.WriteLine(eventTypeIns.ToString());
  333. }
  334.  
  335. private EventType GetEventType(Auth auth,dynamic json)
  336. {
  337. //イベント系かどうか
  338. if (json.IsDefined("event"))
  339. {
  340. string eventType = json["event"].ToString();
  341. switch (eventType)
  342. {
  343. case "favorite":
  344. if ((auth.UserId == json["target"]["id_str"]) && (auth.UserId == json["source"]["id_str"]))
  345. {
  346. //自演ふぁぼ
  347. return EventType.I_FAVORITED_ME;
  348. }
  349. else if (auth.UserId == json["source"]["id_str"])
  350. {
  351. //他人ふぁぼ
  352. return EventType.I_FAVORITED_YOU;
  353. }
  354. else if (auth.UserId == json["target"]["id_str"])
  355. {
  356. //ふぁぼられ
  357. return EventType.YOU_FAVORITED_ME;
  358. }
  359. else
  360. {
  361. //????
  362. throw new Exception("ふぁぼふぁぼ関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  363. }
  364. case "unfavorite":
  365. if ((auth.UserId == json["target"]["id_str"]) && (auth.UserId == json["source"]["id_str"]))
  366. {
  367. //自演ふぁぼリム
  368. return EventType.DELETED_I_FAVORITED_ME;
  369. }
  370. else if (auth.UserId == json["source"]["id_str"])
  371. {
  372. //他人ふぁぼリム
  373. return EventType.DELETED_I_FAVORITED_YOU;
  374. }
  375. else if (auth.UserId == json["target"]["id_str"])
  376. {
  377. //ふぁぼられリム
  378. return EventType.DELETED_YOU_FAVORITED_ME;
  379. }
  380. else
  381. {
  382. //????
  383. throw new Exception("ふぁぼリム関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  384. }
  385. case "follow":
  386. if (auth.UserId == json["source"]["id_str"])
  387. {
  388. //こっちがフォロー
  389. return EventType.I_FOLLOWED_YOU;
  390. }
  391. else if (auth.UserId == json["target"]["id_str"])
  392. {
  393. //相手からのフォロー
  394. return EventType.YOU_FOLLOWED_ME;
  395. }
  396. else
  397. {
  398. //????
  399. throw new Exception("フォロー関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  400. }
  401. case "unfollow":
  402. if (auth.UserId == json["source"]["id_str"])
  403. {
  404. //こっちがリムーブ・・・なんだけど
  405. //----*注意!*----
  406. //この結果は、Twitter社の陰謀で、
  407. //①自分が相手をリムーブ
  408. //②相手をフォロー時に自分が相手をブロック
  409. //③自分が相手にブロックされる
  410. //上記のどの条件でも発動します。注意されたし。
  411. return EventType.I_REMOVED_YOU;
  412. }
  413. else
  414. {
  415. //????
  416. throw new Exception("unfollowリムブロ関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  417. }
  418. case "block":
  419. if (auth.UserId == json["source"]["id_str"])
  420. {
  421. return EventType.I_BLOCKED_YOU;
  422. }
  423. else
  424. {
  425. //????
  426. throw new Exception("blockブロック関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  427. }
  428. case "unblock":
  429. if (auth.UserId == json["source"]["id_str"])
  430. {
  431. return EventType.DELETED_I_BLOCKED_YOU;
  432. }
  433. else
  434. {
  435. //????
  436. throw new Exception("unblockアンブロック関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  437. }
  438. case "list_created":
  439. if (auth.UserId == json["source"]["id_str"])
  440. {
  441.  
  442. return EventType.I_CREATED_MY_PUBLIC_LIST;
  443. }
  444. else
  445. {
  446. //????
  447. throw new Exception("リスト作成関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  448. }
  449. case "list_destroyed":
  450. if (auth.UserId == json["source"]["id_str"])
  451. {
  452. return EventType.DELETED_I_CREATED_MY_PUBLIC_LIST;
  453. }
  454. else
  455. {
  456. //????
  457. throw new Exception("リスト削除関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  458. }
  459. case "list_updated":
  460. if (auth.UserId == json["source"]["id_str"])
  461. {
  462. return EventType.I_UPDATED_MY_PUBLIC_LIST;
  463. }
  464. else
  465. {
  466. //????
  467. throw new Exception("リスト削除関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  468. }
  469. case "list_member_added":
  470. if ((auth.UserId == json["source"]["id_str"]) && (auth.UserId == json["target"]["id_str"]))
  471. {
  472. //自作リストに自分を追加させた
  473. return EventType.I_ADDED_ME_TO_MY_PUBLIC_LIST;
  474. }
  475. else if (auth.UserId == json["source"]["id_str"])
  476. {
  477. //自作リストに他人を追加した
  478. return EventType.I_ADDED_YOU_TO_MY_PUBLIC_LIST;
  479. }
  480. else if (auth.UserId == json["target"]["id_str"])
  481. {
  482. //他人のリストに自分が追加された
  483. return EventType.YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST;
  484. }
  485. else
  486. {
  487. //????
  488. throw new Exception("リストメンバー追加関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  489. }
  490. case "list_member_removed":
  491. if ((auth.UserId == json["source"]["id_str"]) && (auth.UserId == json["target"]["id_str"]))
  492. {
  493. //自作リストから自分を除外した
  494. return EventType.DELETED_I_ADDED_ME_TO_MY_PUBLIC_LIST;
  495. }
  496. else if (auth.UserId == json["source"]["id_str"])
  497. {
  498. //自作リストから他人を除外した
  499. return EventType.DELETED_I_ADDED_YOU_TO_MY_PUBLIC_LIST;
  500. }
  501. else if (auth.UserId == json["target"]["id_str"])
  502. {
  503. //他人のリストから自分が除外された
  504. return EventType.DELETED_YOU_ADDED_ME_TO_YOUR_PUBLIC_LIST;
  505. }
  506. else
  507. {
  508. //????
  509. throw new Exception("リストメンバー除外関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  510. }
  511. case "list_user_subscribed":
  512. if (auth.UserId == json["source"]["id_str"])
  513. {
  514. //自分が相手のリストを保存した
  515. return EventType.I_SAVED_YOUR_PUBLIC_LIST;
  516. }
  517. else if (auth.UserId == json["target"]["id_str"])
  518. {
  519. //他人が自分のリストを保存した
  520. return EventType.YOU_SAVED_MY_PUBLIC_LIST;
  521. }
  522. else
  523. {
  524. //????
  525. throw new Exception("リスト保存関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  526. }
  527. case "list_user_unsubscribed":
  528. if (auth.UserId == json["source"]["id_str"])
  529. {
  530. //自分が相手のリストを保存を解除した
  531. return EventType.DELETED_I_SAVED_YOUR_PUBLIC_LIST;
  532. }
  533. else if (auth.UserId == json["target"]["id_str"])
  534. {
  535. //他人が自分のリストを保存を解除した
  536. return EventType.DELETED_YOU_SAVED_MY_PUBLIC_LIST;
  537. }
  538. else
  539. {
  540. //????
  541. throw new Exception("リスト保存関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  542. }
  543. case "access_revoked":
  544. if (auth.UserId == json["source"]["id_str"])
  545. {
  546. //自分が自分でアプリ連携の許可を取り消した
  547. return EventType.I_REVOKED_APPLET_ACCESS;
  548. }
  549. else
  550. {
  551. //????
  552. throw new Exception("アプリ連携取り消し関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  553. }
  554. case "access_unrevoked":
  555. if (auth.UserId == json["source"]["id_str"])
  556. {
  557. //自分が自分でアプリ連携の許可を取り消したをやめた(日本語おかしい)
  558. return EventType.DELETED_I_REVOKED_APPLET_ACCESS;
  559. }
  560. else
  561. {
  562. //????
  563. throw new Exception("アプリ連携取り消しの取り消し関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["source"]["id_str"] + ",target:" + json["target"]["id_str"] + ")");
  564. }
  565. default:
  566. Console.WriteLine("不明なevent名 : " + eventType);
  567. return EventType.UNKNOWN;
  568. }
  569. }
  570. else
  571. {
  572. if (json.IsDefined("retweeted_status"))
  573. {
  574. if ((auth.UserId != json["retweeted_status"]["user"]["id_str"]) && (auth.UserId != json["user"]["id_str"]))
  575. {
  576. //他人⇒他人
  577. return EventType.YOU_RETWEETED_YOU;
  578. }
  579. else if (auth.UserId != json["retweeted_status"]["user"]["id_str"])
  580. {
  581. //自分⇒他人
  582. return EventType.I_RETWEETED_YOU;
  583. }
  584. else if (auth.UserId != json["user"]["id_str"])
  585. {
  586. //他人⇒自分
  587. return EventType.YOU_RETWEETED_ME;
  588. }
  589. else
  590. {
  591. //????
  592. throw new Exception("RT関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["user"]["id_str"] + ",target:" + json["retweeted_status"]["user"]["id_str"] + ")");
  593. }
  594. }
  595. else if (json.IsDefined("direct_message"))
  596. {
  597. if (auth.UserId == json["direct_message"]["sender"]["id_str"])
  598. {
  599. //DM送った
  600. return EventType.I_SENDED_DIRECT_MESSAGE_TO_YOU;
  601. }
  602. else if (auth.UserId == json["direct_message"]["recipient"]["id_str"])
  603. {
  604. //DM受け取った
  605. return EventType.YOU_SENDED_DIRECT_MESSAGE_TO_ME;
  606. }
  607. else
  608. {
  609. //????
  610. throw new Exception("DM関係で謎の状態に陥った(auth:" + auth.UserId + ",sender:" + auth.UserId == json["direct_message"]["sender"]["id_str"] + ",recipient:" + json["direct_message"]["recipient"]["id_str"] + ")");
  611. }
  612. }
  613. else if (json.IsDefined("delete"))
  614. {
  615. if (json["delete"].IsDefined("status"))
  616. {
  617. if (auth.UserId == json["delete"]["status"]["user_id_str"])
  618. {
  619. //自分のメッセージを消した(ツイ消し・リプ消し・RT取り消し)
  620. return EventType.DELETED_I_TWEETED_OR_REPLIED_OR_RETWEETED;
  621. }
  622. else
  623. {
  624. //相手がメッセージを消した(ツイ消し・リプ消し・RT取り消し)
  625. return EventType.DELETED_YOU_TWEETED_OR_REPLIED_OR_RETWEETED;
  626. }
  627.  
  628. }
  629. else if (json["delete"].IsDefined("direct_message"))
  630. {
  631. if (auth.UserId == json["delete"]["direct_message"]["user_id"].ToString()) //user_id_strはない。バグ?
  632. {
  633. //自分or相手が自分のDMを消した
  634. return EventType.DELETED_I_SENDED_DIRECT_MESSAGE_TO_YOU;
  635. }
  636. else
  637. {
  638. //????
  639. throw new Exception("DM削除関係で謎の状態に陥った(auth:" + auth.UserId + ",target:" + json["delete"]["direct_message"]["user_id"] + ")");
  640. }
  641. }
  642. else
  643. {
  644. //????
  645. throw new Exception("削除関係で謎の状態に陥った(auth:" + auth.UserId + ")");
  646. }
  647. }
  648. else if (json.IsDefined("scrub_geo"))
  649. {
  650. if (auth.UserId == json["scrub_geo"]["user_id_str"])
  651. {
  652. //自分が自分の位置情報を消した
  653. return EventType.DELETED_MY_SCRUB_GEO;
  654. }
  655. else
  656. {
  657. //他人が他人の位置情報を消した
  658. return EventType.DELETED_YOUR_SCRUB_GEO;
  659. }
  660. }
  661. else if (json.IsDefined("text"))
  662. {
  663. if (json.IsDefined("in_reply_to_user_id_str") && json["in_reply_to_user_id_str"] != null)
  664. {
  665. //リプライ
  666. if ((auth.UserId == json["in_reply_to_user_id_str"]) && (auth.UserId == json["user"]["id_str"]))
  667. {
  668. //自分⇒自分
  669. return EventType.I_REPLIED_TO_ME;
  670. }
  671. else if ((auth.UserId != json["in_reply_to_user_id_str"]) && (auth.UserId != json["user"]["id_str"]))
  672. {
  673. //他人⇒他人
  674. return EventType.YOU_REPLIED_TO_ANOTHER;
  675. }
  676. else if (auth.UserId != json["in_reply_to_user_id_str"])
  677. {
  678. //自分⇒他人
  679. return EventType.I_REPLIED_TO_YOU;
  680. }
  681. else if (auth.UserId != json["user"]["id_str"])
  682. {
  683. //他人⇒自分
  684. return EventType.YOU_REPLIED_TO_ME;
  685. }
  686. else
  687. {
  688. //????
  689. throw new Exception("リプライ関係で謎の状態に陥った(auth:" + auth.UserId + ",source:" + json["user"]["id_str"] + ",target:" + json["in_reply_to_user_id_str"] + ")");
  690. }
  691. }
  692. else
  693. {
  694. //多分通常ツイート
  695. if (auth.UserId == json["user"]["id_str"])
  696. {
  697. //自分のつぶやき
  698. return EventType.I_TWEETED;
  699. }
  700. else
  701. {
  702. //他人のつぶやき
  703. return EventType.YOU_TWEETED;
  704. }
  705. }
  706. }
  707. else if (json.IsDefined("friends"))
  708. {
  709. //一番最初にだけやってくるfriendリスト
  710. return EventType.FRIEND_ID_LIST;
  711. }
  712. else
  713. {
  714. //よくわからんのが来た
  715. return EventType.UNKNOWN;
  716. }
  717. }
  718. }
  719. }
  720. }
  721.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty