我想用Node.js创建一个Telegram Bot,并且正在使用Telegraf。我知道我可以回答这样的消息:
app.hears('hi', (ctx) => ctx.reply('Hey there!'))
Run Code Online (Sandbox Code Playgroud)
但是,如何在没有收到消息的情况下发送消息?我想读取文件,并且总是在文件更改后才想发送消息。
const Telegraf = require('telegraf');
var fs = require('fs');
const app = new Telegraf(process.env.BOT_TOKEN);
var filePath = "C:\\path\\to\\my\\file.txt";
fs.watchFile(filePath, function() {
    file = fs.readFileSync(filePath);
    // Send message to chat or group with the file content here
    console.log("File content at: " + new Date() + " is: \n" + file);
})
Run Code Online (Sandbox Code Playgroud)
如果有人可以帮助我会很好。
我有一个范围很大的电子表格:A2-AJ1900。有些列具有静态值,有些列具有公式,有些列具有混合值,因此有时是静态值,有时是公式。我想用脚本更新每一行并节省时间,我想构建一个包含所有值和公式的数组,然后我想通过一次调用将该数组写入电子表格。那可能吗?或者我必须将该数组拆分为静态值和公式列吗?我认为这不会是一个大问题,但是我应该如何处理混合列呢?如果我通过一次调用更新每个单元格,这将非常复杂,并且脚本将需要太长的时间。对于这样的情况,难道就没有办法改善吗?
我想创建一个命名管道,然后写入它,然后我想读取它。这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#define FIFO "fifo0001"
int main(intargc, char *argv[]){
    char input[256];
    FILE *fp;
    char str[50];
    printf("Please write some text:\n");
    scanf("%s", input);
    unlink(FIFO); /* Because it already exists, unlink it before */
    umask(0);
    if(mkfifo(FIFO, 0666) == -1){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    if((fp = fopen(FIFO, "a")) == NULL){
        printf("Something went wrong");
        return EXIT_FAILURE;
    }
    fprintf(fp, "%s", input);
    if(fgets(str, 50, fp) != NULL){
        puts(str);
    }
    fclose(fp); …Run Code Online (Sandbox Code Playgroud) 我正在尝试用npm安装离子框架.我现在有些问题.起初我尝试使用最新的节点版本(6.8),当我安装离子时,我总是遇到minimatch版本的错误.现在我卸载了节点并安装了LTS版本(4.6.0).现在,当我运行"npm install -g ionic"时,没有错误或警告.但是当我运行"npm install -g cordova"时,我再次发出了迷你匹配警告.现在,当我尝试使用"离子启动测试选项卡--v2"启动离子项目时,我收到以下消息:
... Installing npm packages... Error with start undefined Error Initializing app: There was an error with the spawned command: npminstall There was an error with the spawned command: npminstall Caught exception: undefined ...
$离子信息
Your system information: Cordova CLI: 6.3.1 Ionic Framework Version: 2.0.0-rc.1 Ionic CLI Version: 2.1.0 Ionic App Lib Version: 2.0.0-beta.20 OS: Node Version: v4.6.0
$ npm过时(在新的Ionic Project文件夹中)
Package Current Wanted Latest Location @angular/compiler-cli 0.6.4 0.6.4 2.1.0 @angular\compiler-cli @ionic/app-scripts 0.0.30 0.0.30 …
我有一个使用片段的 NavigationDrawer 活动。在我的一个片段中,我想将数据从 Firebase 数据库加载到 RecyclerView。
所以我有一个 ArrayList 用于存储在数据库中的对象。然后我将一个 ValueEventListener 添加到我的数据库引用中,我将数据库中的对象添加到数组列表中。然后我将 ArrayList 提供给 RecyclerView Adapter,它应该使用我的对象创建列表。
当我使用 addListenerForSingleValueEvent 它永远不会工作时,我总是得到一个空的 RecyclerView。当我使用 addValueEventListener 时,它在开始时都不起作用,但是当我将手机的方向切换到横向时,数据突然出现。如果我回到正常方向,它仍然存在。但不是在我打开片段的开始。
这是我的片段类代码:
public class LogFragment extends Fragment {
    private RecyclerView recyclerView;
    private RecyclerView.Adapter rvAdapter;
    private RecyclerView.LayoutManager rvLayoutManager;
    private ArrayList<LogEntry> entries;
    private DatabaseReference databaseReference;
    private DatabaseReference logReference;
    private FirebaseAuth firebaseAuth;
    private FirebaseUser firebaseUser;
    public LogFragment() {
        // Required empty public constructor
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_log, container, false);
        databaseReference = FirebaseDatabase.getInstance().getReference(); …Run Code Online (Sandbox Code Playgroud) android android-fragments firebase firebase-realtime-database
在我的Ionic 2应用程序中,硬件后退按钮(android,windows)应该像默认情况下那样工作,但有一个例外:如果没有任何东西可以返回,他不应该退出应用程序.
我知道我可以这样做:
platform.ready().then(() => {
    platform.registerBackButtonAction(() => {
        // Default action with the exception here
    },);
});
Run Code Online (Sandbox Code Playgroud)
但是我现在必须如何做到这一点,让它作为默认工作,但有一个例外?在该函数的离子1文档中,存在不同情况的优先级.但我认为离子2改变了!?因为在离子2文档中没有这些优先级.我试图将优先级设置为99,因为那时一切都应该作为默认值.但是现在侧面菜单不能再关闭了,这就是为什么我认为离子1的优先级已经改变了,因为在离子1文档中,sidemenu的优先级是150,这就是为什么我的函数应该被忽略的原因.有人可以帮我吗?
我尝试用C创建一个简单的计算器.数字和运算符应该是参数.我已经有了main函数和一个calculate函数:
主要:
int main(int argc, char *argv[]){
    long result;
    long number1 = strtol(argv[1], NULL, 10);
    long number2 = strtol(argv[3], NULL, 10);
    result = calculate(number1, number2, argv[2]);
    printf("Result: %li", result);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
计算:
long calculate(long number1, long number2, char operator){
    long result;
    switch(operator){
        case '+': result = number1 + number2; break;
        case '-': result = number1 - number2; break;
    }
    return result;
}
Run Code Online (Sandbox Code Playgroud)
当我启动这样的程序时:
./calc 1 + 2
结果为0.我认为运算符参数存在问题,因为当我写'+'而不是argv [2]时它会起作用.但我不知道如何解决它,它也适用于参数.
我有一个海关细胞的桌子视图.每个单元格都有两个文本字段.桌子下面是一个按钮.我在表视图控制器中有一个"buttonPressed"动作.如何在此方法中获取每个表行的文本字段值?
这是自定义单元头文件:
...
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITextField *age;
@end
Run Code Online (Sandbox Code Playgroud)
在表视图控制器中我有这个方法:
- (IBAction)saveBtnPressed:(id)sender{
    // Store the text field values of each row in an array here
}
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
当我开始一个新的选项卡式活动时,我有这个生成的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="eis1617.muellerkimmeyer.app.MainActivity">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">
        </android.support.v7.widget.Toolbar>
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我该如何更改它,标签栏将放在屏幕的底部?在TabLayout标签上我已经尝试添加android:layout_gravity ="bottom",但它没有改变任何东西.
如何在离子2侧面菜单中添加Logout选项卡?如果您已登录,则表明您正在使用DashboardPage.现在我有一个菜单项"Logout",它只是带我到主页.这是app.component.ts中包含所有菜单项的pages数组:
this.pages = [
    {title: 'Dashboard', component: DashboardPage},
    ...
    {title: 'Logout', component: HomePage}
];
Run Code Online (Sandbox Code Playgroud)
但现在我需要在注销后面添加逻辑,而不仅仅是页面切换.当我点击Logout选项卡而不是仅转到HomePage时,是否可以调用函数logout()?
编辑:
这是openPage函数:
openPage(page) {
    this.nav.setRoot(page.component);
}
Run Code Online (Sandbox Code Playgroud) 我想用 fork() 创建 3 个子进程。这是我创建一个子进程的代码:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void main(){
    int pid = fork();
    if(pid < 0){
        /* was not successfully */
    }
    else if (pid > 0){
        /* Parent process */
    }
    else{
        /* Child process */
        for (int i = 0; i < 20; i++){
            printf("1");
            usleep(1000);
        }
        exit(0);
    }
}
Run Code Online (Sandbox Code Playgroud)
子进程应该打印 20 次数字 1,并在每次后休眠 1 毫秒。
我知道我不能只使用 fork() 3 次,因为那样我将得到 7 个子进程。但我怎样才能得到正好3呢?我怎样才能做到每个子进程都打印另一个数字?例如,第一个进程编号为 1,第二个进程编号为 2,第三个进程编号为 3。
父进程应该使用 waitpid() 来等待所有 3 个子进程。如果他们完成了,家长应该打印一条消息。但是这里如何使用waitpid呢?
c ×3
ionic2 ×3
android ×2
node.js ×2
angular ×1
argv ×1
back-button ×1
calculator ×1
cordova ×1
custom-cell ×1
default ×1
exit ×1
fifo ×1
file ×1
firebase ×1
fopen ×1
fork ×1
install ×1
ionic3 ×1
ios ×1
objective-c ×1
parameters ×1
pipe ×1
pointers ×1
process ×1
telegraf ×1
telegram ×1
telegram-bot ×1
typescript ×1
uitextfield ×1
waitpid ×1