Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
chopperdaddy committed Jul 28, 2022
1 parent bce54c9 commit 338ce75
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
8 changes: 5 additions & 3 deletions twitter-bot/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { BigNumber, Event } from 'ethers';
import dotenv from 'dotenv';
dotenv.config();

const auctionURL = process.env.NODE_ENV === 'prod' ? 'https://phunks.auction/auction' : 'https://testnet.phunks.auction/auction';

interface Time {
days: string,
hours: string,
Expand Down Expand Up @@ -73,7 +75,7 @@ export class AppService {
const receipt = await event.getTransactionReceipt();
const ens = await this.web3Svc.provider.lookupAddress(receipt?.from);

const text = `📢 Phunk #${phunkId.toString()} has been put up for auction\n\nStarted by: ${ens ?? this.shortenAddress(receipt?.from)}\nAuction Ends: ${format(date, 'PPpp')} GMT\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}https://phunks.auction/auction/${auctionId.toString()}`;
const text = `📢 Phunk #${phunkId.toString()} has been put up for auction\n\nStarted by: ${ens ?? this.shortenAddress(receipt?.from)}\nAuction Ends: ${format(date, 'PPpp')} GMT\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}${auctionURL}/${auctionId.toString()}`;

this.twSvc.tweet({ text, image });

Expand All @@ -97,7 +99,7 @@ export class AppService {
const image = await this.imgSvc.createImage(this.pad(phunkId.toString()));
const ens = await this.web3Svc.provider.lookupAddress(sender);

const text = `📢 Phunk #${phunkId.toString()} has a new bid of Ξ${this.web3Svc.weiToEth(value)}\n\nFrom: ${ens ?? this.shortenAddress(sender)}\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}https://phunks.auction/auction/${auctionId.toString()}`;
const text = `📢 Phunk #${phunkId.toString()} has a new bid of Ξ${this.web3Svc.weiToEth(value)}\n\nFrom: ${ens ?? this.shortenAddress(sender)}\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}${auctionURL}/${auctionId.toString()}`;

this.twSvc.tweet({ text, image });

Expand All @@ -112,7 +114,7 @@ export class AppService {

const image = await this.imgSvc.createImage(this.pad(phunkId.toString()));

const text = `📢 The auction for Phunk #${phunkId.toString()} is ending in soon!\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}https://phunks.auction/auction/${auctionId.toString()}`;
const text = `📢 The auction for Phunk #${phunkId.toString()} is ending in soon!\n\nTime remaining:\n${timeLeft.days !== '00' ? timeLeft.days + ' days\n' : ''}${timeLeft.hours !== '00' ? timeLeft.hours + ' hours\n' : ''}${timeLeft.minutes !== '00' ? timeLeft.minutes + ' minutes\n' : ''}${timeLeft.seconds !== '00' ? timeLeft.seconds + ' seconds\n\n' : ''}${auctionURL}/${auctionId.toString()}`;

this.twSvc.tweet({ text, image });
}
Expand Down
2 changes: 1 addition & 1 deletion twitter-bot/src/services/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ImageService {

async createImage(phunkId: string): Promise<string> {

registerFont(path.join(__dirname, '../static/retro-computer.woff'), { family: 'RetroComputer' });
registerFont(path.join(__dirname, '../static/retro-computer.ttf'), { family: 'RetroComputer' });

const canvasWidth = 1200;
const canvasHeight = 1200;
Expand Down
9 changes: 8 additions & 1 deletion twitter-bot/src/services/tweet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import twit from 'twit';
import dotenv from 'dotenv';
dotenv.config();

const twitterConfig = {
const twitterConfig = process.env.NODE_ENV === 'prod' ? {
consumer_key: process.env.TW_CONSUMER_KEY,
consumer_secret: process.env.TW_CONSUMER_SECRET,
access_token: process.env.TW_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TW_ACCESS_TOKEN_SECRET,
} : {
consumer_key: process.env.DEV_TW_CONSUMER_KEY,
consumer_secret: process.env.DEV_TW_CONSUMER_SECRET,
access_token: process.env.DEV_TW_ACCESS_TOKEN_KEY,
access_token_secret: process.env.DEV_TW_ACCESS_TOKEN_SECRET,
};

const twitterClient = new twit(twitterConfig);
Expand Down Expand Up @@ -41,6 +46,8 @@ export class TweetService {
if (!error) console.log(`Successfully tweeted: ${data.text}`);
else console.error(error);
});

// console.log(data.text);
}

}
12 changes: 9 additions & 3 deletions twitter-bot/src/services/web3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import { BigNumber, ethers } from 'ethers';
import auctionABI from '../abi/AuctionHouseABI.json';
import punkDataABI from '../abi/PunkData.json';

const alchemyURL = 'https://eth-mainnet.g.alchemy.com/v2';
import dotenv from 'dotenv';
dotenv.config();

const alchemyURL = process.env.NODE_ENV === 'prod' ? 'https://eth-mainnet.g.alchemy.com/v2' : 'https://eth-rinkeby.alchemyapi.io/v2';

const auctionContractAddress = process.env.NODE_ENV === 'prod' ? process.env.AUCTION_CONTRACT_ADDRESS : process.env.DEV_AUCTION_CONTRACT_ADDRESS;
const punkDataAddress = process.env.NODE_ENV === 'prod' ? process.env.PUNK_DATA_ADDRESS : process.env.DEV_PUNK_DATA_ADDRESS;

@Injectable()
export class Web3Service {

public provider = new ethers.providers.JsonRpcProvider(`${alchemyURL}/${process.env.ALCHEMY_API_KEY}`);
public auctionHouseContract = new ethers.Contract(process.env.AUCTION_CONTRACT_ADDRESS, auctionABI, this.provider);
public punkDataContract = new ethers.Contract(process.env.PUNK_DATA_ADDRESS, punkDataABI, this.provider);
public auctionHouseContract = new ethers.Contract(auctionContractAddress, auctionABI, this.provider);
public punkDataContract = new ethers.Contract(punkDataAddress, punkDataABI, this.provider);

weiToEth(wei: BigNumber): string {
return ethers.utils.formatUnits(wei, 'ether');
Expand Down
Binary file added twitter-bot/src/static/retro-computer.ttf
Binary file not shown.

0 comments on commit 338ce75

Please sign in to comment.