Skip to content

Commit

Permalink
Merge pull request #129 from vvd170501/telegram-plugin-fixes
Browse files Browse the repository at this point in the history
Telegram plugin fixes
  • Loading branch information
blackav authored Dec 29, 2022
2 parents 6242d18 + ec40b84 commit d482fb4
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
24 changes: 15 additions & 9 deletions bin/ej-jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,31 +1922,37 @@ void *__attribute__((unused))
job_server_force_link_2[] =
{
base64u_decode,
xml_parse_full_cookie,
xml_err_elem_undefined_s,
cJSON_Delete,
cJSON_GetArrayItem,
cJSON_GetArraySize,
cJSON_GetObjectItem,
cJSON_Parse,
ej_uuid_parse,
userprob_plugin_get,
task_New,
userprob_plugin_get,
xml_err_elem_undefined_s,
xml_parse_full_cookie,
xml_parse_int,
xml_parse_ip,
xml_parse_ipv6_2,
xml_unparse_full_cookie,
xml_unparse_ip,
xml_unparse_ipv6,
};

#if HAVE_LIBMONGOC - 0 > 0
void *
job_server_force_link[] =
{
cJSON_Delete,
ej_bson_parse_string_new,
xml_parse_int,
};
#endif

#if HAVE_LIBMONGO_CLIENT - 0 == 1
#elif HAVE_LIBMONGO_CLIENT - 0 == 1

void *
job_server_force_link[] =
{
cJSON_Delete,
ej_bson_parse_string,
xml_parse_int,
};

#endif
1 change: 1 addition & 0 deletions plugins/telegram/mongo_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#endif

#include <stdio.h>
#include <string.h>

#define MONGO_RETRY_TIMEOUT 60

Expand Down
7 changes: 4 additions & 3 deletions plugins/telegram/mysql_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "ejudge/xalloc.h"
#include "ejudge/errlog.h"

#include <stdio.h>

static struct generic_conn *
free_func(struct generic_conn *gc)
{
Expand Down Expand Up @@ -526,10 +528,9 @@ token_remove_expired_func(

mi->lock(md);
cmd_f = open_memstream(&cmd_s, &cmd_z);
fprintf(cmd_f, "DELETE FROM %stelegram_tokens WHERE expiry_time = '",
fprintf(cmd_f, "DELETE FROM %stelegram_tokens WHERE expiry_time = ",
md->table_prefix);
mi->write_timestamp(md, cmd_f, NULL, current_time);
fprintf(cmd_f, "'");
fclose(cmd_f); cmd_f = NULL;
if (mi->simple_query(md, cmd_s, cmd_z) < 0)
db_error_fail(md);
Expand Down Expand Up @@ -963,7 +964,7 @@ subscription_fetch_func(
return ts;
}

ts = telegram_subscription_create(bot_id, contest_id, user_id);
ts = telegram_subscription_create(bot_id, user_id, contest_id);
mi->unlock(md);
gc->vt->subscription_save(gc, ts);
return ts;
Expand Down
13 changes: 7 additions & 6 deletions plugins/telegram/telegram.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
#include <curl/curl.h>
#endif

#include <pthread.h>
#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>

static struct common_plugin_data *
init_func(void);
Expand Down Expand Up @@ -780,7 +781,7 @@ packet_handler_telegram_reviewed(int uid, int argc, char **argv, void *user)
goto cleanup;
}

sub = state->conn->vt->subscription_fetch(state->conn, argv[1], contest_id, user_id);
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], user_id, contest_id);
if (!sub) goto cleanup;
if (!sub->review_flag) goto cleanup;
if (!sub->chat_id) {
Expand Down Expand Up @@ -860,7 +861,7 @@ packet_handler_telegram_replied(int uid, int argc, char **argv, void *user)
goto cleanup;
}

sub = state->conn->vt->subscription_fetch(state->conn, argv[1], contest_id, user_id);
sub = state->conn->vt->subscription_fetch(state->conn, argv[1], user_id, contest_id);
if (!sub) goto cleanup;
if (!sub->reply_flag) goto cleanup;
if (!sub->chat_id) {
Expand Down Expand Up @@ -1444,11 +1445,11 @@ handle_incoming_message(
} else if (!r) {
send_result = send_message(state, bs, mc, "Token expired. Operation failed.", NULL, NULL);
} else {
sub = state->conn->vt->subscription_fetch(state->conn, bs->bot_id, token->contest_id, token->user_id);
sub = state->conn->vt->subscription_fetch(state->conn, bs->bot_id, token->user_id, token->contest_id);
if (!sub && !strcmp(tcs->command, "/unsubscribe")) {
send_result = send_message(state, bs, mc, "You have no subscriptions. Nothing to unsubscribe.", NULL, "{ \"hide_keyboard\": true}");
} else {
if (!sub) sub = telegram_subscription_create(bs->bot_id, token->contest_id, token->user_id);
if (!sub) sub = telegram_subscription_create(bs->bot_id, token->user_id, token->contest_id);
if (!strcmp(tcs->command, "/subscribe")) {
if (tcs->review_flag) sub->review_flag = 1;
if (tcs->reply_flag) sub->reply_flag = 1;
Expand Down
5 changes: 4 additions & 1 deletion plugins/telegram/telegram_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* GNU General Public License for more details.
*/

#include "telegram_chat.h"

#include "ejudge/bson_utils.h"

#include "ejudge/xalloc.h"
#include "ejudge/errlog.h"
#include "ejudge/osdeps.h"

#include "telegram_chat.h"
#include "mongo_conn.h"

#if HAVE_LIBMONGOC - 0 > 1
Expand All @@ -31,6 +33,7 @@
#endif

#include <errno.h>
#include <string.h>

#if HAVE_LIBMONGOC - 0 > 0
struct _bson_t;
Expand Down
5 changes: 4 additions & 1 deletion plugins/telegram/telegram_chat_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* GNU General Public License for more details.
*/

#include "telegram_chat_state.h"

#include "ejudge/bson_utils.h"

#include "ejudge/xalloc.h"
#include "ejudge/errlog.h"
#include "ejudge/osdeps.h"

#include "telegram_chat_state.h"
#include "mongo_conn.h"

#if HAVE_LIBMONGOC - 0 > 1
Expand All @@ -31,6 +33,7 @@
#endif

#include <errno.h>
#include <string.h>

#if HAVE_LIBMONGOC - 0 > 0
struct _bson_t;
Expand Down
7 changes: 4 additions & 3 deletions plugins/telegram/telegram_subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#endif

#include <errno.h>
#include <stdio.h>
#include <string.h>

#if HAVE_LIBMONGOC - 0 > 0
Expand Down Expand Up @@ -61,7 +62,7 @@ telegram_subscription_free(struct telegram_subscription *sub)
}

struct telegram_subscription *
telegram_subscription_create(const unsigned char *bot_id, int contest_id, int user_id)
telegram_subscription_create(const unsigned char *bot_id, int user_id, int contest_id)
{
struct telegram_subscription *sub = NULL;
unsigned char buf[1024];
Expand All @@ -72,8 +73,8 @@ telegram_subscription_create(const unsigned char *bot_id, int contest_id, int us
XCALLOC(sub, 1);
sub->_id = xstrdup(buf);
sub->bot_id = xstrdup(bot_id);
sub->contest_id = contest_id;
sub->user_id = user_id;
sub->contest_id = contest_id;
return sub;
}

Expand Down Expand Up @@ -207,7 +208,7 @@ telegram_subscription_unparse_bson(const struct telegram_subscription *sub)
}

struct telegram_subscription *
telegram_subscription_fetch(struct mongo_conn *conn, const unsigned char *bot_id, int contest_id, int user_id)
telegram_subscription_fetch(struct mongo_conn *conn, const unsigned char *bot_id, int user_id, int contest_id)
{
#if HAVE_LIBMONGOC - 0 > 0
if (!conn->b.vt->open(&conn->b)) return NULL;
Expand Down
2 changes: 1 addition & 1 deletion plugins/telegram/telegram_subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ struct telegram_subscription
struct telegram_subscription *
telegram_subscription_free(struct telegram_subscription *subscription);
struct telegram_subscription *
telegram_subscription_create(const unsigned char *bot_id, int contest_id, int user_id);
telegram_subscription_create(const unsigned char *bot_id, int user_id, int contest_id);

#endif
5 changes: 4 additions & 1 deletion plugins/telegram/telegram_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
* GNU General Public License for more details.
*/

#include "telegram_user.h"

#include "ejudge/bson_utils.h"

#include "ejudge/xalloc.h"
#include "ejudge/errlog.h"
#include "ejudge/osdeps.h"

#include "telegram_user.h"
#include "mongo_conn.h"

#if HAVE_LIBMONGOC - 0 > 1
Expand All @@ -31,6 +33,7 @@
#endif

#include <errno.h>
#include <string.h>

#if HAVE_LIBMONGOC - 0 > 0
struct _bson_t;
Expand Down

0 comments on commit d482fb4

Please sign in to comment.