-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto.js
102 lines (94 loc) · 3.09 KB
/
auto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const twit = require('./twit');
const advent = require('./adventure');
const confirmed = ['200 OK']
const forbidden = ['403 Forbidden']
const failed = [400]
// https://etherscan.io/address/
// https://etherscan.io/tx/
module.exports = {
onFollow,
walletRequest,
txInfoExtract
};
// When user follows Omni, omni follows back, creates wallet and DM's the user
async function onFollow(userId, twitUser) {
// Prevents the bot from following iteself ['403']
if (userId == '1234326202699005954') {
return
}
let wallet;
// Checks if new followers has a omni wallet
// If they do logs wallet; if not creates wallet
await advent.getWallet(twitUser)
.then((result) => {
(result.status == 200) ?
wallet = result.data.publicKey:
advent.postWallet(twitUser)
.then((result) => {console.log(`${twitUser} wallet: `, result);
wallet = result.data.address});
;
});
// Follows back users and sens welcome msg with omni wallet info
await twit.follow(twitUser)
.then((result) => {
let welcomeMsg = `Welcome to Omni ${twitUser}!\nYour generated Ethereum wallet: https://etherscan.io/address/${wallet}`;
twit.dm(userId, welcomeMsg)
.then((result) => console.log(`${twitUser}'s welcome message: `, result.status))
.catch((err) => console.log(err))
});
};
// User Dm's bot 'wallet' to request wallet (twitId = serialized account number)
async function walletRequest(twitUser, twitId) {
if (twitUser == 'FyiOmni') {
return
}
let response
let wallet
console.log(`wallet request from: ${twitUser}`)
// Grabs wallet
await advent.getWallet(twitUser)
.then((result) => {
wallet = result.data.publicKey;
response = `https://etherscan.io/address/${wallet}`
twit.dm(twitId, response)
.then((result) => {console.log(result.status)})
.catch((err) => {console.log(err)})})
.catch((err) => console.log(err))
};
// Extracts transaction info from tweet (Bot must be mentioned i.e. @FyiOmni)
function txInfoExtract(tweet) {
let output = {}
// Token List
const tokens = ['XOMNImv', 'XOMNI', 'PETCARE', 'UCLASUPREME', 'TANKGOD','HYPEKILLS', 'RSCH', 'SS2', 'CAR', 'JAMIWA', 'ACIDWINE', 'GRATITUDE', 'HELLO', 'DEEPBLUE', 'FISHCLUB', 'POTTA', '2SWIM', 'DUNKONYOU', 'GINANDJUICE', 'SONNET18', 'OKBOOMER', 'JOLENE', 'ILIKEYOURTIKTOK', 'HOTPOTATO', 'BERNIE']
// Regexp
const amtTicReg = /send\s\d*\s\w*/gi
const amtReg = /[0-9]\d*/gi
const ticReg = /[a-zA-z]\w*/gi
const usersReg = /(?<=@)[_a-zA-Z]\w*/gi
// Returns grouped tx info from tweet
if (tweet.match(amtTicReg)) {
const res = tweet.match(amtTicReg)
const usersList = tweet.match(usersReg)
const amt = res[0].match(amtReg)
const markers = res[0].match(ticReg)
const tickers = markers.map(function(x) { return x.toUpperCase() })
let ticker
let users
// Designates tocken ticker
if (tokens.includes(tickers[1])) {
ticker = tickers[1]
} else {
ticker = null
}
// Filters out FyiOmni from users list
users = usersList.filter((n) => { return n != 'FyiOmni'})
output = {
amount: amt,
users: users,
ticker: ticker
}
return output
} else {
console.log('not a tweet tx')
}
};