Commit 93483bf3 authored by Guillaume Vagner's avatar Guillaume Vagner
Browse files

changed!

parent c32a7d23
var mysql = require('promise-mysql');
const config = require('./config');
function query(req) {
return mysql.createConnection(
config.mysql
).then(connection => {
return Promise.all([
connection.query(req),
connection
])
}).then(([rep, connection]) => {
connection.end();
return rep;
}).catch(error => {
//logs out the error
console.error(error);
});
}
Promise.all([
query(`CREATE TABLE IF NOT EXISTS channel(
chatId INT PRIMARY KEY NOT NULL,
username TEXT,
state TEXT,
token TEXT,
refresh TEXT,
expiration TEXT,
schedule TEXT
)`),
query(`CREATE TABLE IF NOT EXISTS groups(
chatId INT NOT NULL,
grp INT,
primary key (chatId, grp)
)`)
]).then(_ => {
console.log('[mariadb] connected to database')
})
function getChanByChatId(chatId) {
return query(`
SELECT *
FROM channel
WHERE chatId = ${chatId}
`).then(rep => rep[0]);
}
function createChan(data) {
return query(`
INSERT INTO channel
VALUES (${data.chatId}, "${data.username}", "${data.state}", "${data.token}", "${data.refresh}", "${data.expiration}", "${data.schedule}")
`)
}
function deleteChanByChatId(chatId) {
return query(`DELETE FROM channel WHERE chatId = ${chatId}`);
}
function modifyChan(data) {
return query(`
UPDATE channel
SET username = "${data.username}",
state = "${data.state}",
token = "${data.token}",
refresh = "${data.refresh}",
expiration = "${data.expiration}",
schedule = "${data.schedule}"
WHERE chatId = ${data.chatId}
`).then(_ => {
return getChanByChatId(data.chatId)
})
}
function getChanByState(state) {
return query(`
SELECT *
FROM channel
WHERE state = "${state}"
`).then(rep => rep[0]);
}
function addGroup(chatId, groupId) {
return query(`
INSERT INTO groups
VALUES (${chatId}, ${groupId})
`);
}
function getGroups(chatId) {
return query(`
SELECT grp
FROM groups
WHERE chatId = ${chatId}
`).then(rep => {
return rep.map(element => element.grp);
})
}
module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, getGroups };
\ No newline at end of file
const mongoose = require('../mongoose');
const channelSchema = new mongoose.Schema({
token: String,
refresh: String,
expiration: Date,
username: String,
chatId: Number,
state: String,
groups: [Number],
scheduleTime: { type: String, validate: /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/ }
})
module.exports = mongoose.model('Channel', channelSchema);
\ No newline at end of file
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/botday', { useNewUrlParser: true })
.then(() => console.log('[mongoose] Connection succesful'))
.catch((err) => console.error(err));
module.exports = mongoose;
\ No newline at end of file
../semver/bin/semver
\ No newline at end of file
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
# Installation
> `npm install --save @types/bluebird`
# Summary
This package contains type definitions for bluebird (https://github.com/petkaantonov/bluebird).
# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bluebird
Additional Details
* Last updated: Thu, 13 Dec 2018 21:05:14 GMT
* Dependencies: none
* Global values: none
# Credits
These definitions were written by Leonard Hecker <https://github.com/lhecker>.
This diff is collapsed.
{
"_from": "@types/bluebird@^3.5.19",
"_id": "@types/bluebird@3.5.25",
"_inBundle": false,
"_integrity": "sha512-yfhIBix+AIFTmYGtkC0Bi+XGjSkOINykqKvO/Wqdz/DuXlAKK7HmhLAXdPIGsV4xzKcL3ev/zYc4yLNo+OvGaw==",
"_location": "/@types/bluebird",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "@types/bluebird@^3.5.19",
"name": "@types/bluebird",
"escapedName": "@types%2fbluebird",
"scope": "@types",
"rawSpec": "^3.5.19",
"saveSpec": null,
"fetchSpec": "^3.5.19"
},
"_requiredBy": [
"/promise-mysql"
],
"_resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.25.tgz",
"_shasum": "59188b871208092e37767e4b3d80c3b3eaae43bd",
"_spec": "@types/bluebird@^3.5.19",
"_where": "/home/capsule_man/developpement/happy-botday/node_modules/promise-mysql",
"bugs": {
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
},
"bundleDependencies": false,
"contributors": [
{
"name": "Leonard Hecker",
"url": "https://github.com/lhecker"
}
],
"dependencies": {},
"deprecated": false,
"description": "TypeScript definitions for bluebird",
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
"license": "MIT",
"main": "",
"name": "@types/bluebird",
"repository": {
"type": "git",
"url": "git+https://github.com/DefinitelyTyped/DefinitelyTyped.git"
},
"scripts": {},
"typeScriptVersion": "2.8",
"types": "index",
"typesPublisherContentHash": "84f287bba570664e8a87b6b30953506fa39d74685adb9b86fb0389dad064398f",
"version": "3.5.25"
}
MIT License
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
# Installation
> `npm install --save @types/mysql`
# Summary
This package contains type definitions for mysql (https://github.com/mysqljs/mysql).
# Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mysql
Additional Details
* Last updated: Thu, 31 May 2018 20:09:03 GMT
* Dependencies: stream, tls, node
* Global values: none
# Credits
These definitions were written by William Johnston <https://github.com/wjohnsto>, Kacper Polak <https://github.com/kacepe>, Krittanan Pingclasai <https://github.com/kpping>, James Munro <https://github.com/jdmunro>.
// Type definitions for mysql 2.15
// Project: https://github.com/mysqljs/mysql
// Definitions by: William Johnston <https://github.com/wjohnsto>
// Kacper Polak <https://github.com/kacepe>
// Krittanan Pingclasai <https://github.com/kpping>
// James Munro <https://github.com/jdmunro>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
/// <reference types="node" />
import stream = require("stream");
import tls = require("tls");
export interface EscapeFunctions {
escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
escapeId(value: string, forbidQualified?: boolean): string;
format(sql: string, values: any[], stringifyObjects?: boolean, timeZone?: string): string;
}
// implements EscapeFunctions
export function escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
export function escapeId(value: string, forbidQualified?: boolean): string;
export function format(sql: string, values: any[], stringifyObjects?: boolean, timeZone?: string): string;
export function createConnection(connectionUri: string | ConnectionConfig): Connection;
export function createPool(config: PoolConfig | string): Pool;
export function createPoolCluster(config?: PoolClusterConfig): PoolCluster;
export function raw(sql: string): () => string;
export interface Connection extends EscapeFunctions {
config: ConnectionConfig;
state: 'connected' | 'authenticated' | 'disconnected' | 'protocol_error' | string;
threadId: number | null;
createQuery: QueryFunction;
connect(callback?: (err: MysqlError, ...args: any[]) => void): void;
connect(options: any, callback?: (err: MysqlError, ...args: any[]) => void): void;
changeUser(options: ConnectionOptions, callback?: (err: MysqlError) => void): void;
changeUser(callback: (err: MysqlError) => void): void;
beginTransaction(options?: QueryOptions, callback?: (err: MysqlError) => void): void;
beginTransaction(callback: (err: MysqlError) => void): void;
commit(options?: QueryOptions, callback?: (err: MysqlError) => void): void;
commit(callback: (err: MysqlError) => void): void;
rollback(options?: QueryOptions, callback?: (err: MysqlError) => void): void;
rollback(callback: (err: MysqlError) => void): void;
query: QueryFunction;
ping(options?: QueryOptions, callback?: (err: MysqlError) => void): void;
ping(callback: (err: MysqlError) => void): void;
statistics(options?: QueryOptions, callback?: (err: MysqlError) => void): void;
statistics(callback: (err: MysqlError) => void): void;
end(callback?: (err: MysqlError, ...args: any[]) => void): void;
end(options: any, callback: (err: MysqlError, ...args: any[]) => void): void;
destroy(): void;
pause(): void;
resume(): void;
on(ev: 'drain' | 'connect', callback: () => void): Connection;
on(ev: 'end', callback: (err?: MysqlError) => void): Connection;
on(ev: 'fields', callback: (fields: any[]) => void): Connection;
on(ev: 'error', callback: (err: MysqlError) => void): Connection;
on(ev: 'enqueue', callback: (...args: any[]) => void): Connection;
on(ev: string, callback: (...args: any[]) => void): this;
}
export interface PoolConnection extends Connection {
release(): void;
end(): void;
destroy(): void;
}
export interface Pool extends EscapeFunctions {
config: PoolConfig;
getConnection(callback: (err: MysqlError, connection: PoolConnection) => void): void;
acquireConnection(connection: PoolConnection, callback: (err: MysqlError, connection: PoolConnection) => void): void;
releaseConnection(connection: PoolConnection): void;
end(callback?: (err: MysqlError) => void): void;
query: QueryFunction;
on(ev: 'connection' | 'acquire' | 'release', callback: (connection: PoolConnection) => void): Pool;
on(ev: 'error', callback: (err: MysqlError) => void): Pool;
on(ev: 'enqueue', callback: (err?: MysqlError) => void): Pool;
on(ev: string, callback: (...args: any[]) => void): Pool;
}
export interface PoolCluster {
config: PoolClusterConfig;
add(config: PoolConfig): void;
add(id: string, config: PoolConfig): void;
end(callback?: (err: MysqlError) => void): void;
of(pattern: string, selector?: string): Pool;
of(pattern: undefined | null | false, selector: string): Pool;
/**
* remove all pools which match pattern
*/
remove(pattern: string): void;
getConnection(callback: (err: MysqlError, connection: PoolConnection) => void): void;
getConnection(pattern: string, callback: (err: MysqlError, connection: PoolConnection) => void): void;
getConnection(pattern: string, selector: string, callback: (err: MysqlError, connection: PoolConnection) => void): void;
on(ev: string, callback: (...args: any[]) => void): PoolCluster;
on(ev: 'remove' | 'offline' | 'remove', callback: (nodeId: string) => void): PoolCluster;
}
// related to Query
export type packetCallback = (packet: any) => void;
export interface Query {
/**
* Template query
*/
sql: string;
/**
* Values for template query
*/
values?: string[];
/**
* Default true
*/
typeCast?: TypeCast;
/**
* Default false
*/
nestedTables: boolean;
/**
* Emits a query packet to start the query
*/
start(): void;
/**
* Determines the packet class to use given the first byte of the packet.
*
* @param byte The first byte of the packet
* @param parser The packet parser
*/
determinePacket(byte: number, parser: any): any;
OkPacket: packetCallback;
ErrorPacket: packetCallback;
ResultSetHeaderPacket: packetCallback;
FieldPacket: packetCallback;
EofPacket: packetCallback;
RowDataPacket(packet: any, parser: any, connection: Connection): void;
/**
* Creates a Readable stream with the given options
*
* @param options The options for the stream. (see readable-stream package)
*/
stream(options?: stream.ReadableOptions): stream.Readable;
on(ev: string, callback: (...args: any[]) => void): Query;
on(ev: 'result', callback: (row: any, index: number) => void): Query;
on(ev: 'error', callback: (err: MysqlError) => void): Query;
on(ev: 'fields', callback: (fields: FieldInfo[], index: number) => void): Query;
on(ev: 'packet', callback: (packet: any) => void): Query;
on(ev: 'end', callback: () => void): Query;
}
export interface GeometryType extends Array<{x: number, y: number} | GeometryType> {
x: number;
y: number;
}
export type TypeCast = boolean | (
(field: FieldInfo
& { type: string, length: number, string(): string, buffer(): Buffer, geometry(): null | GeometryType},
next: () => void) => any);
export type queryCallback = (err: MysqlError | null, results?: any, fields?: FieldInfo[]) => void;
// values can be non [], see custom format (https://github.com/mysqljs/mysql#custom-format)
export interface QueryFunction {
(query: Query): Query;
(options: string | QueryOptions, callback?: queryCallback): Query;
(options: string, values: any, callback?: queryCallback): Query;
}
export interface QueryOptions {
/**
* The SQL for the query
*/
sql: string;
/**
* Values for template query
*/
values?: any;
/**
* Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
* operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
* operations through the client. This means that when a timeout is reached, the connection it occurred on will be
* destroyed and no further operations can be performed.
*/
timeout?: number;
/**
* Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
* nested as tableName_fieldName
*/
nestTables?: any;
/**
* Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
* to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
*
* You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
*
* WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
*
* field.string()
* field.buffer()
* field.geometry()
*
* are aliases for
*
* parser.parseLengthCodedString()
* parser.parseLengthCodedBuffer()
* parser.parseGeometryValue()
*
* You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
*/
typeCast?: TypeCast;
}
export interface ConnectionOptions {
/**
* The MySQL user to authenticate as
*/
user?: string;
/**
* The password of that MySQL user
*/
password?: string;
/**
* Name of the database to use for this connection
*/
database?: string;
/**
* The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci).
* If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
* (Default: 'UTF8_GENERAL_CI')
*/
charset?: string;
/**
* Number of milliseconds
*/
timeout?: number;
}
export interface ConnectionConfig extends ConnectionOptions {
/**
* The hostname of the database you are connecting to. (Default: localhost)
*/
host?: string;
/**
* The port number to connect to. (Default: 3306)
*/
port?: number;
/**
* The source IP address to use for TCP connection
*/
localAddress?: string;
/**
* The path to a unix domain socket to connect to. When used host and port are ignored