Exemplo n.º 1
0
        public static async Task Run([TimerTrigger("0 5 15 * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"{nameof(AggregateYesterdayNotes)} executed at {DateTime.Now}");
            var credential = new Credential
            {
                Domain       = GetEnvironmentVariable("MISSKEY_DOMAIN"),
                ClientSecret = GetEnvironmentVariable("MISSKEY_CLIENT_SECRET"),
                AccessToken  = GetEnvironmentVariable("MISSKEY_ACCESS_TOKEN")
            };

            var misskey = new MisskeyClient(credential);
            var me      = await misskey.IAsync();

            var data = await misskey.Charts.Users.NotesAsync(me.Id, "hour", 24 * 2); // 2 days

            var notes = data.Inc.Skip(1).Take(24).Sum();

            var pixela = new PixelaClient(GetEnvironmentVariable("PIXELA_USER"), GetEnvironmentVariable("PIXELA_ACCESS_TOKEN"));

            var graphs = await pixela.Graphs.ListAsync();

            if (graphs.All(w => w.Id != "misskey"))
            {
                await pixela.Graphs.CreateAsync("misskey", "Misskey Notes", "note", GraphType.Int, GraphColor.Sora, "Asia/Tokyo");
            }
            await pixela.Pixel.CreateAsync("misskey", DateTime.Today, notes); // Azure Function's timezone is UTC

            log.LogInformation($"{nameof(AggregateYesterdayNotes)} ended at {DateTime.Now}");
        }
Exemplo n.º 2
0
 protected internal NotesClient(MisskeyClient client) : base(client, "notes")
 {
     FavoritesClient = new FavoritesClient(client);
     Polls           = new PollsClient(client);
     Reactions       = new ReactionsClient(client);
     Watching        = new WatchingClient(client);
 }
Exemplo n.º 3
0
        private static async Task AuthorizeAsync(MisskeyClient mi, Logger logger)
        {
            var app = await mi.App.CreateAsync("RealXelticaBot", "Xeltica Imitation", ((Permission[])Enum.GetValues(typeof(Permission))).Select(p => p.ToStr()).ToArray(), "http://xeltica.work");

            var session = await mi.Auth.Session.GenerateAsync();

            try
            {
                Server.OpenUrl(session.Url);
            }
            catch (NotSupportedException)
            {
                logger.Error("ユーザー認証のためのURLを開くことができませんでした。以下のURLにアクセスして認証を進めてください。");
                logger.Error("> " + session.Url);
            }

            logger.Info("ユーザー認証を行います。ウェブブラウザ上で認証が終わったら、コンソールで何かキーを押してください。");
            Console.Write("> ");
            ReadLine();

            await mi.Auth.Session.UserKeyAsync(session.Token);

            var credential = JsonConvert.SerializeObject(mi.Credential);

            File.WriteAllText("./token", credential);
        }
Exemplo n.º 4
0
        /// <summary>
        /// bot を初期化します。
        /// </summary>
        /// <returns>初期化された <see cref="Shell"/> のインスタンス。</returns>
        public static async Task <Shell> InitializeAsync()
        {
            MisskeyClient mi;
            var           logger = new Logger(nameof(Shell));

            try
            {
                var credential = File.ReadAllText("./token");
                mi = new MisskeyClient(JsonConvert.DeserializeObject <Disboard.Models.Credential>(credential));
                logger.Info("Misskey に接続しました。");
            }
            catch (Exception)
            {
                logger.Error($"認証に失敗しました。セットアップを開始します。");
                Write("Misskey URLを入力してください。> ");
                var host = ReadLine();
                mi = new MisskeyClient(host);
                await AuthorizeAsync(mi, logger);
            }

            var myself = await mi.IAsync();

            logger.Info($"bot ユーザーを取得しました (@{myself.Username})");

            // 呼ばないとストリームの初期化ができないらしい
            await mi.Streaming.ConnectAsync();

            var sh = new Shell(mi, myself, logger);

            sh.MaxNoteLength = (await mi.MetaAsync()).MaxNoteTextLength;
            return(sh);
        }
Exemplo n.º 5
0
 public Shell(MisskeyClient mi, User myself, Logger logger)
 {
     Logger  = logger;
     Core    = new Server(this);
     Misskey = mi;
     Myself  = new MiUser(myself);
     SubscribeStreams();
 }
Exemplo n.º 6
0
 protected internal IClient(MisskeyClient client) : base(client, "i")
 {
 }
Exemplo n.º 7
0
 protected internal AggregationClient(MisskeyClient client) : base(client, "aggregation")
 {
     Users = new Aggregation.UsersClient(client);
 }
Exemplo n.º 8
0
 protected internal NotificationsClient(MisskeyClient client) : base(client, "notifications")
 {
 }
Exemplo n.º 9
0
 protected internal UsersClient(MisskeyClient client) : base(client, "users")
 {
     Lists = new ListsClient(client);
 }
Exemplo n.º 10
0
 protected internal ReactionsClient(MisskeyClient client) : base(client, "notes/reactions")
 {
 }
Exemplo n.º 11
0
 protected internal FavoritesClient(MisskeyClient client) : base(client, "notes/favorites")
 {
 }
Exemplo n.º 12
0
 protected internal EmojiClient(MisskeyClient client) : base(client, "admin/emoji")
 {
 }
Exemplo n.º 13
0
 protected internal FoldersClient(MisskeyClient client) : base(client, "drive/folders")
 {
 }
Exemplo n.º 14
0
 protected internal AppClient(MisskeyClient client) : base(client, "app")
 {
 }
Exemplo n.º 15
0
 protected internal ListsClient(MisskeyClient client) : base(client, "users/lists")
 {
 }
Exemplo n.º 16
0
 protected internal UsersClient(MisskeyClient client) : base(client, "aggregation/users")
 {
 }
Exemplo n.º 17
0
 protected internal BlockingClient(MisskeyClient client) : base(client, "blocking")
 {
 }
Exemplo n.º 18
0
 protected internal UsernameClient(MisskeyClient client) : base(client, "username")
 {
 }
Exemplo n.º 19
0
 protected internal ChartsClient(MisskeyClient client) : base(client, "charts")
 {
     User = new UserClient(client);
 }
Exemplo n.º 20
0
 protected internal FederationClient(MisskeyClient client) : base(client, "federation")
 {
 }
Exemplo n.º 21
0
 protected internal MuteClient(MisskeyClient client) : base(client, "mute")
 {
 }
Exemplo n.º 22
0
 protected internal FilesClient(MisskeyClient client) : base(client, "drive/files")
 {
 }
Exemplo n.º 23
0
 protected internal MessagingClient(MisskeyClient client) : base(client, "messaging")
 {
     Messages = new MessagesClient(client);
 }
Exemplo n.º 24
0
 protected internal MyClient(MisskeyClient client) : base(client, "my")
 {
 }
Exemplo n.º 25
0
 protected internal PollsClient(MisskeyClient client) : base(client, "notes/polls")
 {
 }
Exemplo n.º 26
0
 protected internal FollowingClient(MisskeyClient client) : base(client, "following")
 {
     Requests = new RequestsClient(client);
 }
Exemplo n.º 27
0
 protected internal RequestsClient(MisskeyClient client) : base(client, "following/requests")
 {
 }
Exemplo n.º 28
0
 protected internal AdminClient(MisskeyClient client) : base(client, "admin")
 {
     Emoji = new Admin.EmojiClient(client);
 }
Exemplo n.º 29
0
 protected internal UserClient(MisskeyClient client) : base(client, "charts/user")
 {
 }
Exemplo n.º 30
0
 protected internal HashtagsClient(MisskeyClient client) : base(client, "hashtags")
 {
 }