Skip to content

Commit

Permalink
selected some parts of stakwork#287
Browse files Browse the repository at this point in the history
lower warning count to 466
  • Loading branch information
antonilol committed Jun 13, 2022
1 parent 0830ac2 commit b3fcfa2
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 207 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dev": "rm -rf dist/ && tsc && cp -r public dist/public && node --inspect ./dist/app.js",
"build-binaries": "rm -rf dist/ && tsc && cp config/app.json dist/config/app.json && cp config/config.json dist/config/config.json && pkg . --target node12-alpine-x64,node12-macos-x64 --out-path binaries",
"start-ecs": "cp config/app.json dist/config/app.json && cp config/config.json dist/config/config.json && export NODE_ENV=production && node --max-old-space-size=128 dist/app.js",
"lint": "eslint ./src/*.ts ./src/**/*.ts --fix --max-warnings 517"
"lint": "eslint ./src/*.ts ./src/**/*.ts --fix --max-warnings 466"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 2 additions & 2 deletions src/builtin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import * as GitBot from './git'
import { Msg } from '../network/interfaces'
import { buildBotPayload } from '../controllers/bots'

async function init() {
async function init(): Promise<void> {
MotherBot.init()
WelcomeBot.init()
LoopBot.init()
GitBot.init()
}

function builtinBotEmit(msg: Msg) {
function builtinBotEmit(msg: Msg): void {
setTimeout(() => {
SphinxBot._emit('message', buildBotPayload(msg))
}, 1200)
Expand Down
40 changes: 21 additions & 19 deletions src/builtin/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { spawn } from 'child_process'
import { loadConfig } from '../utils/config'
import { sphinxLogger } from '../utils/logger'
import { getTribeOwnersChatByUUID } from '../utils/tribes'
import validate from 'bitcoin-address-validation'

const config = loadConfig()

const validate = require('bitcoin-address-validation')
const msg_types = Sphinx.MSG_TYPE

let initted = false

// const baseurl = 'https://localhost:8080'

export function init() {
export function init(): void {
if (initted) return
initted = true

Expand Down Expand Up @@ -182,25 +182,27 @@ export function init() {
}
switch (cmd) {
case 'help':
const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setTitle('LoopBot Commands:')
.addFields([
{
name: 'Send to your on-chain address',
value: '/loopout {ADDRESS} {AMOUNT}',
},
{ name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Help', value: '/loopout help' },
])
.setThumbnail(botSVG)
message.channel.send({ embed })
message.channel.send({
embed: new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setTitle('LoopBot Commands:')
.addFields([
{
name: 'Send to your on-chain address',
value: '/loopout {ADDRESS} {AMOUNT}',
},
{ name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Help', value: '/loopout help' },
])
.setThumbnail(botSVG)
})
return
default:
const embed2 = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('Command not recognized')
message.channel.send({ embed: embed2 })
message.channel.send({
embed: new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('Command not recognized')
})
return
}
} // end else
Expand Down
68 changes: 35 additions & 33 deletions src/builtin/mother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const builtInBotNames = {
git: 'GitBot',
}

export function init() {
export function init(): void {
const client = new Sphinx.Client()
client.login('_', finalAction)

Expand All @@ -45,7 +45,7 @@ export function init() {
if (!isAdmin) return

switch (cmd) {
case 'install':
case 'install': {
if (arr.length < 3) return
const botName = arr[2]

Expand Down Expand Up @@ -106,8 +106,8 @@ export function init() {
}
}
return true

case 'uninstall':
}
case 'uninstall': {
if (arr.length < 3) return
const botName2 = arr[2]
const chat2 = await getTribeOwnersChatByUUID(message.channel.id)
Expand All @@ -132,8 +132,8 @@ export function init() {
.setDescription('Cant find a bot by that name')
return message.channel.send({ embed })
}

case 'search':
}
case 'search': {
if (arr.length < 2) return
const query = arr[2]
const bots = await searchBots(query)
Expand All @@ -143,35 +143,37 @@ export function init() {
.setDescription('No bots found')
return message.channel.send({ embed })
}
const embed3 = new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bots:')
.addFields(
bots.map((b) => {
const maxLength = 35
const value =
b.description.length > maxLength
? b.description.substr(0, maxLength) + '...'
: b.description
return { name: b.unique_name, value }
})
)
.setThumbnail(botSVG)
message.channel.send({ embed: embed3 })
message.channel.send({
embed: new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bots:')
.addFields(
bots.map((b) => {
const maxLength = 35
const value =
b.description.length > maxLength
? b.description.substr(0, maxLength) + '...'
: b.description
return { name: b.unique_name, value }
})
)
.setThumbnail(botSVG)
})
return true

}
default:
const embed = new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bot Commands:')
.addFields([
{ name: 'Search for bots', value: '/bot search {SEARCH_TERM}' },
{ name: 'Install a new bot', value: '/bot install {BOTNAME}' },
{ name: 'Uninstall a bot', value: '/bot uninstall {BOTNAME}' },
{ name: 'Help', value: '/bot help' },
])
.setThumbnail(botSVG)
message.channel.send({ embed })
message.channel.send({
embed: new Sphinx.MessageEmbed()
.setAuthor('MotherBot')
.setTitle('Bot Commands:')
.addFields([
{ name: 'Search for bots', value: '/bot search {SEARCH_TERM}' },
{ name: 'Install a new bot', value: '/bot install {BOTNAME}' },
{ name: 'Uninstall a bot', value: '/bot uninstall {BOTNAME}' },
{ name: 'Help', value: '/bot help' },
])
.setThumbnail(botSVG)
})
}
})
}
Expand Down
31 changes: 16 additions & 15 deletions src/builtin/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const msg_types = Sphinx.MSG_TYPE

let initted = false

export function init() {
export function init(): void {
if (initted) return
initted = true

Expand Down Expand Up @@ -61,7 +61,7 @@ export function init() {
if (!isAdmin) return

switch (cmd) {
case 'setmessage':
case 'setmessage': {
if (arr.length < 3) return
sphinxLogger.info(`setmsg ${arr[2]}`)
const chat = await getTribeOwnersChatByUUID(message.channel.id)
Expand All @@ -83,20 +83,21 @@ export function init() {
.setDescription('Your welcome message has been updated')
message.channel.send({ embed: resEmbed })
return

}
default:
const embed = new Sphinx.MessageEmbed()
.setAuthor('WelcomeBot')
.setTitle('Bot Commands:')
.addFields([
{
name: 'Set welcome message',
value: '/welcome setmessage {MESSAGE}',
},
{ name: 'Help', value: '/welcome help' },
])
.setThumbnail(botSVG)
message.channel.send({ embed })
message.channel.send({
embed: new Sphinx.MessageEmbed()
.setAuthor('WelcomeBot')
.setTitle('Bot Commands:')
.addFields([
{
name: 'Set welcome message',
value: '/welcome setmessage {MESSAGE}',
},
{ name: 'Help', value: '/welcome help' },
])
.setThumbnail(botSVG)
})
return
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export async function requestTransportKey(req: Req, res) {
return
}

const transportTokenKeys: { [k: string]: string } = await rsa.genKeys()
const transportTokenKeys = await rsa.genKeys()
fs.writeFileSync(config.transportPublicKeyLocation, transportTokenKeys.public)
fs.writeFileSync(
config.transportPrivateKeyLocation,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/chatTribes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export async function createTribeChatParams(
}

// make ts sig here w LNd pubkey - that is UUID
const keys: { [k: string]: string } = await rsa.genKeys()
const keys = await rsa.genKeys()
const groupUUID = await tribes.genSignedTimestamp(owner.publicKey)
const theContactIds = contactIds.includes(owner.id)
? contactIds
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as bolt11 from '@boltz/bolt11'
import { sphinxLogger } from '../utils/logger'
import { Req } from '../types'
import { Response } from 'express'
import { ChatPlusMembers } from '../network/send'

function stripLightningPrefix(s: string): string {
if (s.toLowerCase().startsWith('lightning:')) return s.substring(10)
Expand Down Expand Up @@ -202,7 +203,7 @@ export const createInvoice = async (req: Req, res: Response): Promise<void> => {
success(res, jsonUtils.messageToJson(message, chat))

network.sendMessage({
chat: chat,
chat: chat as Partial<ChatPlusMembers>,
sender: owner,
type: constants.message_types.invoice,
message: {
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { loadConfig } from '../utils/config'
import { failure } from '../utils/res'
import { logging, sphinxLogger } from '../utils/logger'
import { Req } from '../types'
import { ChatPlusMembers } from '../network/send'

const config = loadConfig()

Expand Down Expand Up @@ -143,7 +144,7 @@ export const sendAttachmentMessage = async (req: Req, res) => {
if (reply_uuid) msg.replyUuid = reply_uuid
if (parent_id) msg.parentId = parent_id
network.sendMessage({
chat: chat,
chat: chat as Partial<ChatPlusMembers>,
sender: owner,
type: constants.message_types.attachment,
amount: amount || 0,
Expand Down Expand Up @@ -230,7 +231,7 @@ export const purchase = async (req: Req, res) => {
purchaser: owner.id, // for tribe, knows who sent
}
network.sendMessage({
chat: { ...chat.dataValues, contactIds: [contact_id] },
chat: { ...chat.dataValues, contactIds: JSON.stringify([ contact_id ]) },
sender: owner,
type: constants.message_types.purchase,
realSatsContactId: contact_id, // ALWAYS will be keysend, so doesnt matter if tribe owner or not
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as short from 'short-uuid'
import constants from '../constants'
import { logging, sphinxLogger } from '../utils/logger'
import { Req, Res } from '../types'
import { ChatPlusMembers } from '../network/send'

// deprecated
export const getMessages = async (req: Req, res: Res): Promise<void> => {
Expand Down Expand Up @@ -383,7 +384,7 @@ export const sendMessage = async (req: Req, res: Res): Promise<void> => {
if (recipientPic) msgToSend.recipientPic = recipientPic

const sendMessageParams: SendMessageParams = {
chat: chat,
chat: chat as Partial<ChatPlusMembers>,
sender: owner,
amount: amount || 0,
type: msgtype,
Expand Down
7 changes: 4 additions & 3 deletions src/controllers/payment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, Chat, models } from '../models'
import { Message, ChatRecord, models } from '../models'
import { sendNotification } from '../hub'
import * as socket from '../utils/socket'
import * as jsonUtils from '../utils/json'
Expand All @@ -14,6 +14,7 @@ import { anonymousKeysend } from './feed'
import { sphinxLogger } from '../utils/logger'
import { Req, Res } from '../types'
import { sendConfirmation } from './confirmations'
import { ChatPlusMembers } from '../network/send'

export const sendPayment = async (req: Req, res: Res): Promise<void> => {
if (!req.owner) return failure(res, 'no owner')
Expand Down Expand Up @@ -120,11 +121,11 @@ export const sendPayment = async (req: Req, res: Res): Promise<void> => {
// if remote text map, put that in
let theChat = chat
if (contact_ids) {
theChat = { ...chat.dataValues, contactIds: contact_ids } as Chat
theChat = <ChatRecord>{ ...chat.dataValues, contactIds: contact_ids }
if (remote_text_map) msgToSend.content = remote_text_map
}
network.sendMessage({
chat: theChat,
chat: theChat as Partial<ChatPlusMembers>,
sender: owner,
type: constants.message_types.direct_payment,
message: msgToSend as Message,
Expand Down
Loading

0 comments on commit b3fcfa2

Please sign in to comment.