This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMyAnimeList+Twitter.m
54 lines (50 loc) · 2.51 KB
/
MyAnimeList+Twitter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// MyAnimeList+Twitter.m
// MAL Updater OS X
//
// Created by 天々座理世 on 2018/01/24.
//
#import "MyAnimeList+Twitter.h"
#import <TwitterManagerKit/TwitterManagerKit.h>
@implementation MyAnimeList (Twitter)
- (void)postaddanimetweet {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"twitteraddanime"] && [NSUserDefaults.standardUserDefaults boolForKey:@"tweetonscrobble"] && !self.testing) {
[self performtweet:[NSUserDefaults.standardUserDefaults objectForKey:@"twitteraddanimeformat"]];
}
}
- (void)postupdateanimetweet {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"twitterupdateanime"] && [NSUserDefaults.standardUserDefaults boolForKey:@"tweetonscrobble"] && !self.testing) {
[self performtweet:[NSUserDefaults.standardUserDefaults objectForKey:@"twitterupdateanimeformat"]];
}
}
- (void)postupdatestatustweet {
if ([NSUserDefaults.standardUserDefaults boolForKey:@"twitterupdatestatus"] && [NSUserDefaults.standardUserDefaults boolForKey:@"tweetonscrobble"] && !self.testing) {
[self performtweet:[NSUserDefaults.standardUserDefaults objectForKey:@"twitterupdatestatusformat"]];
}
}
- (void)performtweet:(NSString *)format {
if ([self.twittermanager accountexists]) {
[self.twittermanager postTweet:[self generateTweetStringWithFormat:format] completion:^(bool success) {
if (success) {
NSLog(@"Tweet successful.");
}
} error:^(NSError *error) {
NSLog(@"Error posting tweet: %@", error.localizedDescription);
}];
}
}
- (NSString *)generateTweetStringWithFormat:(NSString *)formatstring {
NSString *tmpstr = formatstring;
// Replace $title% with actual title
tmpstr = [tmpstr stringByReplacingOccurrencesOfString:@"%title%" withString:self.LastScrobbledActualTitle];
// Replace %status% with actual status
tmpstr = [tmpstr stringByReplacingOccurrencesOfString:@"%status%" withString:self.WatchStatus];
// Replace %episode% with actual episode number
tmpstr = [tmpstr stringByReplacingOccurrencesOfString:@"%episode%" withString:self.LastScrobbledEpisode];
// Replace %malurl% with actual MAL URL
tmpstr = [tmpstr stringByReplacingOccurrencesOfString:@"%malurl%" withString:[NSString stringWithFormat:@"https://myanimelist.net/anime/%@", self.AniID]];
// Replace %score$ with the actual score
tmpstr = [tmpstr stringByReplacingOccurrencesOfString:@"%score%" withString:[NSString stringWithFormat:@"%i/10", self.TitleScore]];
return tmpstr;
}
@end